From 111fed98dae66c70ff8a568832e947ccf1c0ecaf Mon Sep 17 00:00:00 2001 From: Foivos Date: Mon, 9 Oct 2023 11:50:37 +0300 Subject: [PATCH] feat: removed the default evm address from remote address validator (#112) * removed the default evm address from remote address validator * fixed a namign issue in tests --------- Co-authored-by: Milap Sheth --- .../interfaces/IRemoteAddressValidator.sol | 11 +-- .../RemoteAddressValidator.sol | 54 +--------- scripts/deploy.js | 10 +- test/RemoteAddressValidator.js | 48 +++------ test/tokenService.js | 98 ++++++++----------- test/tokenServiceFullFlow.js | 7 +- 6 files changed, 67 insertions(+), 161 deletions(-) diff --git a/contracts/interfaces/IRemoteAddressValidator.sol b/contracts/interfaces/IRemoteAddressValidator.sol index 93d6eda7..818a893b 100644 --- a/contracts/interfaces/IRemoteAddressValidator.sol +++ b/contracts/interfaces/IRemoteAddressValidator.sol @@ -10,6 +10,7 @@ interface IRemoteAddressValidator { error ZeroAddress(); error LengthMismatch(); error ZeroStringLength(); + error UntrustedChain(); event TrustedAddressAdded(string sourceChain, string sourceAddress); event TrustedAddressRemoved(string sourceChain); @@ -19,16 +20,6 @@ interface IRemoteAddressValidator { */ function chainName() external view returns (string memory); - /** - * @notice Returns the interchain token address - */ - function interchainTokenServiceAddress() external view returns (address); - - /** - * @notice Returns the interchain token address to string to lower case hash, which is used to compare with incoming calls. - */ - function interchainTokenServiceAddressHash() external view returns (bytes32); - /** * @dev Validates that the sender is a valid interchain token service address * @param sourceChain Source chain of the transaction diff --git a/contracts/remote-address-validator/RemoteAddressValidator.sol b/contracts/remote-address-validator/RemoteAddressValidator.sol index 89d7d40c..6caa0ec7 100644 --- a/contracts/remote-address-validator/RemoteAddressValidator.sol +++ b/contracts/remote-address-validator/RemoteAddressValidator.sol @@ -17,40 +17,13 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable { mapping(string => string) public remoteAddresses; string public chainName; - address public immutable interchainTokenServiceAddress; - bytes32 public immutable interchainTokenServiceAddressHash; - - /** - * @dev Store the interchain token service address as string across two immutable variables to avoid recomputation and save gas - */ - uint256 private immutable interchainTokenServiceAddress1; - uint256 private immutable interchainTokenServiceAddress2; - bytes32 private constant CONTRACT_ID = keccak256('remote-address-validator'); /** - * @dev Constructs the RemoteAddressValidator contract, both array parameters must be equal in length - * @param _interchainTokenServiceAddress Address of the interchain token service + * @dev Constructs the RemoteAddressValidator contract, both array parameters must be equal in length. + * @param chainName_ The name of the current chain. */ - constructor(address _interchainTokenServiceAddress, string memory chainName_) { - if (_interchainTokenServiceAddress == address(0)) revert ZeroAddress(); - - interchainTokenServiceAddress = _interchainTokenServiceAddress; - - string memory interchainTokenServiceAddressString = interchainTokenServiceAddress.toString(); - interchainTokenServiceAddressHash = keccak256(bytes(interchainTokenServiceAddressString)); - - uint256 p1; - uint256 p2; - - assembly { - p1 := mload(add(interchainTokenServiceAddressString, 32)) - p2 := mload(add(interchainTokenServiceAddressString, 64)) - } - - interchainTokenServiceAddress1 = p1; - interchainTokenServiceAddress2 = p2; - + constructor(string memory chainName_) { if (bytes(chainName_).length == 0) revert ZeroStringLength(); chainName = chainName_; } @@ -89,21 +62,6 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable { return s; } - /** - * @dev Return the interchain token service address as a string by constructing it from the two immutable variables caching it - */ - function _interchainTokenServiceAddressString() internal view returns (string memory interchainTokenServiceAddressString) { - interchainTokenServiceAddressString = new string(42); - - uint256 p1 = interchainTokenServiceAddress1; - uint256 p2 = interchainTokenServiceAddress2; - - assembly { - mstore(add(interchainTokenServiceAddressString, 32), p1) - mstore(add(interchainTokenServiceAddressString, 64), p2) - } - } - /** * @dev Validates that the sender is a valid interchain token service address * @param sourceChain Source chain of the transaction @@ -114,10 +72,6 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable { string memory sourceAddressNormalized = _lowerCase(sourceAddress); bytes32 sourceAddressHash = keccak256(bytes(sourceAddressNormalized)); - if (sourceAddressHash == interchainTokenServiceAddressHash) { - return true; - } - return sourceAddressHash == remoteAddressHashes[sourceChain]; } @@ -158,7 +112,7 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable { remoteAddress = remoteAddresses[chainName_]; if (bytes(remoteAddress).length == 0) { - remoteAddress = _interchainTokenServiceAddressString(); + revert UntrustedChain(); } } } diff --git a/scripts/deploy.js b/scripts/deploy.js index 87da2b26..38e7937a 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -11,9 +11,9 @@ async function deployContract(wallet, contractName, args = []) { return contract; } -async function deployRemoteAddressValidator(wallet, interchainTokenServiceAddress, chainName) { - const remoteAddressValidatorImpl = await deployContract(wallet, 'RemoteAddressValidator', [interchainTokenServiceAddress, chainName]); - const params = defaultAbiCoder.encode(['string[]', 'string[]'], [[], []]); +async function deployRemoteAddressValidator(wallet, chainName, interchainTokenServiceAddress = '', evmChains = []) { + const remoteAddressValidatorImpl = await deployContract(wallet, 'RemoteAddressValidator', [chainName]); + const params = defaultAbiCoder.encode(['string[]', 'string[]'], [evmChains, evmChains.map(() => interchainTokenServiceAddress)]); const remoteAddressValidatorProxy = await deployContract(wallet, 'RemoteAddressValidatorProxy', [ remoteAddressValidatorImpl.address, @@ -74,7 +74,7 @@ async function deployTokenManagerImplementations(wallet, interchainTokenServiceA return implementations; } -async function deployAll(wallet, chainName, deploymentKey = 'interchainTokenService') { +async function deployAll(wallet, chainName, evmChains = [], deploymentKey = 'interchainTokenService') { const create3Deployer = await deployContract(wallet, 'Create3Deployer'); const gateway = await deployMockGateway(wallet); const gasService = await deployGasService(wallet); @@ -82,7 +82,7 @@ async function deployAll(wallet, chainName, deploymentKey = 'interchainTokenServ const standardizedToken = await deployContract(wallet, 'StandardizedToken'); const standardizedTokenDeployer = await deployContract(wallet, 'StandardizedTokenDeployer', [standardizedToken.address]); const interchainTokenServiceAddress = await getCreate3Address(create3Deployer.address, wallet, deploymentKey); - const remoteAddressValidator = await deployRemoteAddressValidator(wallet, interchainTokenServiceAddress, chainName); + const remoteAddressValidator = await deployRemoteAddressValidator(wallet, chainName, interchainTokenServiceAddress, evmChains); const tokenManagerImplementations = await deployTokenManagerImplementations(wallet, interchainTokenServiceAddress); const service = await deployInterchainTokenService( diff --git a/test/RemoteAddressValidator.js b/test/RemoteAddressValidator.js index 6415bc77..c787d5c6 100644 --- a/test/RemoteAddressValidator.js +++ b/test/RemoteAddressValidator.js @@ -4,8 +4,7 @@ require('dotenv').config(); const chai = require('chai'); const { ethers } = require('hardhat'); const { - constants: { AddressZero }, - utils: { defaultAbiCoder, keccak256, toUtf8Bytes }, + utils: { defaultAbiCoder }, } = ethers; const { expect } = chai; const { deployRemoteAddressValidator, deployContract } = require('../scripts/deploy'); @@ -21,30 +20,16 @@ describe('RemoteAddressValidator', () => { ownerWallet = wallets[0]; otherWallet = wallets[1]; interchainTokenServiceAddress = wallets[2].address; - remoteAddressValidator = await deployRemoteAddressValidator(ownerWallet, interchainTokenServiceAddress, chainName); - }); - - it('Should revert on RemoteAddressValidator deployment with invalid interchain token service address', async () => { - const remoteAddressValidatorFactory = await ethers.getContractFactory('RemoteAddressValidator'); - await expect(remoteAddressValidatorFactory.deploy(AddressZero, chainName)).to.be.revertedWithCustomError( - remoteAddressValidator, - 'ZeroAddress', - ); + remoteAddressValidator = await deployRemoteAddressValidator(ownerWallet, chainName); }); it('Should revert on RemoteAddressValidator deployment with invalid chain name', async () => { const remoteAddressValidatorFactory = await ethers.getContractFactory('RemoteAddressValidator'); - await expect(remoteAddressValidatorFactory.deploy(interchainTokenServiceAddress, '')).to.be.revertedWithCustomError( - remoteAddressValidator, - 'ZeroStringLength', - ); + await expect(remoteAddressValidatorFactory.deploy('')).to.be.revertedWithCustomError(remoteAddressValidator, 'ZeroStringLength'); }); it('Should revert on RemoteAddressValidator deployment with length mismatch between chains and trusted addresses arrays', async () => { - const remoteAddressValidatorImpl = await deployContract(ownerWallet, 'RemoteAddressValidator', [ - interchainTokenServiceAddress, - chainName, - ]); + const remoteAddressValidatorImpl = await deployContract(ownerWallet, 'RemoteAddressValidator', [chainName]); const remoteAddressValidatorProxyFactory = await ethers.getContractFactory('RemoteAddressValidatorProxy'); const params = defaultAbiCoder.encode(['string[]', 'string[]'], [['Chain A'], []]); await expect( @@ -52,22 +37,16 @@ describe('RemoteAddressValidator', () => { ).to.be.revertedWithCustomError(remoteAddressValidator, 'SetupFailed'); }); - it('Should get the correct remote address for unregistered chains', async () => { - const remoteAddress = await remoteAddressValidator.getRemoteAddress(otherChain); - expect(remoteAddress).to.equal(interchainTokenServiceAddress.toLowerCase()); - }); - - it('Should get the correct interchain token service address', async () => { - const itsAddress = await remoteAddressValidator.interchainTokenServiceAddress(); - expect(itsAddress).to.equal(interchainTokenServiceAddress); - - const itsAddressHash = await remoteAddressValidator.interchainTokenServiceAddressHash(); - expect(itsAddressHash).to.equal(keccak256(toUtf8Bytes(interchainTokenServiceAddress.toLowerCase()))); + it('Should revert when querrying the remote address for unregistered chains', async () => { + await expect(remoteAddressValidator.getRemoteAddress(otherChain)).to.be.revertedWithCustomError( + remoteAddressValidator, + 'UntrustedChain', + ); }); it('Should be able to validate remote addresses properly', async () => { expect(await remoteAddressValidator.validateSender(otherChain, otherRemoteAddress)).to.equal(false); - expect(await remoteAddressValidator.validateSender(otherChain, interchainTokenServiceAddress)).to.equal(true); + expect(await remoteAddressValidator.validateSender(otherChain, interchainTokenServiceAddress)).to.equal(false); }); it('Should not be able to add a custom remote address as not the owner', async () => { @@ -112,7 +91,10 @@ describe('RemoteAddressValidator', () => { await expect(remoteAddressValidator.removeTrustedAddress(otherChain)) .to.emit(remoteAddressValidator, 'TrustedAddressRemoved') .withArgs(otherChain); - expect(await remoteAddressValidator.getRemoteAddress(otherChain)).to.equal(interchainTokenServiceAddress.toLowerCase()); + await expect(remoteAddressValidator.getRemoteAddress(otherChain)).to.be.revertedWithCustomError( + remoteAddressValidator, + 'UntrustedChain', + ); }); it('Should revert on removing a custom remote address with an empty chain name', async () => { @@ -124,6 +106,6 @@ describe('RemoteAddressValidator', () => { it('Should be able to validate remote addresses properly.', async () => { expect(await remoteAddressValidator.validateSender(otherChain, otherRemoteAddress)).to.equal(false); - expect(await remoteAddressValidator.validateSender(otherChain, interchainTokenServiceAddress)).to.equal(true); + expect(await remoteAddressValidator.validateSender(otherChain, interchainTokenServiceAddress)).to.equal(false); }); }); diff --git a/test/tokenService.js b/test/tokenService.js index f2e2a39c..93b0bca9 100644 --- a/test/tokenService.js +++ b/test/tokenService.js @@ -30,6 +30,8 @@ describe('Interchain Token Service', () => { let service, gateway, gasService; const deployFunctions = {}; + const destinationChain = 'destination chain'; + const sourceChain = 'source chain'; deployFunctions.lockUnlock = async function deployNewLockUnlock( tokenName, @@ -132,7 +134,7 @@ describe('Interchain Token Service', () => { const wallets = await ethers.getSigners(); wallet = wallets[0]; liquidityPool = wallets[1]; - [service, gateway, gasService] = await deployAll(wallet, 'Test'); + [service, gateway, gasService] = await deployAll(wallet, 'Test', [sourceChain, destinationChain]); }); describe('Register Canonical Token', () => { @@ -211,19 +213,18 @@ describe('Interchain Token Service', () => { }); it('Should be able to initiate a remote standardized token deployment', async () => { - const chain = 'chain1'; const gasValue = 1e6; const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes', 'uint256', 'bytes'], [SELECTOR_DEPLOY_AND_REGISTER_STANDARDIZED_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, '0x', '0x', 0, '0x'], ); - await expect(service.deployRemoteCanonicalToken(tokenId, chain, gasValue, { value: gasValue })) + await expect(service.deployRemoteCanonicalToken(tokenId, destinationChain, gasValue, { value: gasValue })) .to.emit(service, 'RemoteStandardizedTokenAndManagerDeploymentInitialized') - .withArgs(tokenId, tokenName, tokenSymbol, tokenDecimals, '0x', '0x', 0, '0x', chain, gasValue) + .withArgs(tokenId, tokenName, tokenSymbol, tokenDecimals, '0x', '0x', 0, '0x', destinationChain, gasValue) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) .and.to.emit(gateway, 'ContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), payload); + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), payload); }); // it('Should revert if token manager for given token has not be deployed', async () => {}); @@ -246,12 +247,10 @@ describe('Interchain Token Service', () => { const tokenManagerAddress = await service.getValidTokenManagerAddress(tokenId); expect(tokenManagerAddress).to.not.equal(AddressZero); - const chain = 'chain1'; const gasValue = 1e6; - await expect(service.deployRemoteCanonicalToken(tokenId, chain, gasValue, { value: gasValue })).to.be.revertedWithCustomError( - service, - 'NotCanonicalTokenManager', - ); + await expect( + service.deployRemoteCanonicalToken(tokenId, destinationChain, gasValue, { value: gasValue }), + ).to.be.revertedWithCustomError(service, 'NotCanonicalTokenManager'); }); it('Should revert on remote standardized token deployment if paused', async () => { @@ -260,12 +259,10 @@ describe('Interchain Token Service', () => { const salt = getRandomBytes32(); const tokenId = await service.getCustomTokenId(wallet.address, salt); - const chain = 'chain1'; const gasValue = 1e6; - await expect(service.deployRemoteCanonicalToken(tokenId, chain, gasValue, { value: gasValue })).to.be.revertedWithCustomError( - service, - 'Paused', - ); + await expect( + service.deployRemoteCanonicalToken(tokenId, destinationChain, gasValue, { value: gasValue }), + ).to.be.revertedWithCustomError(service, 'Paused'); tx = await service.setPaused(false); await tx.wait(); @@ -329,7 +326,6 @@ describe('Interchain Token Service', () => { const tokenSymbol = 'TN'; const tokenDecimals = 13; const distributor = '0x12345678'; - const destinationChain = 'dest'; const mintTo = '0x0abc'; const mintAmount = 123456; const operator = '0x5678'; @@ -418,7 +414,6 @@ describe('Interchain Token Service', () => { }); describe('Receive Remote Standardized Token Deployment', () => { - const sourceChain = 'source chain'; const tokenName = 'Token Name'; const tokenSymbol = 'TN'; const tokenDecimals = 13; @@ -685,7 +680,6 @@ describe('Interchain Token Service', () => { it('Should initialize a remote custom token manager deployment', async () => { const salt = getRandomBytes32(); const tokenId = await service.getCustomTokenId(wallet.address, salt); - const chain = 'chain1'; const gasValue = 1e6; const params = '0x1234'; const type = LOCK_UNLOCK; @@ -694,13 +688,13 @@ describe('Interchain Token Service', () => { [SELECTOR_DEPLOY_TOKEN_MANAGER, tokenId, type, params], ); - await expect(service.deployRemoteCustomTokenManager(salt, chain, type, params, gasValue, { value: gasValue })) + await expect(service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { value: gasValue })) .to.emit(service, 'RemoteTokenManagerDeploymentInitialized') - .withArgs(tokenId, chain, gasValue, type, params) + .withArgs(tokenId, destinationChain, gasValue, type, params) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) .and.to.emit(gateway, 'ContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), payload); + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), payload); }); it('Should revert on remote custom token manager deployment if paused', async () => { @@ -708,13 +702,12 @@ describe('Interchain Token Service', () => { await tx.wait(); const salt = getRandomBytes32(); - const chain = 'chain1'; const gasValue = 1e6; const params = '0x1234'; const type = LOCK_UNLOCK; await expect( - service.deployRemoteCustomTokenManager(salt, chain, type, params, gasValue, { value: gasValue }), + service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { value: gasValue }), ).to.be.revertedWithCustomError(service, 'Paused'); tx = await service.setPaused(false); await tx.wait(); @@ -732,7 +725,6 @@ describe('Interchain Token Service', () => { it('Should initialize a remote custom token manager deployment', async () => { const salt = getRandomBytes32(); const tokenId = await service.getCustomTokenId(wallet.address, salt); - const chain = 'chain1'; const gasValue = 1e6; const params = '0x1234'; const type = LOCK_UNLOCK; @@ -741,13 +733,13 @@ describe('Interchain Token Service', () => { [SELECTOR_DEPLOY_TOKEN_MANAGER, tokenId, type, params], ); - await expect(service.deployRemoteCustomTokenManager(salt, chain, type, params, gasValue, { value: gasValue })) + await expect(service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { value: gasValue })) .to.emit(service, 'RemoteTokenManagerDeploymentInitialized') - .withArgs(tokenId, chain, gasValue, type, params) + .withArgs(tokenId, destinationChain, gasValue, type, params) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), gasValue, wallet.address) .and.to.emit(gateway, 'ContractCall') - .withArgs(service.address, chain, service.address.toLowerCase(), keccak256(payload), payload); + .withArgs(service.address, destinationChain, service.address.toLowerCase(), keccak256(payload), payload); }); it('Should revert on remote custom token manager deployment if paused', async () => { @@ -755,13 +747,12 @@ describe('Interchain Token Service', () => { await tx.wait(); const salt = getRandomBytes32(); - const chain = 'chain1'; const gasValue = 1e6; const params = '0x1234'; const type = LOCK_UNLOCK; await expect( - service.deployRemoteCustomTokenManager(salt, chain, type, params, gasValue, { value: gasValue }), + service.deployRemoteCustomTokenManager(salt, destinationChain, type, params, gasValue, { value: gasValue }), ).to.be.revertedWithCustomError(service, 'Paused'); tx = await service.setPaused(false); await tx.wait(); @@ -769,7 +760,6 @@ describe('Interchain Token Service', () => { }); describe('Receive Remote Token Manager Deployment', () => { - const sourceChain = 'source chain'; let sourceAddress; before(async () => { @@ -848,7 +838,6 @@ describe('Interchain Token Service', () => { describe('Send Token', () => { const amount = 1234; - const destChain = 'destination Chain'; const destAddress = '0x5678'; const gasValue = 90; @@ -870,21 +859,20 @@ describe('Interchain Token Service', () => { transferToAddress = liquidityPool.address; } - await expect(tokenManager.interchainTransfer(destChain, destAddress, amount, '0x', { value: gasValue })) + await expect(tokenManager.interchainTransfer(destinationChain, destAddress, amount, '0x', { value: gasValue })) .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) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) .to.emit(service, 'TokenSent') - .withArgs(tokenId, destChain, destAddress, sendAmount); + .withArgs(tokenId, destinationChain, destAddress, sendAmount); }); } }); describe('Receive Remote Tokens', () => { - const sourceChain = 'source chain'; let sourceAddress; const amount = 1234; let destAddress; @@ -962,7 +950,6 @@ describe('Interchain Token Service', () => { describe('Send Token With Data', () => { const amount = 1234; - const destChain = 'destination Chain'; const destAddress = '0x5678'; const gasValue = 90; let sourceAddress; @@ -990,21 +977,20 @@ describe('Interchain Token Service', () => { transferToAddress = liquidityPool.address; } - await expect(tokenManager.callContractWithInterchainToken(destChain, destAddress, amount, data, { value: gasValue })) + await expect(tokenManager.callContractWithInterchainToken(destinationChain, destAddress, amount, data, { value: gasValue })) .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) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) .to.emit(service, 'TokenSentWithData') - .withArgs(tokenId, destChain, destAddress, sendAmount, sourceAddress, data); + .withArgs(tokenId, destinationChain, destAddress, sendAmount, sourceAddress, data); }); } }); describe('Receive Remote Tokens with Data', () => { - const sourceChain = 'source chain'; let sourceAddress; const sourceAddressForService = '0x1234'; const amount = 1234; @@ -1116,7 +1102,6 @@ describe('Interchain Token Service', () => { describe('Send Interchain Token', () => { const amount = 1234; - const destChain = 'destination Chain'; const destAddress = '0x5678'; const gasValue = 90; const metadata = '0x'; @@ -1139,22 +1124,21 @@ describe('Interchain Token Service', () => { transferToAddress = liquidityPool.address; } - await expect(token.interchainTransfer(destChain, destAddress, amount, metadata, { value: gasValue })) + await expect(token.interchainTransfer(destinationChain, destAddress, amount, metadata, { value: gasValue })) .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) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) .to.emit(service, 'TokenSent') - .withArgs(tokenId, destChain, destAddress, sendAmount); + .withArgs(tokenId, destinationChain, destAddress, sendAmount); }); } }); describe('Send Interchain Token With Data', () => { const amount = 1234; - const destChain = 'destination Chain'; const destAddress = '0x5678'; const gasValue = 90; let sourceAddress; @@ -1184,22 +1168,21 @@ describe('Interchain Token Service', () => { } const metadata = solidityPack(['uint32', 'bytes'], [0, data]); - await expect(token.interchainTransfer(destChain, destAddress, amount, metadata, { value: gasValue })) + await expect(token.interchainTransfer(destinationChain, destAddress, amount, metadata, { value: gasValue })) .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) .and.to.emit(gasService, 'NativeGasPaidForContractCall') - .withArgs(service.address, destChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) + .withArgs(service.address, destinationChain, service.address.toLowerCase(), payloadHash, gasValue, wallet.address) .to.emit(service, 'TokenSentWithData') - .withArgs(tokenId, destChain, destAddress, sendAmount, sourceAddress, data); + .withArgs(tokenId, destinationChain, destAddress, sendAmount, sourceAddress, data); }); } }); describe('Express Execute', () => { const commandId = getRandomBytes32(); - const sourceChain = 'source chain'; const sourceAddress = '0x1234'; const amount = 1234; const destinationAddress = new Wallet(getRandomBytes32()).address; @@ -1249,7 +1232,6 @@ describe('Interchain Token Service', () => { }); describe('Express Receive Remote Tokens', () => { - const sourceChain = 'source chain'; let sourceAddress; const amount = 1234; const destAddress = new Wallet(getRandomBytes32()).address; @@ -1339,7 +1321,6 @@ describe('Interchain Token Service', () => { }); describe('Express Receive Remote Tokens with Data', () => { - const sourceChain = 'source chain'; let sourceAddress; const sourceAddressForService = '0x1234'; const amount = 1234; @@ -1443,7 +1424,6 @@ describe('Interchain Token Service', () => { }); describe('Flow Limits', () => { - const destinationChain = 'dest'; const destinationAddress = '0x1234'; let tokenManager, tokenId; const sendAmount = 1234; diff --git a/test/tokenServiceFullFlow.js b/test/tokenServiceFullFlow.js index 1fa94921..2170c04c 100644 --- a/test/tokenServiceFullFlow.js +++ b/test/tokenServiceFullFlow.js @@ -26,22 +26,22 @@ const LOCK_UNLOCK = 2; // const LOCK_UNLOCK_FEE_ON_TRANSFER = 3; // const LIQUIDITY_POOL = 4; -describe('Interchain Token Service Flow', () => { +describe('Interchain Token Service Full Flow', () => { let wallet; let service, gateway, gasService, tokenManager, tokenId; const name = 'tokenName'; const symbol = 'tokenSymbol'; + const otherChains = ['chain 1', 'chain 2']; const decimals = 18; before(async () => { const wallets = await ethers.getSigners(); wallet = wallets[0]; - [service, gateway, gasService] = await deployAll(wallet, 'Test'); + [service, gateway, gasService] = await deployAll(wallet, 'Test', otherChains); }); describe('Full canonical token registration, remote deployment and token send', async () => { let token; - const otherChains = ['chain 1', 'chain 2']; const gasValues = [1234, 5678]; const tokenCap = BigInt(1e18); @@ -134,7 +134,6 @@ describe('Interchain Token Service Flow', () => { let token; let tokenId; const salt = getRandomBytes32(); - const otherChains = ['chain 1', 'chain 2']; const gasValues = [1234, 5678]; const tokenCap = BigInt(1e18);