Skip to content

Commit

Permalink
test(GMPExecutable): adding wait for live tests
Browse files Browse the repository at this point in the history
  • Loading branch information
re1ro committed Dec 13, 2023
1 parent 28d4e85 commit ef513d5
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 355 deletions.
199 changes: 90 additions & 109 deletions test/executable/GMPExecutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,101 @@

const chai = require('chai');
const {
utils: { defaultAbiCoder, keccak256, id },
utils: { defaultAbiCoder, keccak256, id },
} = require('ethers');
const { expect } = chai;
const { ethers } = require('hardhat');
const getRandomID = () => id(Math.floor(Math.random() * 1e10).toString());

describe('GMPExecutable', () => {
let gatewayFactory;

let destinationChainGateway;

let GMPExecutableFactory;
let GMPExecutable;

let ownerWallet;
let userWallet;

const sourceChain = 'chainA';
const num = 10;

before(async () => {
[ownerWallet, userWallet] = await ethers.getSigners();

gatewayFactory = await ethers.getContractFactory(
'MockGateway',
ownerWallet,
);
GMPExecutableFactory = await ethers.getContractFactory(
'GMPExecutableTest',
ownerWallet,
);
});

describe('AxelarGMPExecutable', () => {
describe('Call Contract', () => {
beforeEach(async () => {
destinationChainGateway = await gatewayFactory
.deploy()
.then((d) => d.deployed());

GMPExecutable = await GMPExecutableFactory.deploy(
destinationChainGateway.address,
).then((d) => d.deployed());
});

it('should revert without gateway approval', async () => {
const payload = defaultAbiCoder.encode(['uint256'], [num]);

const approveCommandId = getRandomID();

const receive = GMPExecutable.execute(
approveCommandId,
sourceChain,
userWallet.address.toString(),
payload,
);

await expect(receive).to.be.revertedWithCustomError(
GMPExecutable,
'NotApprovedByGateway',
);
});

it('should call contract on another chain', async () => {
const payload = defaultAbiCoder.encode(['uint256'], [num]);
const payloadHash = keccak256(payload);

const approveCommandId = getRandomID();
const sourceTxHash = keccak256('0x123abc123abc');
const sourceEventIndex = 17;

const approveData = defaultAbiCoder.encode(
['string', 'string', 'address', 'bytes32', 'bytes32', 'uint256'],
[
sourceChain,
userWallet.address,
GMPExecutable.address,
payloadHash,
sourceTxHash,
sourceEventIndex,
],
);

const approveExecute =
await destinationChainGateway.approveContractCall(
approveData,
approveCommandId,
);

await approveExecute.wait();

await expect(approveExecute)
.to.emit(destinationChainGateway, 'ContractCallApproved')
.withArgs(
approveCommandId,
sourceChain,
userWallet.address.toString(),
GMPExecutable.address,
payloadHash,
sourceTxHash,
sourceEventIndex,
);

const receive = await GMPExecutable.execute(
approveCommandId,
sourceChain,
userWallet.address.toString(),
payload,
);

await receive.wait();

await expect(receive).to.emit(GMPExecutable, 'Received').withArgs(num);
});
let gatewayFactory;

let destinationChainGateway;

let GMPExecutableFactory;
let GMPExecutable;

let ownerWallet;
let userWallet;

const sourceChain = 'chainA';
const num = 10;

before(async () => {
[ownerWallet, userWallet] = await ethers.getSigners();

gatewayFactory = await ethers.getContractFactory('MockGateway', ownerWallet);
GMPExecutableFactory = await ethers.getContractFactory('GMPExecutableTest', ownerWallet);
});

describe('AxelarGMPExecutable', () => {
describe('Call Contract', () => {
beforeEach(async () => {
destinationChainGateway = await gatewayFactory.deploy().then((d) => d.deployed());

GMPExecutable = await GMPExecutableFactory.deploy(destinationChainGateway.address).then((d) =>
d.deployed(),
);
});

it('should revert without gateway approval', async () => {
const payload = defaultAbiCoder.encode(['uint256'], [num]);

const approveCommandId = getRandomID();

const receive = GMPExecutable.execute(
approveCommandId,
sourceChain,
userWallet.address.toString(),
payload,
);

await expect(receive).to.be.revertedWithCustomError(GMPExecutable, 'NotApprovedByGateway');
});

it('should call contract on another chain', async () => {
const payload = defaultAbiCoder.encode(['uint256'], [num]);
const payloadHash = keccak256(payload);

const approveCommandId = getRandomID();
const sourceTxHash = keccak256('0x123abc123abc');
const sourceEventIndex = 17;

const approveData = defaultAbiCoder.encode(
['string', 'string', 'address', 'bytes32', 'bytes32', 'uint256'],
[
sourceChain,
userWallet.address,
GMPExecutable.address,
payloadHash,
sourceTxHash,
sourceEventIndex,
],
);

const approveExecute = await destinationChainGateway.approveContractCall(approveData, approveCommandId);

await expect(approveExecute)
.to.emit(destinationChainGateway, 'ContractCallApproved')
.withArgs(
approveCommandId,
sourceChain,
userWallet.address.toString(),
GMPExecutable.address,
payloadHash,
sourceTxHash,
sourceEventIndex,
);

const receive = await GMPExecutable.execute(
approveCommandId,
sourceChain,
userWallet.address.toString(),
payload,
);

await expect(receive).to.emit(GMPExecutable, 'Received').withArgs(num);
});
});
});
});
});
Loading

0 comments on commit ef513d5

Please sign in to comment.