Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
add test scenario for transaction reference content type
Browse files Browse the repository at this point in the history
  • Loading branch information
lourou committed Jan 11, 2024
1 parent c483352 commit cf3b788
Showing 1 changed file with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,63 @@ import { Client } from "@xmtp/xmtp-js";
import { ContentTypeTransactionReference, TransactionReferenceCodec } from "./TransactionReference";
import type { TransactionReference } from "./TransactionReference";

// TODO
test("content type exists", () => {
expect(ContentTypeTransactionReference.authorityId).toBe("xmtp.org");
expect(ContentTypeTransactionReference.typeId).toBe("transactionReference");
expect(ContentTypeTransactionReference.versionMajor).toBe(1);
expect(ContentTypeTransactionReference.versionMinor).toBe(0);
});

test('should successfully send and receive a TransactionReference message', async () => {
const aliceWallet = Wallet.createRandom();
const aliceClient = await Client.create(aliceWallet, {
codecs: [new TransactionReferenceCodec()],
env: "local",
});
await aliceClient.publishUserContact();

const bobWallet = Wallet.createRandom();
const bobClient = await Client.create(bobWallet, {
codecs: [new TransactionReferenceCodec()],
env: "local",
});
await bobClient.publishUserContact();

const conversation = await aliceClient.conversations.newConversation(
bobWallet.address,
);

const transactionRefToSend: TransactionReference = {
namespace: "eip155",
networkId: "0x14a33",
reference: "0xa7cd32b79204559e46b4ef9b519fce58cedb25246f48d0c00bd628e873a81f2f",
metadata: {
transactionType: "transfer",
currency: "USDC",
amount: 1337,
decimals: 6,
fromAddress: aliceWallet.address,
toAddress: bobWallet.address,
},
};

await conversation.send(transactionRefToSend, {
contentType: ContentTypeTransactionReference,
});

const bobConversation = await bobClient.conversations.newConversation(
aliceWallet.address,
);

const messages = await bobConversation.messages();

expect(messages.length).toBe(1);

const message = messages[0];
const messageContent = message.content as TransactionReference;

expect(messageContent.namespace).toBe(transactionRefToSend.namespace);
expect(messageContent.networkId).toBe(transactionRefToSend.networkId);
expect(messageContent.reference).toBe(transactionRefToSend.reference);
expect(messageContent.metadata).toEqual(transactionRefToSend.metadata);
})

0 comments on commit cf3b788

Please sign in to comment.