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/test/lib/mailboxes.ts

58 lines
1.3 KiB

import { expect } from 'chai';
import { ethers } from 'ethers';
import { utils } from '@hyperlane-xyz/utils';
import { TestOutbox } from '../../types';
import { DispatchEvent } from '../../types/contracts/Outbox';
export const dispatchMessage = async (
outbox: TestOutbox,
destination: number,
recipient: string,
messageStr: string,
) => {
const tx = await outbox.dispatch(
destination,
recipient,
ethers.utils.toUtf8Bytes(messageStr),
);
const receipt = await tx.wait();
const dispatch = receipt.events![0] as DispatchEvent;
expect(dispatch.event).to.equal('Dispatch');
return dispatch.args!;
};
export const dispatchMessageAndReturnProof = async (
outbox: TestOutbox,
destination: number,
recipient: string,
messageStr: string,
): Promise<MerkleProof> => {
const { leafIndex, message } = await dispatchMessage(
outbox,
destination,
recipient,
messageStr,
);
const index = leafIndex.toNumber();
const messageHash = utils.messageHash(message, index);
const root = await outbox.root();
const proof = await outbox.proof();
return {
root,
proof: proof,
leaf: messageHash,
index,
message,
};
};
export interface MerkleProof {
root: string;
proof: string[];
leaf: string;
index: number;
message: string;
}