diff --git a/.github/workflows/verify-cli-examples.yaml b/.github/workflows/verify-cli-examples.yaml index ddfca755..f8a5a878 100644 --- a/.github/workflows/verify-cli-examples.yaml +++ b/.github/workflows/verify-cli-examples.yaml @@ -3,20 +3,83 @@ name: Verify Cli Examples on: pull_request jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-22.04] - arch: [amd64] + test-cosmos-examples: + runs-on: ubuntu-22.04 + name: 'Test Cosmos Examples' steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' + + - name: Install Dependencies + run: npm ci + + - name: Create .env file + run: | + # Dummy private key created for testing purpose only, it is not secret + npm run setup + + - name: Compile EVM Smart Contracts + run: npm run build + + - name: Override config/ci.json + run: | + echo '{"aptos": {"enabled": false},"cosmos": {"enabled": true}}' > config/ci.json + + - name: Test + run: | + NODE_ENV=ci npm run test:cosmos + + test-evm-examples: + runs-on: ubuntu-22.04 + name: 'Test EVM Examples' + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 + cache: 'npm' + + - name: Install Dependencies + run: npm ci + - name: Create .env file + run: | + # Dummy private key created for testing purpose only, it is not secret + npm run setup + + - name: Compile EVM Smart Contracts + run: | + npm run build + + - name: Override config/ci.json + run: | + echo '{"aptos": {"enabled": false},"cosmos": {"enabled": false}}' > config/ci.json + + - name: Test + run: | + NODE_ENV=ci npm run test:evm + + test-aptos-examples: + runs-on: ubuntu-22.04 + name: 'Test Aptos Examples' + steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' - name: Prerequisites run: | @@ -25,7 +88,7 @@ jobs: chmod +x aptos cp aptos /usr/local/bin - - name: Install + - name: Install Dependencies run: npm ci - name: Create .env file @@ -33,6 +96,10 @@ jobs: # Dummy private key created for testing purpose only, it is not secret npm run setup + - name: Override config/ci.json + run: | + echo '{"aptos": {"enabled": true},"cosmos": {"enabled": false}}' > config/ci.json + - name: Compile EVM Smart Contracts run: | npm run build @@ -41,12 +108,8 @@ jobs: run: | npm run build-aptos - - name: Override config/ci.json - run: | - echo '{"aptos": {"enabled": true},"cosmos": {"enabled": true}}' > config/ci.json - - name: Test run: | nohup sh -c "aptos node run-local-testnet --with-faucet" > nohup.out 2> nohup.err < /dev/null & - sleep 10 - NODE_ENV=ci npm run test + sleep 30 + NODE_ENV=ci npm run test:aptos diff --git a/.github/workflows/verify-web-examples.yaml b/.github/workflows/verify-web-examples.yaml index d9324972..8b849455 100644 --- a/.github/workflows/verify-web-examples.yaml +++ b/.github/workflows/verify-web-examples.yaml @@ -20,7 +20,7 @@ jobs: - name: Override config/ci.json run: | - echo '{"aptos": {"enabled": false}}' > config/ci.json + echo '{"aptos": {"enabled": false}, "cosmos": {"enabled": false}}' > config/ci.json - name: Install Dependencies for Cli Examples run: npm ci @@ -33,7 +33,7 @@ jobs: run: | # Dummy private key created for testing purpose only, it is not secret npm run setup - nohup npm run start & + NODE_ENV=ci nohup npm run start & sleep 5 - name: Setup Web Examples @@ -42,7 +42,7 @@ jobs: npm ci npm run setup - - name: Compile EVM Smart Contracts and Deploy + - name: Deploy run: | cd examples-web npm run deploy diff --git a/.mocharc.js b/.mocharc.js index d478ec78..70eba903 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -4,5 +4,4 @@ module.exports = { recursive: true, timeout: 600000, slow: 15000, - file: ['examples/tests/checkExamples.js'], }; diff --git a/config/default.json b/config/default.json index f15dfa2b..ad0bd2a2 100644 --- a/config/default.json +++ b/config/default.json @@ -3,6 +3,6 @@ "enabled": false }, "cosmos": { - "enabled": true + "enabled": false } } diff --git a/examples-web/scripts/deploy-contracts.ts b/examples-web/scripts/deploy-contracts.ts index 099ee5e7..af6277a0 100644 --- a/examples-web/scripts/deploy-contracts.ts +++ b/examples-web/scripts/deploy-contracts.ts @@ -1,6 +1,6 @@ import "dotenv/config"; import fs from "fs/promises"; -import { existsSync } from "fs"; +import { existsSync, mkdirSync } from "fs"; import path from "path"; import { Wallet } from "ethers"; import { configPath } from "../../config"; @@ -43,8 +43,9 @@ async function main() { // update chains const updatedChains = [chainA, chainB]; const _path = path.resolve(configPath.localEvmChains); - if (!existsSync(_path)) { - await fs.mkdir(_path, { recursive: true }); + const dirname = path.dirname(_path); + if (!existsSync(dirname)) { + await mkdirSync(dirname, { recursive: true }); } const publicPath = path.resolve(__dirname, "../public/chains.json"); await fs.writeFile(_path, JSON.stringify(updatedChains, null, 2)); diff --git a/examples/tests/aptos.test.js b/examples/tests/aptos.test.js new file mode 100644 index 00000000..79afa561 --- /dev/null +++ b/examples/tests/aptos.test.js @@ -0,0 +1,48 @@ +'use strict'; + +require('dotenv').config(); + +const { start, deploy, executeAptosExample, getWallet, getEVMChains, relayers } = require('../../scripts/libs'); +const { + destroyExported, + utils: { setLogger }, +} = require('@axelar-network/axelar-local-dev'); +const fs = require('fs-extra'); +const { configPath } = require('../../config'); + +// disable logging +setLogger((...args) => {}); + +console.log = () => {}; + +const aptosExamples = ['call-contract', 'token-linker']; + +describe('Verify Aptos Examples', function () { + // marked as slow if it takes longer than 15 seconds to run each test. + const wallet = getWallet(); + const testChains = ['Avalanche', 'Fantom', 'Polygon']; + + before(async () => { + // Remove local-evm.json before each test to ensure a clean start + if (fs.existsSync(configPath.localEvmChains)) { + fs.unlinkSync(configPath.localEvmChains); + } + + await start([wallet.address], testChains, { relayInterval: 500, skipCosmos: true }); + }); + + after(async () => { + await destroyExported(relayers); + }); + + for (const exampleName of aptosExamples) { + it(exampleName, async function () { + const example = rootRequire(`examples/aptos/${exampleName}/index.js`); + const chains = getEVMChains('local', testChains); + + if (example.deploy) await deploy('local', chains, wallet, example); + + await executeAptosExample(chains, [], wallet, example); + }); + } +}); diff --git a/examples/tests/checkExamples.js b/examples/tests/checkExamples.js deleted file mode 100644 index 16e932fb..00000000 --- a/examples/tests/checkExamples.js +++ /dev/null @@ -1,134 +0,0 @@ -'use strict'; - -require('dotenv').config(); - -const { - start, - deploy, - executeEVMExample, - executeAptosExample, - getWallet, - getEVMChains, - relayers, - executeCosmosExample, -} = require('../../scripts/libs'); -const { - destroyExported, - utils: { setLogger }, -} = require('@axelar-network/axelar-local-dev'); -const fs = require('fs-extra'); -const { configPath } = require('../../config'); -const { stopAll } = require('@axelar-network/axelar-local-dev-cosmos'); - -// disable logging -setLogger((...args) => {}); - -console.log = () => {}; - -const examples = [ - 'call-contract', - 'call-contract-with-token', - 'call-contract-with-token-express', - 'cross-chain-token', - 'deposit-address', - 'nonced-execution', - 'send-ack', - 'send-token', - // 'nft-linker', - // 'nft-auctionhouse', -]; - -const aptosExamples = ['call-contract', 'token-linker']; - -const cosmosExamples = ['call-contract']; - -describe('Check Examples Execution', function () { - // marked as slow if it takes longer than 15 seconds to run each test. - const wallet = getWallet(); - const testChains = ['Avalanche', 'Fantom', 'Polygon']; - - describe('EVM Examples', function () { - const allExamples = [...examples]; - - beforeEach(async () => { - // Remove local-evm.json before each test to ensure a clean start - if (fs.existsSync(configPath.localEvmChains)) { - fs.unlinkSync(configPath.localEvmChains); - } - - await start([wallet.address], testChains, { relayInterval: 500, skipCosmos: true, skipAptos: true }); - }); - - afterEach(async () => { - await destroyExported(relayers); - }); - - for (const exampleName of allExamples) { - it(exampleName, async function () { - const example = rootRequire(`examples/evm/${exampleName}/index.js`); - const chains = getEVMChains('local', testChains); - - if (example.deploy) { - await deploy('local', chains, wallet, example); - } - - await executeEVMExample('local', chains, [], wallet, example); - }); - } - }); - - describe('Aptos Examples', function () { - before(async () => { - // Remove local-evm.json before each test to ensure a clean start - if (fs.existsSync(configPath.localEvmChains)) { - fs.unlinkSync(configPath.localEvmChains); - } - - await start([wallet.address], testChains, { relayInterval: 500, skipCosmos: true }); - }); - - after(async () => { - await destroyExported(relayers); - }); - - for (const exampleName of aptosExamples) { - it(exampleName, async function () { - const example = rootRequire(`examples/aptos/${exampleName}/index.js`); - const chains = getEVMChains('local', testChains); - - if (example.deploy) await deploy('local', chains, wallet, example); - - await executeAptosExample(chains, [], wallet, example); - }); - } - }); - - describe('Cosmos Examples', function () { - let dropConnections; - beforeEach(async () => { - // Remove local-evm.json before each test to ensure a clean start - if (fs.existsSync(configPath.localEvmChains)) { - fs.unlinkSync(configPath.localEvmChains); - } - - dropConnections = await start([wallet.address], ['Ethereum'], { relayInterval: 2000, skipAptos: true }); - }); - - afterEach(async () => { - await destroyExported(relayers); - await stopAll(); - await dropConnections(); - }); - - for (const exampleName of cosmosExamples) { - it(exampleName, async function () { - const example = rootRequire(`examples/cosmos/${exampleName}/index.js`); - const chains = getEVMChains('local', ['Ethereum']); - - if (example.deploy) await deploy('local', chains, wallet, example); - - await executeCosmosExample('local', chains, [], wallet, example); - }); - } - }); -}); diff --git a/examples/tests/cosmos.test.js b/examples/tests/cosmos.test.js new file mode 100644 index 00000000..fe640317 --- /dev/null +++ b/examples/tests/cosmos.test.js @@ -0,0 +1,51 @@ +'use strict'; + +require('dotenv').config(); + +const { start, deploy, getWallet, getEVMChains, relayers, executeCosmosExample } = require('../../scripts/libs'); +const { + destroyExported, + utils: { setLogger }, +} = require('@axelar-network/axelar-local-dev'); +const fs = require('fs-extra'); +const { configPath } = require('../../config'); +const { stopAll } = require('@axelar-network/axelar-local-dev-cosmos'); + +// disable logging +setLogger((...args) => {}); + +console.log = () => {}; + +const cosmosExamples = ['call-contract']; + +describe('Verify Cosmos Examples', function () { + // marked as slow if it takes longer than 15 seconds to run each test. + const wallet = getWallet(); + + let dropConnections; + beforeEach(async () => { + // Remove local-evm.json before each test to ensure a clean start + if (fs.existsSync(configPath.localEvmChains)) { + fs.unlinkSync(configPath.localEvmChains); + } + + dropConnections = await start([wallet.address], ['Ethereum'], { relayInterval: 2000, skipAptos: true }); + }); + + afterEach(async () => { + await destroyExported(relayers); + await stopAll(); + await dropConnections(); + }); + + for (const exampleName of cosmosExamples) { + it(exampleName, async function () { + const example = rootRequire(`examples/cosmos/${exampleName}/index.js`); + const chains = getEVMChains('local', ['Ethereum']); + + if (example.deploy) await deploy('local', chains, wallet, example); + + await executeCosmosExample('local', chains, [], wallet, example); + }); + } +}); diff --git a/examples/tests/evm.test.js b/examples/tests/evm.test.js new file mode 100644 index 00000000..09dac9ab --- /dev/null +++ b/examples/tests/evm.test.js @@ -0,0 +1,59 @@ +'use strict'; + +require('dotenv').config(); + +const { start, deploy, executeEVMExample, getWallet, getEVMChains, relayers } = require('../../scripts/libs'); +const { + destroyExported, + utils: { setLogger }, +} = require('@axelar-network/axelar-local-dev'); +const fs = require('fs-extra'); +const { configPath } = require('../../config'); + +// disable logging +setLogger((...args) => {}); + +console.log = () => {}; + +const examples = [ + 'call-contract', + 'call-contract-with-token', + 'call-contract-with-token-express', + 'cross-chain-token', + 'deposit-address', + 'nonced-execution', + 'send-ack', + 'send-token', +]; + +describe('Verify EVM Examples', function () { + const wallet = getWallet(); + const testChains = ['Avalanche', 'Fantom', 'Polygon']; + + const allExamples = [...examples]; + + beforeEach(async () => { + if (fs.existsSync(configPath.localEvmChains)) { + fs.unlinkSync(configPath.localEvmChains); + } + + await start([wallet.address], testChains, { relayInterval: 500, skipCosmos: true, skipAptos: true }); + }); + + afterEach(async () => { + await destroyExported(relayers); + }); + + for (const exampleName of allExamples) { + it(exampleName, async function () { + const example = rootRequire(`examples/evm/${exampleName}/index.js`); + const chains = getEVMChains('local', testChains); + + if (example.deploy) { + await deploy('local', chains, wallet, example); + } + + await executeEVMExample('local', chains, [], wallet, example); + }); + } +}); diff --git a/package.json b/package.json index 8a411cfd..b79bb05c 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ }, "scripts": { "test": "TEST=true mocha examples/tests", + "test:cosmos": "TEST=true mocha examples/tests/cosmos.test.js", + "test:evm": "TEST=true mocha examples/tests/evm.test.js", + "test:aptos": "TEST=true mocha examples/tests/aptos.test.js", "start": "node scripts/runStart", "deploy": "node scripts/runDeploy", "execute": "node scripts/runExecute", diff --git a/scripts/libs/start.js b/scripts/libs/start.js index 91847cfb..10b397af 100644 --- a/scripts/libs/start.js +++ b/scripts/libs/start.js @@ -1,7 +1,7 @@ const fs = require('fs'); const { ethers } = require('ethers'); const { createAndExport, EvmRelayer, RelayerType } = require('@axelar-network/axelar-local-dev'); -const { IBCRelayerService, AxelarRelayerService, defaultAxelarChainInfo } = require('@axelar-network/axelar-local-dev-cosmos'); +const { AxelarRelayerService, defaultAxelarChainInfo } = require('@axelar-network/axelar-local-dev-cosmos'); const { enabledAptos, enabledCosmos } = require('./config'); const { configPath } = require('../../config'); const path = require('path');