Have a standard TestRecipient (#1121)

* Have a standard TestRecipient

* PR review

* PR review
pull/1125/head
Nam Chu Hoai 2 years ago committed by GitHub
parent 6787234ebf
commit 9191c47c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      solidity/core/contracts/test/TestRecipient.sol
  2. 39
      solidity/core/test/testrecipient.test.ts
  3. 12
      typescript/ica/contracts/TestRecipient.sol
  4. 14
      typescript/ica/test/accounts.test.ts

@ -7,12 +7,30 @@ contract TestRecipient is IMessageRecipient {
bytes32 public lastSender;
bytes public lastData;
address public lastCaller;
string public lastCallMessage;
event ReceivedMessage(
uint32 indexed origin,
bytes32 indexed sender,
string message
);
event ReceivedCall(address indexed caller, uint256 amount, string message);
function handle(
uint32,
uint32 _origin,
bytes32 _sender,
bytes calldata _data
) external override {
emit ReceivedMessage(_origin, _sender, string(_data));
lastSender = _sender;
lastData = _data;
}
function fooBar(uint256 amount, string calldata message) external {
emit ReceivedCall(msg.sender, amount, message);
lastCaller = msg.sender;
lastCallMessage = message;
}
}

@ -0,0 +1,39 @@
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { utils } from '@hyperlane-xyz/utils';
import { TestRecipient, TestRecipient__factory } from '../types';
const testData = ethers.utils.hexlify(ethers.utils.toUtf8Bytes('test'));
describe('TestRecipient', () => {
let recipient: TestRecipient;
let signerAddress: string;
before(async () => {
const [signer] = await ethers.getSigners();
signerAddress = await signer.getAddress();
const recipientFactory = new TestRecipient__factory(signer);
recipient = await recipientFactory.deploy();
});
it('handles a message', async () => {
await expect(
recipient.handle(0, utils.addressToBytes32(signerAddress), testData),
).to.emit(recipient, 'ReceivedMessage');
expect(await recipient.lastSender()).to.eql(
utils.addressToBytes32(signerAddress),
);
expect(await recipient.lastData()).to.eql(testData);
});
it('handles a call', async () => {
await expect(recipient.fooBar(1, 'test')).to.emit(
recipient,
'ReceivedCall',
);
expect(await recipient.lastCaller()).to.eql(signerAddress);
expect(await recipient.lastCallMessage()).to.eql('test');
});
});

@ -1,12 +0,0 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
contract TestRecipient {
address public lastSender;
bytes public lastData;
function foo(bytes calldata data) external {
lastSender = msg.sender;
lastData = data;
}
}

@ -2,6 +2,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { TestRecipient__factory } from '@hyperlane-xyz/core';
import {
ChainMap,
ChainNameToDomainId,
@ -16,7 +17,7 @@ import {
} from '@hyperlane-xyz/sdk';
import { InterchainAccountDeployer } from '../src/deploy';
import { InterchainAccountRouter, TestRecipient__factory } from '../types';
import { InterchainAccountRouter } from '../types';
describe('InterchainAccountRouter', async () => {
const localChain = 'test1';
@ -59,15 +60,18 @@ describe('InterchainAccountRouter', async () => {
it('forwards calls from interchain account', async () => {
const recipientF = new TestRecipient__factory(signer);
const recipient = await recipientF.deploy();
const fooData = '0x12';
const data = recipient.interface.encodeFunctionData('foo', [fooData]);
const fooMessage = 'Test';
const data = recipient.interface.encodeFunctionData('fooBar', [
1,
fooMessage,
]);
const icaAddress = await remote.getInterchainAccount(
localDomain,
signer.address,
);
await local.dispatch(remoteDomain, [{ to: recipient.address, data }]);
await coreApp.processMessages();
expect(await recipient.lastData()).to.eql(fooData);
expect(await recipient.lastSender()).to.eql(icaAddress);
expect(await recipient.lastCallMessage()).to.eql(fooMessage);
expect(await recipient.lastCaller()).to.eql(icaAddress);
});
});

Loading…
Cancel
Save