Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
297 changes: 194 additions & 103 deletions .github/workflows/test-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,151 +9,242 @@ on:
- "package*.json"
- "contracts/hardhat.config.ts"
- "contracts/tsconfig.json"
- "contracts/.solcover.js"
- ".github/workflows/test-contracts.yaml"
push:
branches:
- main
paths:
- "contracts/contracts/**"
- "contracts/test/**"
- "contracts/scripts/**"
- "package*.json"
- "contracts/hardhat.config.ts"
- "contracts/tsconfig.json"

env:
# Local (Right now using testnet)
LOCAL_PRIVATE_KEY_0: "0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524"
LOCAL_PRIVATE_KEY_1: "0x2e1d968b041d84dd120a5860cee60cd83f9374ef527ca86996317ada3d0d03e7"
LOCAL_PRIVATE_KEY_2: "0x45a5a7108a18dd5013cf2d5857a28144beadc9c70b3bdbd914e38df4e804b8d8"
LOCAL_PRIVATE_KEY_3: "0x6e9d61a325be3f6675cf8b7676c70e4a004d2308e3e182370a41f5653d52c6bd"
LOCAL_PRIVATE_KEY_4: "0x0b58b1bd44469ac9f813b5aeaf6213ddaea26720f0b2f133d08b6f234130a64f"
LOCAL_PRIVATE_KEY_2: "0x44162cd9b9a2f5582bd13b43cfd8be3bc20b8a81ee77f6bf77391598bcfbae4c"
LOCAL_JSON_RPC_ENDPOINT: "http://localhost:7546"
LOCAL_MIRROR_NODE_ENDPOINT: "http://localhost:5551"
# Tesnet
TESTNET_JSON_RPC_ENDPOINT: "https://296.rpc.thirdweb.com"
TESTNET_MIRROR_NODE_ENDPOINT: "https://testnet.mirrornode.hedera.com"

permissions:
contents: read

# ! It does NOT work if running locally using ACT (file sharing issue)

jobs:
thread0:
# ==========================================================================
# Job 0: Build contracts (shared by test and coverage jobs)
# ==========================================================================
# Installs dependencies and builds contracts once, then caches both
# node_modules and build artifacts for downstream deployment jobs.
# Uses actions/cache (save) here and actions/cache/restore (read-only)
# in downstream jobs to avoid redundant npm ci + Solidity compilation.
# ==========================================================================
build:
name: Build Stablecoin Studio Contracts
runs-on: token-studio-linux-medium
# ! Cannot use container with Hedera Local Network
# container:
# image: node:20.17.0-alpine3.20 # Using alpine for a smaller image
permissions:
contents: read

timeout-minutes: 10
steps:
# * Initial steps
- name: Harden Runner
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e #v2.14.2
uses: step-security/harden-runner@v2
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.4.0
uses: actions/setup-node@v4
with:
node-version: "20.x"
node-version: "22"

- name: Install dependencies
run: npm ci

- name: Initial steps
uses: ./.github/actions/initial-steps
- name: Save dependencies to cache
uses: actions/cache/save@v4
with:
module: "contracts"
docker-engine-ubuntu: "true"
# deps-create-env-file: "true" # Needed for testnet
path: |
node_modules
*/node_modules
~/.npm
key: ${{ runner.os }}-deps-${{ hashFiles('package-lock.json') }}

- name: Install and run Hedera Local Network
- name: Compile contracts
run: |
npm install @hashgraph/hedera-local -g
hedera start --detached

# Needed for testnet
# - name: Export ENV variables for contracts
# uses: ./.github/actions/create-env-file
# with:
# api-access-token-1: ${{ secrets.API_ACCESS_TOKEN_1 }}
# api-access-token-2: ${{ secrets.API_ACCESS_TOKEN_2 }}
# module: "contracts"

- name: Install and build Contracts
uses: ./.github/actions/install-and-build
npm run build:contracts

- name: Save Hardhat artifacts
uses: actions/cache/save@v4
with:
module: "contracts"
path: |
contracts/artifacts
contracts/cache
contracts/typechain-types
key: ${{ runner.os }}-contracts-build-${{ github.sha }}

# ==========================================================================
# Job 1: Execute smart contracts coverage (depends on test job)
# ==========================================================================
# Runs the smart contracts coverage in hardhat network.
# ==========================================================================
coverage:
name: Coverage of Stablecoin Studio Contracts
needs: [build]
runs-on: token-studio-linux-medium
timeout-minutes: 15

# * Actual test command
- name: Run
run: npm run test:ci:thread0 --workspace=contracts -- --network local
steps:
- name: Harden Runner
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
with:
egress-policy: audit

- name: Stop Hedera Local Network
if: always()
run: hedera stop
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Clean project
if: always()
run: npm run clean --workspace=contracts
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "22"
cache: npm

thread1:
- name: Restore dependencies from cache
uses: actions/cache/restore@v4
with:
path: |
node_modules
*/node_modules
~/.npm
key: ${{ runner.os }}-deps-${{ hashFiles('package-lock.json') }}
fail-on-cache-miss: true

- name: Restore build artifacts from cache
uses: actions/cache/restore@v4
with:
path: |
contracts/artifacts
contracts/typechain-types
contracts/cache
key: ${{ runner.os }}-contracts-build-${{ github.sha }}
fail-on-cache-miss: false

- name: Run coverage
run: |
npm run coverage:contracts

# ==========================================================================
# Job 2: Execute smart contracts tests (depends on build job)
# ==========================================================================
# Runs the smart contracts tests in hiero ledger Solo.
# ==========================================================================
tests:
name: Test Stablecoin Studio Contracts
needs: [build]
runs-on: token-studio-linux-medium
# ! Cannot use container with Hedera Local Network
# container:
# image: node:20.17.0-alpine3.20 # Using alpine for a smaller image
permissions:
contents: read
timeout-minutes: 60

steps:
# * Initial steps
- name: Harden Runner
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e #v2.14.2
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.4.0
with:
node-version: "20.x"

- name: Initial steps
uses: ./.github/actions/initial-steps
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
module: "contracts"
deps-contracts-install: "true"
# deps-create-env-file: "true" # Needed for testnet
node-version: "22"
cache: npm

- name: Install and run Hedera Local Network
- name: Check Docker availability
id: docker-check
run: |
npm install @hashgraph/hedera-local -g
hedera start --detached

# Needed for testnet
# - name: Export ENV variables for contracts
# uses: ./.github/actions/create-env-file
# with:
# api-access-token-1: ${{ secrets.API_ACCESS_TOKEN_1 }}
# api-access-token-2: ${{ secrets.API_ACCESS_TOKEN_2 }}
# module: "contracts"

- name: Install and build Contracts
uses: ./.github/actions/install-and-build
if docker info > /dev/null 2>&1; then
echo "available=true" >> "${GITHUB_OUTPUT}"
echo "Docker is available"
docker --version
else
echo "available=false" >> "${GITHUB_OUTPUT}"
echo "::warning::Docker not available - skipping Solo deployment test"
fi

- name: Restore dependencies from cache
uses: actions/cache/restore@v4
with:
module: "contracts"

# * Actual test command
- name: Run
run: npm run test:ci:thread1 --workspace=contracts -- --network local

- name: Stop Hedera Local Network
if: always()
run: hedera stop
path: |
node_modules
*/node_modules
~/.npm
key: ${{ runner.os }}-deps-${{ hashFiles('package-lock.json') }}
fail-on-cache-miss: true

- name: Restore build artifacts from cache
uses: actions/cache/restore@v4
with:
path: |
contracts/artifacts
contracts/typechain-types
contracts/cache
key: ${{ runner.os }}-contracts-build-${{ github.sha }}
fail-on-cache-miss: false

- name: Setup Hiero Solo Network
id: solo
if: steps.docker-check.outputs.available == 'true'
uses: hiero-ledger/hiero-solo-action@fbca3e7a99ce9aa8a250563a81187abe115e0dad # v0.16.0
with:
installRelay: true
installMirrorNode: true
hbarAmount: 10000000

- name: Create ECDSA account 0
if: steps.solo.outcome == 'success'
env:
DEPLOYMENT: ${{ steps.solo.outputs.deployment }}
KEY: ${{ env.LOCAL_PRIVATE_KEY_0 }}
run: |
DER_KEY=${KEY#0x}

solo ledger account create \
--ecdsa-private-key "$DER_KEY" \
--set-alias \
--hbar-amount 10000000 \
--deployment "$DEPLOYMENT" \
--dev

- name: Create ECDSA account 1
if: steps.solo.outcome == 'success'
env:
DEPLOYMENT: ${{ steps.solo.outputs.deployment }}
KEY: ${{ env.LOCAL_PRIVATE_KEY_1 }}
run: |
DER_KEY=${KEY#0x}

solo ledger account create \
--ecdsa-private-key "$DER_KEY" \
--set-alias \
--hbar-amount 10000000 \
--deployment "$DEPLOYMENT" \
--dev

- name: Create ED25519 account
if: steps.solo.outcome == 'success'
env:
DEPLOYMENT: ${{ steps.solo.outputs.deployment }}
KEY: ${{ env.LOCAL_PRIVATE_KEY_2 }}
run: |
DER_KEY=${KEY#0x}

solo ledger account create \
--ed25519-private-key "$DER_KEY" \
--hbar-amount 10000000 \
--deployment "$DEPLOYMENT" \
--dev

- name: Run tests
if: steps.docker-check.outputs.available == 'true' && steps.solo.outcome == 'success'
run: |
npm run test --workspace=contracts -- --network local

- name: Clean project
if: always()
run: npm run clean --workspace=contracts
- name: Stop Hiero Solo Network
if: always() && steps.docker-check.outputs.available == 'true'
run: |
docker stop $(docker ps -q --filter "name=hiero") || true
docker rm $(docker ps -aq --filter "name=hiero") || true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ coverage/

# History
.history/

# Gas report
gas-report.txt

.tasks
Loading
Loading