Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jan 16, 2025
1 parent 9a729bd commit a5ad995
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion test/InterchainTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('Interchain Token Service', () => {
await token.mint(wallet.address, mintAmount).then((tx) => tx.wait);
if (!skipApprove) await token.approve(service.address, mintAmount).then((tx) => tx.wait);
}

if (minter) {
await token.transferMintership(minter).then((tx) => tx.wait);
}
Expand Down Expand Up @@ -2981,6 +2981,62 @@ describe('Interchain Token Service', () => {
'NotOwner',
);
});

it('Should migrate a token automatically when sending token only once', async () => {
const name = 'migrated token';
const symbol = 'MT';
const decimals = 53;
const amount1 = 123;
const amount2 = 456;
const destinationAddress = '0x1234';

const [token, tokenManager, tokenId] = await deployFunctions.interchainToken(
service,
name,
symbol,
decimals,
service.address,
amount1 + amount2,
);

await expect(service.interchainTransfer(tokenId, destinationChain, destinationAddress, amount1, '0x', 0))
.to.emit(token, 'RolesRemoved')
.withArgs(service.address, 1 << MINTER_ROLE)
.to.emit(token, 'RolesAdded')
.withArgs(tokenManager.address, 1 << MINTER_ROLE);

await expect(service.interchainTransfer(tokenId, destinationChain, destinationAddress, amount2, '0x', 0))
.to.not.emit(token, 'RolesRemoved')
.to.not.emit(token, 'RolesAdded');
});

it('Should migrate a token automatically when receiving token', async () => {
const name = 'migrated token';
const symbol = 'MT';
const decimals = 53;
const amount = 123;
const sourceAddress = '0x1234';

const [token, tokenManager, tokenId] = await deployFunctions.interchainToken(service, name, symbol, decimals, service.address);

const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'bytes', 'bytes', 'uint256', 'bytes'],
[MESSAGE_TYPE_INTERCHAIN_TRANSFER, tokenId, sourceAddress, wallet.address, amount, '0x'],
);
let commandId = await approveContractCall(gateway, destinationChain, service.address, service.address, payload);

await expect(service.execute(commandId, destinationChain, service.address, payload))
.to.emit(token, 'RolesRemoved')
.withArgs(service.address, 1 << MINTER_ROLE)
.to.emit(token, 'RolesAdded')
.withArgs(tokenManager.address, 1 << MINTER_ROLE);

commandId = await approveContractCall(gateway, destinationChain, service.address, service.address, payload);

await expect(service.execute(commandId, destinationChain, service.address, payload))
.to.not.emit(token, 'RolesRemoved')
.to.not.emit(token, 'RolesAdded');
});
});

describe('Bytecode checks [ @skip-on-coverage ]', () => {
Expand Down

0 comments on commit a5ad995

Please sign in to comment.