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- import { IDL } from "../target/idl/close_account_program.json" ;
9+ import IDL from "../target/idl/close_account_program.json" ;
1010const PROGRAM_ID = new PublicKey ( IDL . address ) ;
1111
12- describe ( ' close-an-account' , async ( ) => {
12+ describe ( " close-an-account" , async ( ) => {
1313 // Configure the client to use the local cluster.
14- const context = await startAnchor ( '' , [ { name : 'close_account_program' , programId : PROGRAM_ID } ] , [ ] ) ;
14+ const context = await startAnchor (
15+ "" ,
16+ [ { name : "close_account_program" , programId : PROGRAM_ID } ] ,
17+ [ ] ,
18+ ) ;
1519 const provider = new BankrunProvider ( context ) ;
1620
1721 const payer = provider . wallet as anchor . Wallet ;
1822 const program = new anchor . Program < CloseAccountProgram > ( IDL , provider ) ;
1923 // Derive the PDA for the user's account.
20- const [ userAccountAddress ] = PublicKey . findProgramAddressSync ( [ Buffer . from ( 'USER' ) , payer . publicKey . toBuffer ( ) ] , program . programId ) ;
24+ const [ userAccountAddress ] = PublicKey . findProgramAddressSync (
25+ [ Buffer . from ( "USER" ) , payer . publicKey . toBuffer ( ) ] ,
26+ program . programId ,
27+ ) ;
2128
22- it ( ' Create Account' , async ( ) => {
29+ it ( " Create Account" , async ( ) => {
2330 await program . methods
24- . createUser ( ' John Doe' )
31+ . createUser ( " John Doe" )
2532 . accounts ( {
2633 user : payer . publicKey ,
2734 } )
2835 . rpc ( ) ;
2936
3037 // Fetch the account data
31- const userAccount = await program . account . userState . fetch ( userAccountAddress ) ;
32- assert . equal ( userAccount . name , 'John Doe' ) ;
38+ const userAccount =
39+ await program . account . userState . fetch ( userAccountAddress ) ;
40+ assert . equal ( userAccount . name , "John Doe" ) ;
3341 assert . equal ( userAccount . user . toBase58 ( ) , payer . publicKey . toBase58 ( ) ) ;
3442 } ) ;
3543
36- it ( ' Close Account' , async ( ) => {
44+ it ( " Close Account" , async ( ) => {
3745 await program . methods
3846 . closeUser ( )
3947 . accounts ( {
@@ -43,7 +51,8 @@ describe('close-an-account', async () => {
4351
4452 // The account should no longer exist, returning null.
4553 try {
46- const userAccount = await program . account . userState . fetchNullable ( userAccountAddress ) ;
54+ const userAccount =
55+ await program . account . userState . fetchNullable ( userAccountAddress ) ;
4756 assert . equal ( userAccount , null ) ;
4857 } catch ( err ) {
4958 // Won't return null and will throw an error in anchor-bankrun'
0 commit comments