close-account.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { PublicKey, Transaction } from '@solana/web3.js';
  2. import { describe, test } from 'node:test';
  3. import { createCreateUserInstruction, createCloseUserInstruction } from '../ts';
  4. import { start } from 'solana-bankrun';
  5. describe('Close Account!', async () => {
  6. const PROGRAM_ID = PublicKey.unique();
  7. const context = await start(
  8. [{ name: 'close_account_native_program', programId: PROGRAM_ID }],
  9. []
  10. );
  11. const client = context.banksClient;
  12. const payer = context.payer;
  13. const testAccountPublicKey = PublicKey.findProgramAddressSync(
  14. [Buffer.from('USER'), payer.publicKey.toBuffer()],
  15. PROGRAM_ID
  16. )[0];
  17. test('Create the account', async () => {
  18. const blockhash = context.lastBlockhash;
  19. const ix = createCreateUserInstruction(
  20. testAccountPublicKey,
  21. payer.publicKey,
  22. PROGRAM_ID,
  23. 'Jacob'
  24. );
  25. const tx = new Transaction();
  26. tx.recentBlockhash = blockhash;
  27. tx.add(ix).sign(payer);
  28. await client.processTransaction(tx);
  29. });
  30. test('Close the account', async () => {
  31. const blockhash = context.lastBlockhash;
  32. const ix = createCloseUserInstruction(
  33. testAccountPublicKey,
  34. payer.publicKey,
  35. PROGRAM_ID
  36. );
  37. const tx = new Transaction();
  38. tx.recentBlockhash = blockhash;
  39. tx.add(ix).sign(payer);
  40. await client.processTransaction(tx);
  41. });
  42. });