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" ;
88
9- const IDL = require ( ' ../target/idl/close_account_program.json' ) ;
9+ const IDL = require ( " ../target/idl/close_account_program.json" ) ;
1010const PROGRAM_ID = new PublicKey ( IDL . address ) ;
1111
12- describe ( 'close-account' , async ( ) => {
13- // Configure the client to use the local cluster.
14- const context = await startAnchor ( '' , [ { name : 'close_account_program' , programId : PROGRAM_ID } ] , [ ] ) ;
15- const provider = new BankrunProvider ( context ) ;
12+ describe ( "close-account" , async ( ) => {
13+ // Configure the client to use the local cluster.
14+ const context = await startAnchor (
15+ "" ,
16+ [ { name : "close_account_program" , programId : PROGRAM_ID } ] ,
17+ [ ] ,
18+ ) ;
19+ const provider = new BankrunProvider ( context ) ;
1620
17- const payer = provider . wallet as anchor . Wallet ;
18- const program = new anchor . Program < CloseAccountProgram > ( IDL , provider ) ;
19- // Derive the PDA for the user's account.
20- const [ userAccountAddress ] = PublicKey . findProgramAddressSync ( [ Buffer . from ( 'user' ) , payer . publicKey . toBuffer ( ) ] , program . programId ) ;
21+ const payer = provider . wallet as anchor . Wallet ;
22+ const program = new anchor . Program < CloseAccountProgram > ( IDL , provider ) ;
23+ // Derive the PDA for the user's account.
24+ const [ userAccountAddress ] = PublicKey . findProgramAddressSync (
25+ [ Buffer . from ( "user" ) , payer . publicKey . toBuffer ( ) ] ,
26+ program . programId ,
27+ ) ;
2128
22- it ( ' Create Account' , async ( ) => {
23- await program . methods
24- . createUser ( )
25- . accounts ( {
26- user : payer . publicKey ,
27- } )
28- . rpc ( ) ;
29+ it ( " Create Account" , async ( ) => {
30+ await program . methods
31+ . createUser ( )
32+ . accounts ( {
33+ user : payer . publicKey ,
34+ } )
35+ . rpc ( ) ;
2936
30- // Fetch the account data
31- const userAccount = await program . account . closeAccountState . fetch ( userAccountAddress ) ;
32- assert . equal ( userAccount . user . toBase58 ( ) , payer . publicKey . toBase58 ( ) ) ;
33- } ) ;
37+ // Fetch the account data
38+ const userAccount =
39+ await program . account . closeAccountState . fetch ( userAccountAddress ) ;
40+ assert . equal ( userAccount . user . toBase58 ( ) , payer . publicKey . toBase58 ( ) ) ;
41+ } ) ;
3442
35- it ( ' Close Account' , async ( ) => {
36- await program . methods
37- . closeUser ( )
38- . accounts ( {
39- user : payer . publicKey ,
40- } )
41- . rpc ( ) ;
43+ it ( " Close Account" , async ( ) => {
44+ await program . methods
45+ . closeUser ( )
46+ . accounts ( {
47+ user : payer . publicKey ,
48+ } )
49+ . rpc ( ) ;
4250
43- // The account should no longer exist, returning null.
44- try {
45- const userAccount = await program . account . closeAccountState . fetchNullable ( userAccountAddress ) ;
46- assert . equal ( userAccount , null ) ;
47- } catch ( err ) {
48- // Won't return null and will throw an error in anchor-bankrun'
49- assert . equal ( err . message , `Could not find ${ userAccountAddress } ` ) ;
50- }
51- } ) ;
52- } ) ;
51+ // The account should no longer exist, returning null.
52+ try {
53+ const userAccount =
54+ await program . account . closeAccountState . fetchNullable (
55+ userAccountAddress ,
56+ ) ;
57+ assert . equal ( userAccount , null ) ;
58+ } catch ( err ) {
59+ // Won't return null and will throw an error in anchor-bankrun'
60+ assert . equal ( err . message , `Could not find ${ userAccountAddress } ` ) ;
61+ }
62+ } ) ;
63+ } ) ;
0 commit comments