Skip to content

Commit

Permalink
chore: fix gmp express test
Browse files Browse the repository at this point in the history
chore: remove ethereum-waffle

chore: remove jest setTimeout per test file

chore: add npm run build

chore: increase test timeout to 5m

chore: add tests timeout

chore: run tests only for core module

chore: increase wait time

chore: skip createAndExport  tests

chore: enable tests for all

chore: not skip near tests

chore: remove skip in export tests

chore: fix tests

chore: skip near tests
  • Loading branch information
npty committed Jul 27, 2023
1 parent f496daa commit 8dab121
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Test
timeout-minutes: 8
run: |
nohup sh -c "aptos node run-local-testnet --with-faucet" > nohup.out 2> nohup.err < /dev/null &
sleep 10
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"publish": "lerna publish from-package --yes",
"version": "lerna version --yes --exact",
"bootstrap": "lerna bootstrap",
"postinstall": "npm run bootstrap && lerna run build",
"postinstall": "lerna bootstrap",
"link": "lerna link",
"test": "lerna run test",
"update": "lerna update",
Expand Down
1 change: 0 additions & 1 deletion packages/axelar-local-dev-aptos/__tests__/aptos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { keccak256, toUtf8Bytes } = ethers.utils;
setLogger(() => undefined);

describe('aptos', () => {
jest.setTimeout(60000);
let client: AptosNetwork;
let evmNetwork: Network;

Expand Down
1 change: 1 addition & 0 deletions packages/axelar-local-dev-aptos/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = {
},
testRegex: '/__tests__/.*\\.(test|spec)?\\.(ts)$',
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testTimeout: 300000,
};
1 change: 1 addition & 0 deletions packages/axelar-local-dev-near/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testTimeout: 300000,
};
2 changes: 0 additions & 2 deletions packages/axelar-local-dev-near/src/__tests__/near.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { createNearNetwork, NearNetwork } from '..';
import { Network, createNetwork, stopAll, deployContract, relay } from '@axelar-network/axelar-local-dev';
import { EvmRelayer } from '@axelar-network/axelar-local-dev/dist/relay/EvmRelayer';

jest.setTimeout(120000);

describe('near', () => {
let client: NearNetwork;

Expand Down
1 change: 1 addition & 0 deletions packages/axelar-local-dev/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testTimeout: 300000,
};
3 changes: 3 additions & 0 deletions packages/axelar-local-dev/src/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { AxelarGateway } from './types/@axelar-network/axelar-cgp-solidity/contr
import { AxelarGasService__factory as AxelarGasServiceFactory } from './types/factories/@axelar-network/axelar-cgp-solidity/contracts/gas-service/AxelarGasService__factory';
import { AxelarGasService } from './types/@axelar-network/axelar-cgp-solidity/contracts/gas-service/AxelarGasService';
import http from 'http';
import { EvmRelayer } from './relay/EvmRelayer';
import { evmRelayer } from './relay';

const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
const { defaultAbiCoder, arrayify, keccak256, toUtf8Bytes } = ethers.utils;
Expand Down Expand Up @@ -234,6 +236,7 @@ export class Network {

async giveToken(address: string, alias: string, amount: bigint) {
const symbol = this.tokens[alias] || alias;

const data = arrayify(
defaultAbiCoder.encode(
['uint256', 'bytes32[]', 'string[]', 'bytes[]'],
Expand Down
9 changes: 3 additions & 6 deletions packages/axelar-local-dev/src/__tests__/export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import { ExpressWithToken__factory as ExpressWithTokenFactory } from '../types/f
import { ExecutableWithToken__factory as ExecuteWithTokenFactory } from '../types/factories/src/contracts/test/ExecutableWithToken__factory';
import ExpressWithToken from '../artifacts/src/contracts/test/ExpressWithToken.sol/ExpressWithToken.json';
import ExecuteWithToken from '../artifacts/src/contracts/test/ExecutableWithToken.sol/ExecutableWithToken.json';
import { solidity } from 'ethereum-waffle';
import { EvmRelayer } from '../relay/EvmRelayer';

chai.use(solidity);
setLogger(() => null);
jest.setTimeout(20000);

async function deployAndFundUsdc(chain: Network) {
await chain.deployToken('Axelar Wrapped aUSDC', 'aUSDC', 6, BigInt(1e22));
Expand Down Expand Up @@ -49,7 +46,7 @@ describe('createAndExport', () => {
});

afterEach(async () => {
await destroyExported();
await destroyExported({ evm: evmRelayer });
});

it('should export a local.json file correctly', async () => {
Expand Down Expand Up @@ -90,7 +87,7 @@ describe('createAndExport', () => {
// print eth balance of owner
await contract1.setAndSend(chain2.name, 'hello', wallet.address, 'aUSDC', amount, { value: BigInt(1e12) });

await new Promise((resolve) => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 3000));

const token2 = await chain2.getTokenContract('aUSDC');
const balance = await token2.balanceOf(wallet.address);
Expand All @@ -113,7 +110,7 @@ describe('createAndExport', () => {
await token1.approve(contract1.address, amount);
await contract1.sendToMany(chain2.name, contract2.address, [wallet.address], 'aUSDC', amount, { value: BigInt(1e17) });

await new Promise((resolve) => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 3000));

const token2 = await chain2.getTokenContract('aUSDC');
const balance = await token2.balanceOf(wallet.address);
Expand Down
1 change: 0 additions & 1 deletion packages/axelar-local-dev/src/__tests__/forking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface NetworkUsdc extends Network {
}

describe.skip("forking", () => {
jest.setTimeout(2000000);

afterEach(async () => {
await stopAll();
Expand Down
1 change: 0 additions & 1 deletion packages/axelar-local-dev/src/__tests__/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import chai from 'chai';
const { expect } = chai;
setLogger(() => null);

jest.setTimeout(300000);

function validateNetwork(network: Network) {
// wallets
Expand Down
46 changes: 28 additions & 18 deletions packages/axelar-local-dev/src/__tests__/relay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict';

import { createNetwork, relay, stopAll, listen, getFee, getDepositAddress, deployContract, setLogger } from '../';
import { createNetwork, relay, stopAll, listen, getFee, getDepositAddress, deployContract, setLogger, evmRelayer } from '../';
import { defaultAbiCoder } from 'ethers/lib/utils';
import { BigNumber, Contract, ContractTransaction, Wallet } from 'ethers';
import { BigNumber, Contract, ContractTransaction, Wallet, ethers } from 'ethers';
import { Network } from '../Network';
import ExpressWithToken from '../artifacts/src/contracts/test/ExpressWithToken.sol/ExpressWithToken.json';
import chai from 'chai';
Expand All @@ -14,7 +14,6 @@ setLogger(() => null);
interface NetworkUsdc extends Network {
usdc?: Contract;
}
jest.setTimeout(200000);

describe('relay', () => {
let chain1: NetworkUsdc;
Expand All @@ -29,9 +28,11 @@ describe('relay', () => {
[user2] = chain2.userWallets;
chain2.usdc = await chain2.deployToken('Axelar Wrapped USDC', 'aUSDC', 6, BigInt(1e18)).then((c: Contract) => c.connect(user2));
});

afterEach(async () => {
await stopAll();
});

describe('deposit address', () => {
it('should generate a deposit address', async () => {
const depositAddress = await getDepositAddress(chain1, chain2, user2.address, 'aUSDC');
Expand Down Expand Up @@ -251,20 +252,17 @@ describe('relay', () => {
});

describe('gmp express', () => {
const amount = 1e10;
const amount = 1e6;

it('should be able to relay a valid gmp-express call', async () => {
it.only('should be able to relay a valid gmp-express call', async () => {
// source chain contract doesn't need to be proxy contract. it can be a normal contract
const contract1 = await deployContract(chain1.ownerWallet, ExpressWithToken, [
chain1.gateway.address,
chain1.gasService.address,
]);
const contract1 = await deployContract(user1, ExpressWithToken, [chain1.gateway.address, chain1.gasService.address]);

// get bytecode with constructor data
const contract2 = await deployContract(chain2.ownerWallet, ExpressWithToken, [
chain2.gateway.address,
chain2.gasService.address,
]);
const contract2 = await deployContract(user2, ExpressWithToken, [chain2.gateway.address, chain2.gasService.address]);

// subscribe to the express call
await evmRelayer.subscribeExpressCall();

// mint usdc tokens to user1
await chain1.giveToken(user1.address, 'aUSDC', BigInt(amount));
Expand All @@ -274,15 +272,27 @@ describe('relay', () => {

// call the express contract
await contract1
.connect(user1)
.sendToMany(chain2.name, contract2.address, [user2.address], 'aUSDC', amount, { value: 1e15 })
.sendToMany(chain2.name, contract2.address, [user2.address], 'aUSDC', amount, { value: ethers.utils.parseEther('1') })
.then((tx: ContractTransaction) => tx.wait());

// relay the call
await relay();
await new Promise((resolve) => setTimeout(resolve, 5000));
await evmRelayer.unsubscribe();

// check that the call was successful
expect((await chain2.usdc?.balanceOf(user2.address))?.toNumber()).to.equal(amount);
const user2Balance = (await chain2.usdc?.balanceOf(user2.address))?.toNumber();
expect(user2Balance).to.equal(amount);

// check that relayer wallet balance
const balanceRelayerAfterExpressed = await chain2.usdc?.balanceOf(chain2.relayerWallet.address);

// relay the usual gmp call
await relay();

// check that relayer should receive fund back.
const balanceRelayerAfterRelayed = await chain2.usdc?.balanceOf(chain2.relayerWallet.address);

// check that relayer wallet balance should be increased by amount from the usual gmp call
expect(balanceRelayerAfterRelayed.sub(balanceRelayerAfterExpressed).toNumber()).to.be.eq(amount);
});
});
});
1 change: 0 additions & 1 deletion packages/axelar-local-dev/src/__tests__/token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { expect } = chai;

setLogger(() => undefined);

jest.setTimeout(300000);

describe('token', () => {
let chain: Network;
Expand Down
9 changes: 5 additions & 4 deletions packages/axelar-local-dev/src/networkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { Network, networks, NetworkOptions, NetworkInfo, NetworkSetup } from './
import { AxelarGateway__factory as AxelarGatewayFactory } from './types/factories/@axelar-network/axelar-cgp-solidity/contracts/AxelarGateway__factory';
import { AxelarGasService__factory as AxelarGasServiceFactory } from './types/factories/@axelar-network/axelar-cgp-solidity/contracts/gas-service/AxelarGasService__factory';
import { ConstAddressDeployer, Create3Deployer } from './contracts';
import { Server } from 'http';

const { keccak256, id, solidityPack, toUtf8Bytes } = ethers.utils;

let serverInstance: any;
let serverInstance: Server | undefined;

export interface ChainCloneData {
name: string;
Expand Down Expand Up @@ -283,8 +284,8 @@ export async function forkNetwork(chainInfo: ChainCloneData, options: NetworkOpt
}

export async function stop(network: string | Network) {
if (typeof network === 'string') network = networks.find((chain) => chain.name == network)!;
if (network.server != null) await network.server.close();
if (typeof network === 'string') network = networks.find((chain) => chain.name === network)!;
if (network.server) await network.server.close();
networks.splice(networks.indexOf(network), 1);
}

Expand All @@ -294,7 +295,7 @@ export async function stopAll() {
}
if (serverInstance) {
await serverInstance.close();
serverInstance = null;
serverInstance = undefined;
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/axelar-local-dev/src/relay/EvmRelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ export class EvmRelayer extends Relayer {
// fund relayer wallet with token
const balance = await tokenContract.balanceOf(to.relayerWallet.address);
if (balance.lt(payed.amount)) {
await to.giveToken(to.relayerWallet.address, payed.symbol, BigInt(10000e18));
const fundAmount = ethers.BigNumber.from(1e10);
await to.giveToken(
to.relayerWallet.address,
payed.symbol,
fundAmount.gt(payed.amount) ? fundAmount.toBigInt() : payed.amount
);
}

const allowance = await tokenContract.allowance(to.relayerWallet.address, expressExecutorContract.address);
Expand Down

0 comments on commit 8dab121

Please sign in to comment.