Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Nov 3, 2023
1 parent e3e076e commit 825a689
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
15 changes: 10 additions & 5 deletions contracts/interchain-token-service/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,8 @@ contract InterchainTokenService is
* @param payload the payload of the receive token
*/
function _expressExecute(string calldata sourceChain, bytes calldata payload) internal {
(uint256 messageType, bytes32 tokenId, bytes memory sourceAddress, bytes memory destinationAddressBytes, uint256 amount) = abi.decode(
payload,
(uint256, bytes32, bytes, bytes, uint256)
);
(uint256 messageType, bytes32 tokenId, bytes memory sourceAddress, bytes memory destinationAddressBytes, uint256 amount) = abi
.decode(payload, (uint256, bytes32, bytes, bytes, uint256));
address destinationAddress = destinationAddressBytes.toAddress();

IERC20 token;
Expand Down Expand Up @@ -868,7 +866,14 @@ contract InterchainTokenService is
// slither-disable-next-line reentrancy-events
emit InterchainTransferWithData(tokenId, destinationChain, destinationAddress, amount, sourceAddress, metadata);

payload = abi.encode(MESSAGE_TYPE_INTERCHAIN_TRANSFER_WITH_DATA, tokenId, sourceAddress.toBytes(), destinationAddress, amount, metadata);
payload = abi.encode(
MESSAGE_TYPE_INTERCHAIN_TRANSFER_WITH_DATA,
tokenId,
sourceAddress.toBytes(),
destinationAddress,
amount,
metadata
);

_callContract(destinationChain, payload, msg.value);
}
Expand Down
20 changes: 6 additions & 14 deletions test/TokenRegistrars.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const IStandardizedToken = require('../artifacts/contracts/interfaces/IStandardi
const { deployAll, deployContract } = require('../scripts/deploy');
const { getRandomBytes32 } = require('./utils');

// const messageType_SEND_TOKEN_WITH_DATA = 2;
// const MESSAGE_TYPE_SEND_TOKEN_WITH_DATA = 2;
// const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 3;
const messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;
const MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;

const LOCK_UNLOCK = 2;
const MINT_BURN = 0;
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Token Registrars', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x'],
[MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x'],
);

await expect(tokenRegistrar.registerCanonicalToken(token.address))
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Token Registrars', () => {
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[
messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
name,
symbol,
Expand All @@ -201,15 +201,7 @@ describe('Token Registrars', () => {
}),
)
.to.emit(service, 'InterchainTokenDeploymentStarted')
.withArgs(
tokenId,
name,
symbol,
decimals,
wallet.address.toLowerCase(),
wallet.address.toLowerCase(),
destinationChain,
)
.withArgs(tokenId, name, symbol, decimals, wallet.address.toLowerCase(), wallet.address.toLowerCase(), destinationChain)
.and.to.emit(gasService, 'NativeGasPaidForContractCall')
.withArgs(service.address, destinationChain, service.address, keccak256(payload), gasValue, wallet.address)
.and.to.emit(gateway, 'ContractCall')
Expand Down Expand Up @@ -241,7 +233,7 @@ describe('Token Registrars', () => {
params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', wallet.address],
[MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', wallet.address],
);

await expect(
Expand Down
58 changes: 49 additions & 9 deletions test/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const {
const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 1;
const MESSAGE_TYPE_INTERCHAIN_TRANSFER_WITH_DATA = 2;
const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 3;
const messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;
const INVALID_messageType = 5;
const MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;
const INVALID_MESSAGE_TYPE = 5;

const MINT_BURN = 0;
const MINT_BURN_FROM = 1;
Expand Down Expand Up @@ -501,7 +501,15 @@ describe('Interchain Token Service', () => {
const tokenId = await service.interchainTokenId(wallet.address, salt);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator],
[
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
tokenName,
tokenSymbol,
tokenDecimals,
distributor,
operator,
],
);
await expect(
service.deployInterchainToken(
Expand Down Expand Up @@ -578,7 +586,15 @@ describe('Interchain Token Service', () => {
const commandId = getRandomBytes32();
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator],
[
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
tokenName,
tokenSymbol,
tokenDecimals,
distributor,
operator,
],
);

await expectRevert(
Expand All @@ -598,7 +614,15 @@ describe('Interchain Token Service', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], [operator, tokenAddress]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator],
[
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
tokenName,
tokenSymbol,
tokenDecimals,
distributor,
operator,
],
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

Expand All @@ -621,7 +645,15 @@ describe('Interchain Token Service', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], [operator, tokenAddress]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator],
[
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
tokenName,
tokenSymbol,
tokenDecimals,
distributor,
operator,
],
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

Expand All @@ -644,7 +676,15 @@ describe('Interchain Token Service', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', tokenAddress]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator],
[
MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN,
tokenId,
tokenName,
tokenSymbol,
tokenDecimals,
distributor,
operator,
],
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

Expand Down Expand Up @@ -1151,15 +1191,15 @@ describe('Interchain Token Service', () => {

const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'bytes', 'uint256'],
[INVALID_messageType, tokenId, destAddress, amount],
[INVALID_MESSAGE_TYPE, tokenId, destAddress, amount],
);
const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload);

await expectRevert(
(gasOptions) => service.execute(commandId, sourceChain, sourceAddress, payload, gasOptions),
service,
'InvalidMessageType',
[INVALID_messageType],
[INVALID_MESSAGE_TYPE],
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/TokenServiceFullFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { deployAll, deployContract } = require('../scripts/deploy');

const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 1;
const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 3;
const messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;
const MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN = 4;

const DISTRIBUTOR_ROLE = 0;

Expand Down Expand Up @@ -68,7 +68,7 @@ describe.skip('Interchain Token Service Full Flow', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes', 'uint256', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x', 0, '0x'],
[MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x', 0, '0x'],
);
const expectedTokenManagerAddress = await service.tokenManagerAddress(tokenId);
await expect(service.multicall(data, { value }))
Expand Down Expand Up @@ -187,7 +187,7 @@ describe.skip('Interchain Token Service Full Flow', () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes', 'uint256', 'bytes'],
[messageType_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x', 0, wallet.address],
[MESSAGE_TYPE_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, name, symbol, decimals, '0x', '0x', 0, wallet.address],
);
const tx = service.multicall(data, { value });

Expand Down

0 comments on commit 825a689

Please sign in to comment.