You can use the getMessages
method to retrieve a list of messages from the blockchain.
const WALLET_A = Wallet.fromPrivateKey(
'0x1ff16505df75735a5bcf4cb4cf839903120c181dd9be6781b82cda23543bd242',
provider
);
const WALLET_B = Wallet.fromPrivateKey(
'0x30bb0bc68f5d2ec3b523cee5a65503031b40679d9c72280cd8088c2cfbc34e38',
provider
);
const EXPECTED_MESSAGES_A: Message[] = [
{
sender: WALLET_B.address,
recipient: WALLET_A.address,
nonce: bn(1),
amount: bn(1),
data: arrayify(
'0x00000000000000080000000000000007000000000000000600000000000000050000000000000004'
),
daHeight: bn(0),
status: MessageStatus.Unspent,
},
];
const EXPECTED_MESSAGES_B: Message[] = [
{
sender: WALLET_A.address,
recipient: WALLET_B.address,
nonce: bn('1017517292834129547'),
amount: bn('12704439083013451934'),
data: arrayify('0x0000000000000007'),
daHeight: bn('3684546456337077810'),
status: MessageStatus.Unspent,
},
];
const aMessages = await WALLET_A.getMessages();
const bMessages = await WALLET_B.getMessages();
expect(aMessages).toStrictEqual(EXPECTED_MESSAGES_A);
expect(bMessages).toStrictEqual(EXPECTED_MESSAGES_B);