mint-close-authority.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { MintCloseAuthority } from "../target/types/mint_close_authority";
  4. import { TOKEN_2022_PROGRAM_ID, closeAccount } from "@solana/spl-token";
  5. describe("mint-close-authority", () => {
  6. // Configure the client to use the local cluster.
  7. const provider = anchor.AnchorProvider.env();
  8. const connection = provider.connection;
  9. const wallet = provider.wallet as anchor.Wallet;
  10. anchor.setProvider(provider);
  11. const program = anchor.workspace
  12. .MintCloseAuthority as Program<MintCloseAuthority>;
  13. const mintKeypair = new anchor.web3.Keypair();
  14. it("Create Mint with Close Authority", async () => {
  15. const transactionSignature = await program.methods
  16. .initialize()
  17. .accounts({ mintAccount: mintKeypair.publicKey })
  18. .signers([mintKeypair])
  19. .rpc({ skipPreflight: true });
  20. console.log("Your transaction signature", transactionSignature);
  21. });
  22. it("Close Mint with Anchor CPI", async () => {
  23. const transactionSignature = await program.methods
  24. .close()
  25. .accounts({ mintAccount: mintKeypair.publicKey })
  26. .rpc({ skipPreflight: true });
  27. console.log("Your transaction signature", transactionSignature);
  28. });
  29. it("Create Mint with Close Authority again", async () => {
  30. const transactionSignature = await program.methods
  31. .initialize()
  32. .accounts({ mintAccount: mintKeypair.publicKey })
  33. .signers([mintKeypair])
  34. .rpc({ skipPreflight: true });
  35. console.log("Your transaction signature", transactionSignature);
  36. });
  37. it("Close Mint using @solana/spl-token", async () => {
  38. const transactionSignature = await closeAccount(
  39. connection,
  40. wallet.payer, // Transaction fee payer
  41. mintKeypair.publicKey, // Mint Account address
  42. wallet.publicKey, // Account to receive lamports from closed account
  43. wallet.publicKey, // Close Authority for Mint Account
  44. undefined, // Additional signers
  45. undefined, // Confirmation options
  46. TOKEN_2022_PROGRAM_ID // Token Extension Program ID
  47. );
  48. console.log("Your transaction signature", transactionSignature);
  49. });
  50. });