addMemo.test.ts 774 B

123456789101112131415161718192021
  1. import { utf8 } from '@metaplex-foundation/umi/serializers';
  2. import test from 'ava';
  3. import { addMemo } from '../src/index.js';
  4. import { createUmi } from './_setup.js';
  5. test('it adds custom text to the transaction logs', async (t) => {
  6. // Given a payer wallet.
  7. const umi = await createUmi();
  8. // When we create a transaction with a custom memo.
  9. const { signature } = await addMemo(umi, {
  10. memo: 'Hello world!',
  11. }).sendAndConfirm(umi);
  12. // Then the instruction data contains our memo.
  13. const transaction = await umi.rpc.getTransaction(signature);
  14. const instructionDataBytes =
  15. transaction?.message.instructions[0].data ?? new Uint8Array();
  16. const [instructionMemo] = utf8.deserialize(instructionDataBytes);
  17. t.is(instructionMemo, 'Hello world!');
  18. });