1
- import assert from " node:assert" ;
2
- import { describe , it } from " node:test" ;
3
- import * as anchor from " @coral-xyz/anchor" ;
4
- import { PublicKey } from " @solana/web3.js" ;
5
- import { BankrunProvider } from " anchor-bankrun" ;
6
- import { startAnchor } from " solana-bankrun" ;
7
- import type { CloseAccountProgram } from " ../target/types/close_account_program" ;
1
+ import assert from ' node:assert' ;
2
+ import { describe , it } from ' node:test' ;
3
+ import * as anchor from ' @coral-xyz/anchor' ;
4
+ import { PublicKey } from ' @solana/web3.js' ;
5
+ import { BankrunProvider } from ' anchor-bankrun' ;
6
+ import { startAnchor } from ' solana-bankrun' ;
7
+ import type { CloseAccountProgram } from ' ../target/types/close_account_program' ;
8
8
9
- const IDL = require ( " ../target/idl/close_account_program.json" ) ;
9
+ const IDL = require ( ' ../target/idl/close_account_program.json' ) ;
10
10
const PROGRAM_ID = new PublicKey ( IDL . address ) ;
11
11
12
- describe ( " Close an account" , async ( ) => {
12
+ describe ( ' Close an account' , async ( ) => {
13
13
// Configure the client to use the local cluster.
14
- const context = await startAnchor (
15
- "" ,
16
- [ { name : "close_account" , programId : PROGRAM_ID } ] ,
17
- [ ]
18
- ) ;
14
+ const context = await startAnchor ( '' , [ { name : 'close_account' , programId : PROGRAM_ID } ] , [ ] ) ;
19
15
const provider = new BankrunProvider ( context ) ;
20
16
21
17
const payer = provider . wallet as anchor . Wallet ;
22
18
const program = new anchor . Program < CloseAccountProgram > ( IDL , provider ) ;
23
19
// Derive the PDA for the user's account.
24
- const [ userAccountAddress ] = PublicKey . findProgramAddressSync (
25
- [ Buffer . from ( "USER" ) , payer . publicKey . toBuffer ( ) ] ,
26
- program . programId
27
- ) ;
20
+ const [ userAccountAddress ] = PublicKey . findProgramAddressSync ( [ Buffer . from ( 'USER' ) , payer . publicKey . toBuffer ( ) ] , program . programId ) ;
28
21
29
- it ( " Can create an account" , async ( ) => {
30
- const userId = anchor . BN ( 76362 )
22
+ it ( ' Can create an account' , async ( ) => {
23
+ const userId = anchor . BN ( 76362 ) ;
31
24
await program . methods
32
25
. createUser ( userId )
33
26
. accounts ( {
@@ -36,13 +29,11 @@ describe("Close an account", async () => {
36
29
. rpc ( ) ;
37
30
38
31
// Fetch the account data
39
- const userAccount = await program . account . userAccount . fetch (
40
- userAccountAddress
41
- ) ;
42
- assert . notEqual ( userAccount , null ) ;
32
+ const userAccount = await program . account . userAccount . fetch ( userAccountAddress ) ;
33
+ assert . notEqual ( userAccount , null ) ;
43
34
} ) ;
44
35
45
- it ( " Can close an Account" , async ( ) => {
36
+ it ( ' Can close an Account' , async ( ) => {
46
37
await program . methods
47
38
. closeUser ( )
48
39
. accounts ( {
@@ -52,9 +43,7 @@ describe("Close an account", async () => {
52
43
53
44
// The account should no longer exist, returning null.
54
45
try {
55
- const userAccount = await program . account . userAccount . fetchNullable (
56
- userAccountAddress
57
- ) ;
46
+ const userAccount = await program . account . userAccount . fetchNullable ( userAccountAddress ) ;
58
47
assert . equal ( userAccount , null ) ;
59
48
} catch ( err ) {
60
49
// Won't return null and will throw an error in anchor-bankrun'
0 commit comments