close-account.test.ts 1.3 KB

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