The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/solidity/abacus-core/test/message.test.ts

89 lines
2.7 KiB

import { ethers, abacus } from 'hardhat';
import { expect } from 'chai';
import { TestMessage, TestMessage__factory } from '../typechain';
const testCases = require('../../../vectors/message.json');
const remoteDomain = 1000;
const localDomain = 2000;
describe('Message', async () => {
let messageLib: TestMessage;
before(async () => {
const [signer] = await ethers.getSigners();
const Message = new TestMessage__factory(signer);
messageLib = await Message.deploy();
});
it('Returns fields from a message', async () => {
const [sender, recipient] = await ethers.getSigners();
const nonce = 1;
const body = ethers.utils.formatBytes32String('message');
const message = abacus.formatMessage(
remoteDomain,
sender.address,
nonce,
localDomain,
recipient.address,
body,
);
expect(await messageLib.origin(message)).to.equal(remoteDomain);
expect(await messageLib.sender(message)).to.equal(
abacus.ethersAddressToBytes32(sender.address),
);
expect(await messageLib.nonce(message)).to.equal(nonce);
expect(await messageLib.destination(message)).to.equal(localDomain);
expect(await messageLib.recipient(message)).to.equal(
abacus.ethersAddressToBytes32(recipient.address),
);
expect(await messageLib.recipientAddress(message)).to.equal(
recipient.address,
);
expect(await messageLib.body(message)).to.equal(body);
});
it('Matches Rust-output AbacusMessage and leaf', async () => {
const origin = 1000;
const sender = '0x1111111111111111111111111111111111111111';
const nonce = 1;
const destination = 2000;
const recipient = '0x2222222222222222222222222222222222222222';
const body = ethers.utils.arrayify('0x1234');
const abacusMessage = abacus.formatMessage(
origin,
sender,
nonce,
destination,
recipient,
body,
);
const {
origin: testOrigin,
sender: testSender,
nonce: testNonce,
destination: testDestination,
recipient: testRecipient,
body: testBody,
messageHash,
} = testCases[0];
expect(await messageLib.origin(abacusMessage)).to.equal(testOrigin);
expect(await messageLib.sender(abacusMessage)).to.equal(testSender);
expect(await messageLib.nonce(abacusMessage)).to.equal(testNonce);
expect(await messageLib.destination(abacusMessage)).to.equal(
testDestination,
);
expect(await messageLib.recipient(abacusMessage)).to.equal(testRecipient);
expect(await messageLib.body(abacusMessage)).to.equal(
ethers.utils.hexlify(testBody),
);
expect(await messageLib.leaf(abacusMessage)).to.equal(messageHash);
expect(abacus.messageHash(abacusMessage)).to.equal(messageHash);
});
});