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

56 lines
1.3 KiB

import { expect } from 'chai';
import { BigNumber, ethers } from 'ethers';
import { utils } from '@abacus-network/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 messageHash = utils.messageHash(message, leafIndex.toNumber());
const root = await outbox.root();
const proof = await outbox.proof();
return {
root,
proof: proof,
leaf: messageHash,
index: leafIndex,
message,
};
};
export interface MerkleProof {
root: string;
proof: string[];
leaf: string;
index: BigNumber;
message: string;
}