Skip to content

Commit

Permalink
chore: refactor test actions
Browse files Browse the repository at this point in the history
chore: add checkout step for aptos

chore: test

chore: increase sleep time

chore: clean up
  • Loading branch information
npty committed Dec 14, 2023
1 parent 3383c2c commit 6d83761
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 158 deletions.
93 changes: 78 additions & 15 deletions .github/workflows/verify-cli-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -25,14 +88,18 @@ jobs:
chmod +x aptos
cp aptos /usr/local/bin
- name: Install
- 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: Override config/ci.json
run: |
echo '{"aptos": {"enabled": true},"cosmos": {"enabled": false}}' > config/ci.json
- name: Compile EVM Smart Contracts
run: |
npm run build
Expand All @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/verify-web-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ module.exports = {
recursive: true,
timeout: 600000,
slow: 15000,
file: ['examples/tests/checkExamples.js'],
};
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"enabled": false
},
"cosmos": {
"enabled": true
"enabled": false
}
}
7 changes: 4 additions & 3 deletions examples-web/scripts/deploy-contracts.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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));
Expand Down
48 changes: 48 additions & 0 deletions examples/tests/aptos.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
});
134 changes: 0 additions & 134 deletions examples/tests/checkExamples.js

This file was deleted.

Loading

0 comments on commit 6d83761

Please sign in to comment.