Skip to content

Commit

Permalink
Merge branch 'feat/test-coverage-two' into feat/test-coverage-three
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Oct 10, 2023
2 parents 0744b80 + 25765d3 commit 2f14552
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 @@ -11,7 +11,8 @@ const TokenManager = require('../artifacts/contracts/token-manager/TokenManager.
const TokenManagerLiquidityPool = require('../artifacts/contracts/token-manager/implementations/TokenManagerLiquidityPool.sol/TokenManagerLiquidityPool.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 @@ -518,7 +519,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 @@ -533,7 +534,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 @@ -1088,7 +1089,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 @@ -1136,7 +1140,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 @@ -1264,7 +1271,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 @@ -1278,7 +1286,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 @@ -1494,13 +1502,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 @@ -1522,13 +1530,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 @@ -1538,7 +1546,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 @@ -2149,12 +2157,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 @@ -2166,7 +2174,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 2f14552

Please sign in to comment.