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.
91 lines
2.7 KiB
91 lines
2.7 KiB
3 years ago
|
import { ethers } from 'hardhat';
|
||
3 years ago
|
import { expect } from 'chai';
|
||
3 years ago
|
import { utils } from '@abacus-network/utils';
|
||
3 years ago
|
import { TestMessage, TestMessage__factory } from '../types';
|
||
3 years ago
|
|
||
3 years ago
|
const testCases = require('../../../vectors/message.json');
|
||
4 years ago
|
|
||
4 years ago
|
const remoteDomain = 1000;
|
||
|
const localDomain = 2000;
|
||
4 years ago
|
|
||
|
describe('Message', async () => {
|
||
3 years ago
|
let messageLib: TestMessage;
|
||
4 years ago
|
|
||
|
before(async () => {
|
||
3 years ago
|
const [signer] = await ethers.getSigners();
|
||
|
|
||
|
const Message = new TestMessage__factory(signer);
|
||
|
messageLib = await Message.deploy();
|
||
4 years ago
|
});
|
||
|
|
||
|
it('Returns fields from a message', async () => {
|
||
3 years ago
|
const [sender, recipient] = await ethers.getSigners();
|
||
3 years ago
|
const nonce = 1;
|
||
4 years ago
|
const body = ethers.utils.formatBytes32String('message');
|
||
|
|
||
3 years ago
|
const message = utils.formatMessage(
|
||
4 years ago
|
remoteDomain,
|
||
4 years ago
|
sender.address,
|
||
3 years ago
|
nonce,
|
||
4 years ago
|
localDomain,
|
||
4 years ago
|
recipient.address,
|
||
|
body,
|
||
|
);
|
||
|
|
||
4 years ago
|
expect(await messageLib.origin(message)).to.equal(remoteDomain);
|
||
4 years ago
|
expect(await messageLib.sender(message)).to.equal(
|
||
3 years ago
|
utils.addressToBytes32(sender.address),
|
||
4 years ago
|
);
|
||
3 years ago
|
expect(await messageLib.nonce(message)).to.equal(nonce);
|
||
4 years ago
|
expect(await messageLib.destination(message)).to.equal(localDomain);
|
||
4 years ago
|
expect(await messageLib.recipient(message)).to.equal(
|
||
3 years ago
|
utils.addressToBytes32(recipient.address),
|
||
4 years ago
|
);
|
||
|
expect(await messageLib.recipientAddress(message)).to.equal(
|
||
|
recipient.address,
|
||
|
);
|
||
|
expect(await messageLib.body(message)).to.equal(body);
|
||
|
});
|
||
4 years ago
|
|
||
3 years ago
|
it('Matches Rust-output AbacusMessage and leaf', async () => {
|
||
4 years ago
|
const origin = 1000;
|
||
|
const sender = '0x1111111111111111111111111111111111111111';
|
||
3 years ago
|
const nonce = 1;
|
||
3 years ago
|
const destination = 2000;
|
||
|
const recipient = '0x2222222222222222222222222222222222222222';
|
||
3 years ago
|
const body = '0x1234';
|
||
4 years ago
|
|
||
3 years ago
|
const abacusMessage = utils.formatMessage(
|
||
4 years ago
|
origin,
|
||
|
sender,
|
||
3 years ago
|
nonce,
|
||
4 years ago
|
destination,
|
||
|
recipient,
|
||
|
body,
|
||
|
);
|
||
|
|
||
|
const {
|
||
|
origin: testOrigin,
|
||
|
sender: testSender,
|
||
3 years ago
|
nonce: testNonce,
|
||
3 years ago
|
destination: testDestination,
|
||
|
recipient: testRecipient,
|
||
4 years ago
|
body: testBody,
|
||
3 years ago
|
messageHash,
|
||
4 years ago
|
} = testCases[0];
|
||
|
|
||
3 years ago
|
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(
|
||
4 years ago
|
testDestination,
|
||
|
);
|
||
3 years ago
|
expect(await messageLib.recipient(abacusMessage)).to.equal(testRecipient);
|
||
|
expect(await messageLib.body(abacusMessage)).to.equal(
|
||
4 years ago
|
ethers.utils.hexlify(testBody),
|
||
|
);
|
||
3 years ago
|
expect(await messageLib.leaf(abacusMessage)).to.equal(messageHash);
|
||
3 years ago
|
expect(utils.messageHash(abacusMessage)).to.equal(messageHash);
|
||
4 years ago
|
});
|
||
4 years ago
|
});
|