close-account.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. Connection,
  3. Keypair,
  4. PublicKey,
  5. sendAndConfirmTransaction,
  6. Transaction,
  7. } from '@solana/web3.js';
  8. import {
  9. describe,
  10. it,
  11. } from 'mocha';
  12. import {
  13. createCreateUserInstruction,
  14. createCloseUserInstruction,
  15. createKeypairFromFile,
  16. } from '../ts';
  17. describe("Close Account!", async () => {
  18. const connection = new Connection(`http://localhost:8899`, 'confirmed');
  19. const payer = createKeypairFromFile(require('os').homedir() + '/.config/solana/id.json');
  20. const program = createKeypairFromFile('./program/target/deploy/program-keypair.json');
  21. const testAccountPublicKey = PublicKey.findProgramAddressSync(
  22. [Buffer.from("USER"), payer.publicKey.toBuffer()],
  23. program.publicKey,
  24. )[0];
  25. it("Create the account", async () => {
  26. console.log(`${testAccountPublicKey}`);
  27. const ix = createCreateUserInstruction(
  28. testAccountPublicKey,
  29. payer.publicKey,
  30. program.publicKey,
  31. "Jacob",
  32. );
  33. await sendAndConfirmTransaction(
  34. connection,
  35. new Transaction().add(ix),
  36. [payer]
  37. );
  38. });
  39. it("Close the account", async () => {
  40. const ix = createCloseUserInstruction(
  41. testAccountPublicKey,
  42. payer.publicKey,
  43. program.publicKey,
  44. );
  45. await sendAndConfirmTransaction(
  46. connection,
  47. new Transaction().add(ix),
  48. [payer],
  49. { skipPreflight: true }
  50. );
  51. });
  52. });