Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Dec 10, 2024
1 parent c4b30ab commit 0f3b53a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
3 changes: 3 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const compilerSettings = {
optimizer: optimizerSettings,
},
};
if (!process.env.CHECK_CONTRACT_SIZE) {
networks.hardhat.allowUnlimitedContractSize = true;
}

/**
* @type import('hardhat/config').HardhatUserConfig
Expand Down
49 changes: 27 additions & 22 deletions test/InterchainTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const { deployAll, deployContract, deployInterchainTokenService } = require('../
const {
MESSAGE_TYPE_INTERCHAIN_TRANSFER,
MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN,
MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER,
MESSAGE_TYPE_RECEIVE_FROM_HUB,
MESSAGE_TYPE_LINK_TOKEN,
MESSAGE_TYPE_REGISTER_TOKEN_METADATA,

Check failure on line 22 in test/InterchainTokenService.js

View workflow job for this annotation

GitHub Actions / lint

'MESSAGE_TYPE_REGISTER_TOKEN_METADATA' is assigned a value but never used
INVALID_MESSAGE_TYPE,
NATIVE_INTERCHAIN_TOKEN,
MINT_BURN_FROM,
Expand Down Expand Up @@ -1111,6 +1112,14 @@ describe('Interchain Token Service', () => {
});

describe('Initialize remote custom token manager deployment', () => {
let tokenAddress, params;
const operator = '0x';

before(async () => {
tokenAddress = wallet.address;
params = defaultAbiCoder.encode(['bytes', 'address'], [operator, tokenAddress]);
});

it('Should initialize a remote custom token manager deployment', async () => {
const salt = getRandomBytes32();

Expand All @@ -1119,17 +1128,16 @@ describe('Interchain Token Service', () => {
salt,
'',
MINT_BURN,
defaultAbiCoder.encode(['bytes', 'address'], ['0x', wallet.address]),
params,
0,
)
).wait();

const tokenId = await service.interchainTokenId(wallet.address, salt);
const params = '0x1234';
const type = LOCK_UNLOCK;
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'uint256', 'bytes'],
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, type, params],
['uint256', 'bytes32', 'uint256', 'bytes', 'bytes', 'bool', 'bytes'],
[MESSAGE_TYPE_LINK_TOKEN, tokenId, type, tokenAddress, tokenAddress, false, operator],
);

const tokenManager = await getContractAt('TokenManager', await service.deployedTokenManager(tokenId), wallet);
Expand All @@ -1146,18 +1154,17 @@ describe('Interchain Token Service', () => {
)
.to.emit(service, 'InterchainTokenIdClaimed')
.withArgs(tokenId, wallet.address, salt)
.to.emit(service, 'TokenManagerDeploymentStarted')
.withArgs(tokenId, destinationChain, type, params)
.to.emit(service, 'LinkTokenStarted')
.withArgs(tokenId, destinationChain, tokenAddress, tokenAddress, type, false, operator)
.and.to.emit(gasService, 'NativeGasPaidForContractCall')
.withArgs(service.address, destinationChain, service.address, keccak256(payload), gasValue, wallet.address)
.and.to.emit(gateway, 'ContractCall')
.withArgs(service.address, destinationChain, service.address, keccak256(payload), payload);
});

it('Should revert on a remote custom token manager deployment if the token manager does does not exist', async () => {
it('Should revert on a remote custom token manager deployment if the token manager does not exist', async () => {
const salt = getRandomBytes32();
const tokenId = await service.interchainTokenId(wallet.address, salt);
const params = '0x1234';
const type = LOCK_UNLOCK;

await expect(
Expand All @@ -1169,7 +1176,6 @@ describe('Interchain Token Service', () => {
await service.setPauseStatus(true).then((tx) => tx.wait);

const salt = getRandomBytes32();
const params = '0x1234';
const type = LOCK_UNLOCK;

await expectRevert(
Expand Down Expand Up @@ -1198,7 +1204,6 @@ describe('Interchain Token Service', () => {
)
).wait();

const params = '0x1234';
const type = LOCK_UNLOCK;
const destinationChainItsHub = 'hub chain 1';

Expand Down Expand Up @@ -1237,8 +1242,8 @@ describe('Interchain Token Service', () => {

const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'uint256', 'bytes'],
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, LOCK_UNLOCK, params],
['uint256', 'bytes32', 'uint256', 'bytes', 'bytes', 'bool', 'bytes'],
[MESSAGE_TYPE_LINK_TOKEN, tokenId, LOCK_UNLOCK, token.address, token.address, false, operator],

Check failure on line 1246 in test/InterchainTokenService.js

View workflow job for this annotation

GitHub Actions / lint

'operator' is not defined
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);
const expectedTokenManagerAddress = await service.tokenManagerAddress(tokenId);
Expand All @@ -1265,8 +1270,8 @@ describe('Interchain Token Service', () => {

const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'uint256', 'bytes'],
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, MINT_BURN, params],
['uint256', 'bytes32', 'uint256', 'bytes', 'bytes', 'bool', 'bytes'],
[MESSAGE_TYPE_LINK_TOKEN, tokenId, MINT_BURN, token.address, token.address, false, operator],

Check failure on line 1274 in test/InterchainTokenService.js

View workflow job for this annotation

GitHub Actions / lint

'operator' is not defined
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

Expand All @@ -1289,10 +1294,9 @@ describe('Interchain Token Service', () => {
tokenId,
]);

const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'uint256', 'bytes'],
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, NATIVE_INTERCHAIN_TOKEN, params],
['uint256', 'bytes32', 'uint256', 'bytes', 'bytes', 'bool', 'bytes'],
[MESSAGE_TYPE_LINK_TOKEN, tokenId, NATIVE_INTERCHAIN_TOKEN, token.address, token.address, false, operator],

Check failure on line 1299 in test/InterchainTokenService.js

View workflow job for this annotation

GitHub Actions / lint

'operator' is not defined
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

Expand Down Expand Up @@ -2160,7 +2164,7 @@ describe('Interchain Token Service', () => {
);
});

it('Should revert with NotSupported when the message type is RECEIVE_FROM_HUB and has MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER type.', async () => {
it.skip('Should revert with NotSupported when the message type is RECEIVE_FROM_HUB and has MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER type.', async () => {
const salt = getRandomBytes32();

await (
Expand Down Expand Up @@ -2637,16 +2641,17 @@ describe('Interchain Token Service', () => {
await token.approve(service.address, amount).then((tx) => tx.wait);

const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'bytes', 'uint256'],
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, destAddress, amount],
['uint256', 'bytes32', 'uint256', 'bytes', 'bytes', 'bool', 'bytes'],
[MESSAGE_TYPE_LINK_TOKEN, tokenId, MINT_BURN, destAddress, destAddress, false, '0x'],
);

const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

await expectRevert(
(gasOptions) => service.expressExecute(commandId, sourceChain, sourceAddress, payload, gasOptions),
service,
'InvalidExpressMessageType',
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER],
[MESSAGE_TYPE_LINK_TOKEN],
);
});

Expand Down
9 changes: 6 additions & 3 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0;
const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1;
const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2;
// const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2; // Deprecated
const MESSAGE_TYPE_SEND_TO_HUB = 3;
const MESSAGE_TYPE_RECEIVE_FROM_HUB = 4;
const INVALID_MESSAGE_TYPE = 5;
const MESSAGE_TYPE_LINK_TOKEN = 5;
const MESSAGE_TYPE_REGISTER_TOKEN_METADATA = 6;
const INVALID_MESSAGE_TYPE = 7;

const NATIVE_INTERCHAIN_TOKEN = 0;
const MINT_BURN_FROM = 1;
Expand All @@ -25,9 +27,10 @@ const ITS_HUB_ADDRESS = 'axelar1xyz';
module.exports = {
MESSAGE_TYPE_INTERCHAIN_TRANSFER,
MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN,
MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER,
MESSAGE_TYPE_SEND_TO_HUB,
MESSAGE_TYPE_RECEIVE_FROM_HUB,
MESSAGE_TYPE_LINK_TOKEN,
MESSAGE_TYPE_REGISTER_TOKEN_METADATA,
INVALID_MESSAGE_TYPE,
NATIVE_INTERCHAIN_TOKEN,
MINT_BURN_FROM,
Expand Down

0 comments on commit 0f3b53a

Please sign in to comment.