Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Oct 9, 2024
1 parent eced233 commit 36f1a3d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
extension,
fetchToken,
getDisableMemoTransfersInstruction,
getEnableMemoTransfersInstruction,
} from '../../../src';
import {
createDefaultSolanaClient,
createMint,
createToken,
generateKeyPairSignerWithSol,
getCreateTokenInstructions,
sendAndConfirmInstructions,
Expand Down Expand Up @@ -58,3 +60,43 @@ test('it initializes a token account with a disabled memo transfers extension',
},
});
});

test('it disables an active memo transfers extension', async (t) => {
// Given some signer accounts.
const client = createDefaultSolanaClient();
const [authority, owner] = await Promise.all([
generateKeyPairSignerWithSol(client),
generateKeyPairSigner(),
]);

// And a token account with an active memo transfers extension.
const mint = await createMint({
authority: authority.address,
client,
payer: authority,
});
const token = await createToken({
client,
extensions: [
extension('MemoTransfer', { requireIncomingTransferMemos: true }),
],
mint,
owner: owner.address,
payer: authority,
});
await sendAndConfirmInstructions(client, authority, [
getEnableMemoTransfersInstruction({ token, owner }),
]);

// When we disable the memo transfers extension.
await sendAndConfirmInstructions(client, authority, [
getDisableMemoTransfersInstruction({ token, owner }),
]);

// Then we expect the token account to have the extension disabled.
const tokenAccount = await fetchToken(client.rpc, token);
t.deepEqual(
tokenAccount.data.extensions,
some([extension('MemoTransfer', { requireIncomingTransferMemos: false })])
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
Token,
extension,
fetchToken,
getDisableMemoTransfersInstruction,
getEnableMemoTransfersInstruction,
} from '../../../src';
import {
createDefaultSolanaClient,
createMint,
createToken,
generateKeyPairSignerWithSol,
getCreateTokenInstructions,
sendAndConfirmInstructions,
Expand Down Expand Up @@ -58,3 +60,43 @@ test('it initializes a token account with an active memo transfers extension', a
},
});
});

test('it enables an disabled memo transfers extension', async (t) => {
// Given some signer accounts.
const client = createDefaultSolanaClient();
const [authority, owner] = await Promise.all([
generateKeyPairSignerWithSol(client),
generateKeyPairSigner(),
]);

// And a token account with a disabled memo transfers extension.
const mint = await createMint({
authority: authority.address,
client,
payer: authority,
});
const token = await createToken({
client,
extensions: [
extension('MemoTransfer', { requireIncomingTransferMemos: false }),
],
mint,
owner: owner.address,
payer: authority,
});
await sendAndConfirmInstructions(client, authority, [
getDisableMemoTransfersInstruction({ token, owner }),
]);

// When we enable the memo transfers extension.
await sendAndConfirmInstructions(client, authority, [
getEnableMemoTransfersInstruction({ token, owner }),
]);

// Then we expect the token account to have the extension enabled.
const tokenAccount = await fetchToken(client.rpc, token);
t.deepEqual(
tokenAccount.data.extensions,
some([extension('MemoTransfer', { requireIncomingTransferMemos: true })])
);
});

0 comments on commit 36f1a3d

Please sign in to comment.