close-account.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { Program } from '@coral-xyz/anchor';
  3. import { assert } from 'chai';
  4. import { CloseAccount } from '../target/types/close_account';
  5. describe('close-account', () => {
  6. // Configure the client to use the local cluster.
  7. const provider = anchor.AnchorProvider.env();
  8. anchor.setProvider(provider);
  9. const program = anchor.workspace.CloseAccount as Program<CloseAccount>;
  10. const user = provider.wallet;
  11. const accountState = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('account')], program.programId)[0];
  12. const someData = Math.floor(Math.random() * 100);
  13. it('Can initalize an account', async () => {
  14. await program.methods
  15. .initalize(someData)
  16. .accounts({
  17. user: user.publicKey,
  18. })
  19. .rpc();
  20. const acc = await program.account.accountState.fetchNullable(accountState);
  21. assert.notEqual(acc, null);
  22. });
  23. it('Can close an account', async () => {
  24. await program.methods
  25. .close()
  26. .accounts({
  27. user: user.publicKey,
  28. })
  29. .rpc();
  30. const acc = await program.account.accountState.fetchNullable(accountState);
  31. assert.equal(acc, null);
  32. });
  33. });