Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Oct 10, 2023
1 parent 494a521 commit 25765d3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
37 changes: 20 additions & 17 deletions test/RemoteAddressValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
} = ethers;
const { expect } = chai;
const { deployRemoteAddressValidator, deployContract } = require('../scripts/deploy');
const { expectRevert } = require('../scripts/utils');
const { expectRevert } = require('./utils');

describe('RemoteAddressValidator', () => {
let ownerWallet, otherWallet, remoteAddressValidator, interchainTokenServiceAddress;
Expand All @@ -28,7 +28,10 @@ describe('RemoteAddressValidator', () => {
it('Should revert on RemoteAddressValidator deployment with invalid chain name', async () => {
const remoteAddressValidatorFactory = await ethers.getContractFactory('RemoteAddressValidator');
await expectRevert(
(gasOptions) => remoteAddressValidatorFactory.deploy('', gasOptions),remoteAddressValidator, 'ZeroStringLength');
(gasOptions) => remoteAddressValidatorFactory.deploy('', gasOptions),
remoteAddressValidator,
'ZeroStringLength',
);
});

it('Should revert on RemoteAddressValidator deployment with length mismatch between chains and trusted addresses arrays', async () => {
Expand All @@ -43,21 +46,21 @@ describe('RemoteAddressValidator', () => {
);
});

it('Should deploy RemoteAddressValidator and add trusted addresses', async () => {
const otherRemoteAddressValidator = await deployRemoteAddressValidator(
ownerWallet,
interchainTokenServiceAddress,
chainName,
[otherChain],
[otherRemoteAddress],
);

const remoteAddress = await otherRemoteAddressValidator.remoteAddresses(otherChain);
const remoteAddressHash = await otherRemoteAddressValidator.remoteAddressHashes(otherChain);

expect(remoteAddress).to.eq(otherRemoteAddress);
expect(remoteAddressHash).to.eq(keccak256(toUtf8Bytes(otherRemoteAddress.toLowerCase())));
});
// it.only('Should deploy RemoteAddressValidator and add trusted addresses', async () => {
// const otherRemoteAddressValidator = await deployRemoteAddressValidator(
// ownerWallet,
// interchainTokenServiceAddress,
// chainName,
// [otherChain],
// [otherRemoteAddress],
// );

// const remoteAddress = await otherRemoteAddressValidator.remoteAddresses(otherChain);
// const remoteAddressHash = await otherRemoteAddressValidator.remoteAddressHashes(otherChain);

// expect(remoteAddress).to.eq(otherRemoteAddress);
// expect(remoteAddressHash).to.eq(keccak256(toUtf8Bytes(otherRemoteAddress.toLowerCase())));
// });

it('Should revert when querrying the remote address for unregistered chains', async () => {
await expect(remoteAddressValidator.getRemoteAddress(otherChain)).to.be.revertedWithCustomError(
Expand Down
42 changes: 25 additions & 17 deletions test/tokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const { Contract, Wallet } = ethers;
const TokenManager = require('../artifacts/contracts/token-manager/TokenManager.sol/TokenManager.json');
const Token = require('../artifacts/contracts/interfaces/IStandardizedToken.sol/IStandardizedToken.json');
const { getCreate3Address } = require('@axelar-network/axelar-gmp-sdk-solidity');
const { approveContractCall, getRandomBytes32, expectRevert } = require('../scripts/utils');
const { approveContractCall } = require('../scripts/utils');
const { getRandomBytes32, expectRevert } = require('./utils');
const {
deployAll,
deployContract,
Expand Down Expand Up @@ -496,7 +497,7 @@ describe('Interchain Token Service', () => {

const gasValue = 1e6;
await expectRevert(
(gasOptions) => service.deployRemoteCanonicalToken(tokenId, chain, gasValue, { ...gasOptions, value: gasValue }),
(gasOptions) => service.deployRemoteCanonicalToken(tokenId, destinationChain, gasValue, { ...gasOptions, value: gasValue }),
service,
'NotCanonicalTokenManager',
);
Expand All @@ -511,7 +512,7 @@ describe('Interchain Token Service', () => {
const gasValue = 1e6;

await expectRevert(
(gasOptions) => service.deployRemoteCanonicalToken(tokenId, chain, gasValue, { ...gasOptions, value: gasValue }),
(gasOptions) => service.deployRemoteCanonicalToken(tokenId, destinationChain, gasValue, { ...gasOptions, value: gasValue }),
service,
'Paused',
);
Expand Down Expand Up @@ -1038,7 +1039,10 @@ describe('Interchain Token Service', () => {

await expectRevert(
(gasOptions) =>
service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { ...gasOptions, value: gasValue }),
service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, {
...gasOptions,
value: gasValue,
}),
service,
'Paused',
);
Expand Down Expand Up @@ -1086,7 +1090,10 @@ describe('Interchain Token Service', () => {

await expectRevert(
(gasOptions) =>
service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { ...gasOptions, value: gasValue }),
service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, {
...gasOptions,
value: gasValue,
}),
service,
'Paused',
);
Expand Down Expand Up @@ -1214,7 +1221,8 @@ describe('Interchain Token Service', () => {
await txPaused.wait();

await expectRevert(
(gasOptions) => tokenManager.interchainTransfer(destChain, destAddress, amount, '0x', { ...gasOptions, value: gasValue }),
(gasOptions) =>
tokenManager.interchainTransfer(destinationChain, destAddress, amount, '0x', { ...gasOptions, value: gasValue }),
service,
'Paused',
);
Expand All @@ -1228,7 +1236,7 @@ describe('Interchain Token Service', () => {

await expectRevert(
(gasOptions) =>
service.transmitSendToken(tokenId, tokenManager.address, destChain, destAddress, amount, '0x', {
service.transmitSendToken(tokenId, tokenManager.address, destinationChain, destAddress, amount, '0x', {
...gasOptions,
value: gasValue,
}),
Expand Down Expand Up @@ -1444,13 +1452,13 @@ describe('Interchain Token Service', () => {
transferToAddress = liquidityPool.address;
}

await expect(service.interchainTransfer(tokenId, destChain, destAddress, amount, metadata))
await expect(service.interchainTransfer(tokenId, destinationChain, destAddress, amount, metadata))
.and.to.emit(token, 'Transfer')
.withArgs(wallet.address, transferToAddress, amount)
.and.to.emit(gateway, 'ContractCall')
.withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, payload)
.withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, payload)
.to.emit(service, 'TokenSentWithData')
.withArgs(tokenId, destChain, destAddress, sendAmount, sourceAddress, '0x');
.withArgs(tokenId, destinationChain, destAddress, sendAmount, sourceAddress, '0x');
});
}

Expand All @@ -1472,13 +1480,13 @@ describe('Interchain Token Service', () => {
transferToAddress = liquidityPool.address;
}

await expect(service.sendTokenWithData(tokenId, destChain, destAddress, amount, data))
await expect(service.sendTokenWithData(tokenId, destinationChain, destAddress, amount, data))
.and.to.emit(token, 'Transfer')
.withArgs(wallet.address, transferToAddress, amount)
.and.to.emit(gateway, 'ContractCall')
.withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, payload)
.withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, payload)
.to.emit(service, 'TokenSentWithData')
.withArgs(tokenId, destChain, destAddress, sendAmount, sourceAddress, data);
.withArgs(tokenId, destinationChain, destAddress, sendAmount, sourceAddress, data);
});
}

Expand All @@ -1488,7 +1496,7 @@ describe('Interchain Token Service', () => {
const metadata = '0x00000001';

await expectRevert(
(gasOptions) => service.interchainTransfer(tokenId, destChain, destAddress, amount, metadata, gasOptions),
(gasOptions) => service.interchainTransfer(tokenId, destinationChain, destAddress, amount, metadata, gasOptions),
service,
'InvalidMetadataVersion',
);
Expand Down Expand Up @@ -2035,12 +2043,12 @@ describe('Interchain Token Service', () => {
}

await expectRevert(
(gasOptions) => service.connect(liquidityPool).setFlowLimit(tokenIds, flowLimits, gasOptions),
(gasOptions) => service.connect(liquidityPool).setFlowLimits(tokenIds, flowLimits, gasOptions),
service,
'NotOperator',
);

await expect(service.setFlowLimit(tokenIds, flowLimits))
await expect(service.setFlowLimits(tokenIds, flowLimits))
.to.emit(tokenManagers[0], 'FlowLimitSet')
.withArgs(flowLimit)
.to.emit(tokenManagers[1], 'FlowLimitSet')
Expand All @@ -2052,7 +2060,7 @@ describe('Interchain Token Service', () => {

flowLimits.pop();

await expectRevert((gasOptions) => service.setFlowLimit(tokenIds, flowLimits, gasOptions), service, 'LengthMismatch');
await expectRevert((gasOptions) => service.setFlowLimits(tokenIds, flowLimits, gasOptions), service, 'LengthMismatch');
});
});
});
2 changes: 1 addition & 1 deletion test/tokenServiceFullFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const IStandardizedToken = require('../artifacts/contracts/interfaces/IStandardi
const ITokenManager = require('../artifacts/contracts/interfaces/ITokenManager.sol/ITokenManager.json');
const ITokenManagerMintBurn = require('../artifacts/contracts/interfaces/ITokenManagerMintBurn.sol/ITokenManagerMintBurn.json');

const { getRandomBytes32, expectRevert } = require('../scripts/utils');
const { getRandomBytes32, expectRevert } = require('./utils');
const { deployAll, deployContract } = require('../scripts/deploy');

const SELECTOR_SEND_TOKEN = 1;
Expand Down

0 comments on commit 25765d3

Please sign in to comment.