Domain support in Mailboxes (#1143)

pull/1147/head
Nam Chu Hoai 2 years ago committed by GitHub
parent 80a6d30270
commit 6fc4638dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      solidity/core/contracts/mock/MockInbox.sol
  2. 8
      solidity/core/contracts/mock/MockOutbox.sol
  3. 5
      solidity/core/test/mockMailbox.test.ts

@ -8,6 +8,7 @@ contract MockInbox {
using TypeCasts for bytes32;
struct PendingMessage {
uint32 originDomain;
bytes32 sender;
bytes32 recipient;
bytes messageBody;
@ -18,11 +19,13 @@ contract MockInbox {
uint256 messageProcessed = 0;
function addPendingMessage(
uint32 _originDomain,
bytes32 _sender,
bytes32 _recipient,
bytes memory _messageBody
) external {
pendingMessages[totalMessages] = PendingMessage(
_originDomain,
_sender,
_recipient,
_messageBody
@ -40,7 +43,7 @@ contract MockInbox {
IMessageRecipient(recipient).handle(
// This is completely arbitrary and consumers should not rely
// on domain handling in the mock mailbox contracts.
1,
pendingMessage.originDomain,
pendingMessage.sender,
pendingMessage.messageBody
);

@ -6,9 +6,11 @@ import {TypeCasts} from "../libs/TypeCasts.sol";
contract MockOutbox {
MockInbox inbox;
uint32 domain;
using TypeCasts for address;
constructor(address _inbox) {
constructor(uint32 _domain, address _inbox) {
domain = _domain;
inbox = MockInbox(_inbox);
}
@ -16,11 +18,13 @@ contract MockOutbox {
uint32,
bytes32 _recipientAddress,
bytes calldata _messageBody
) external {
) external returns (uint256) {
inbox.addPendingMessage(
domain,
msg.sender.addressToBytes32(),
_recipientAddress,
_messageBody
);
return 1;
}
}

@ -9,17 +9,16 @@ import { MockInbox__factory, MockOutbox__factory } from '../types';
describe('Mock mailbox contracts', function () {
it('should be able to mock sending a message', async function () {
const [signer] = await ethers.getSigners();
const originDomain = 1;
const inboxFactory = new MockInbox__factory(signer);
const outboxFactory = new MockOutbox__factory(signer);
const testRecipientFactory = new TestRecipient__factory(signer);
const inbox = await inboxFactory.deploy();
const outbox = await outboxFactory.deploy(inbox.address);
const outbox = await outboxFactory.deploy(originDomain, inbox.address);
const recipient = await testRecipientFactory.deploy();
const data = ethers.utils.toUtf8Bytes('This is a test message');
// Mailbox mocks do not handle domains currently, so this is arbitrary
await outbox.dispatch(0, utils.addressToBytes32(recipient.address), data);
await inbox.processNextPendingMessage();

Loading…
Cancel
Save