createMint.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { generateKeyPairSigner, Account, some, none } from '@solana/kit';
  2. import test from 'ava';
  3. import { fetchMint, Mint, getCreateMintInstructionPlan } from '../src';
  4. import {
  5. createDefaultSolanaClient,
  6. generateKeyPairSignerWithSol,
  7. createDefaultTransactionPlanner,
  8. } from './_setup';
  9. test('it creates and initializes a new mint account', async (t) => {
  10. // Given an authority and a mint account.
  11. const client = createDefaultSolanaClient();
  12. const authority = await generateKeyPairSignerWithSol(client);
  13. const mint = await generateKeyPairSigner();
  14. // When we create and initialize a mint account at this address.
  15. const instructionPlan = getCreateMintInstructionPlan({
  16. payer: authority,
  17. newMint: mint,
  18. decimals: 2,
  19. mintAuthority: authority.address,
  20. });
  21. const transactionPlanner = createDefaultTransactionPlanner(client, authority);
  22. const transactionPlan = await transactionPlanner(instructionPlan);
  23. await client.sendTransactionPlan(transactionPlan);
  24. // Then we expect the mint account to exist and have the following data.
  25. const mintAccount = await fetchMint(client.rpc, mint.address);
  26. t.like(mintAccount, <Account<Mint>>{
  27. address: mint.address,
  28. data: {
  29. mintAuthority: some(authority.address),
  30. supply: 0n,
  31. decimals: 2,
  32. isInitialized: true,
  33. freezeAuthority: none(),
  34. },
  35. });
  36. });
  37. test('it creates a new mint account with a freeze authority', async (t) => {
  38. // Given an authority and a mint account.
  39. const client = createDefaultSolanaClient();
  40. const [payer, mintAuthority, freezeAuthority, mint] = await Promise.all([
  41. generateKeyPairSignerWithSol(client),
  42. generateKeyPairSigner(),
  43. generateKeyPairSigner(),
  44. generateKeyPairSigner(),
  45. ]);
  46. // When we create and initialize a mint account at this address.
  47. const instructionPlan = getCreateMintInstructionPlan({
  48. payer: payer,
  49. newMint: mint,
  50. decimals: 2,
  51. mintAuthority: mintAuthority.address,
  52. freezeAuthority: freezeAuthority.address,
  53. });
  54. const transactionPlanner = createDefaultTransactionPlanner(client, payer);
  55. const transactionPlan = await transactionPlanner(instructionPlan);
  56. await client.sendTransactionPlan(transactionPlan);
  57. // Then we expect the mint account to exist and have the following data.
  58. const mintAccount = await fetchMint(client.rpc, mint.address);
  59. t.like(mintAccount, <Account<Mint>>{
  60. address: mint.address,
  61. data: {
  62. mintAuthority: some(mintAuthority.address),
  63. freezeAuthority: some(freezeAuthority.address),
  64. },
  65. });
  66. });