@@ -2,6 +2,7 @@ import { describe, it } from "node:test";
22import * as anchor from "@coral-xyz/anchor" ;
33import { Keypair , LAMPORTS_PER_SOL , PublicKey } from "@solana/web3.js" ;
44import { BankrunProvider } from "anchor-bankrun" ;
5+ import BN from "bn.js" ;
56import { assert } from "chai" ;
67import { startAnchor } from "solana-bankrun" ;
78import type { PdaRentPayer } from "../target/types/pda_rent_payer" ;
@@ -10,57 +11,57 @@ import IDL from "../target/idl/pda_rent_payer.json" with { type: "json" };
1011const PROGRAM_ID = new PublicKey ( IDL . address ) ;
1112
1213describe ( "PDA Rent-Payer" , async ( ) => {
13- const context = await startAnchor (
14- "" ,
15- [ { name : "pda_rent_payer" , programId : PROGRAM_ID } ] ,
16- [ ] ,
17- ) ;
18- const provider = new BankrunProvider ( context ) ;
19- const program = new anchor . Program < PdaRentPayer > ( IDL , provider ) ;
14+ const context = await startAnchor (
15+ "" ,
16+ [ { name : "pda_rent_payer" , programId : PROGRAM_ID } ] ,
17+ [ ] ,
18+ ) ;
19+ const provider = new BankrunProvider ( context ) ;
20+ const program = new anchor . Program < PdaRentPayer > ( IDL , provider ) ;
2021
21- const wallet = provider . wallet as anchor . Wallet ;
22- const connection = provider . connection ;
22+ const wallet = provider . wallet as anchor . Wallet ;
23+ const connection = provider . connection ;
2324
24- // PDA for the Rent Vault
25- const [ rentVaultPDA ] = PublicKey . findProgramAddressSync (
26- [ Buffer . from ( "rent_vault" ) ] ,
27- program . programId ,
28- ) ;
25+ // PDA for the Rent Vault
26+ const [ rentVaultPDA ] = PublicKey . findProgramAddressSync (
27+ [ Buffer . from ( "rent_vault" ) ] ,
28+ program . programId ,
29+ ) ;
2930
30- it ( "Initialize the Rent Vault" , async ( ) => {
31- // 1 SOL
32- const fundAmount = new anchor . BN ( LAMPORTS_PER_SOL ) ;
31+ it ( "Initialize the Rent Vault" , async ( ) => {
32+ // 1 SOL
33+ const fundAmount = new BN ( LAMPORTS_PER_SOL ) ;
3334
34- await program . methods
35- . initRentVault ( fundAmount )
36- . accounts ( {
37- payer : wallet . publicKey ,
38- } )
39- . rpc ( ) ;
35+ await program . methods
36+ . initRentVault ( fundAmount )
37+ . accounts ( {
38+ payer : wallet . publicKey ,
39+ } )
40+ . rpc ( ) ;
4041
41- // Check rent vault balance
42- const accountInfo =
43- await program . provider . connection . getAccountInfo ( rentVaultPDA ) ;
44- assert ( accountInfo . lamports === fundAmount . toNumber ( ) ) ;
45- } ) ;
42+ // Check rent vault balance
43+ const accountInfo =
44+ await program . provider . connection . getAccountInfo ( rentVaultPDA ) ;
45+ assert ( accountInfo . lamports === fundAmount . toNumber ( ) ) ;
46+ } ) ;
4647
47- it ( "Create a new account using the Rent Vault" , async ( ) => {
48- // Generate a new keypair for the new account
49- const newAccount = new Keypair ( ) ;
48+ it ( "Create a new account using the Rent Vault" , async ( ) => {
49+ // Generate a new keypair for the new account
50+ const newAccount = new Keypair ( ) ;
5051
51- await program . methods
52- . createNewAccount ( )
53- . accounts ( {
54- newAccount : newAccount . publicKey ,
55- } )
56- . signers ( [ newAccount ] )
57- . rpc ( ) ;
52+ await program . methods
53+ . createNewAccount ( )
54+ . accounts ( {
55+ newAccount : newAccount . publicKey ,
56+ } )
57+ . signers ( [ newAccount ] )
58+ . rpc ( ) ;
5859
59- // Minimum balance for rent exemption for new account
60- const lamports = await connection . getMinimumBalanceForRentExemption ( 0 ) ;
60+ // Minimum balance for rent exemption for new account
61+ const lamports = await connection . getMinimumBalanceForRentExemption ( 0 ) ;
6162
62- // Check that the account was created
63- const accountInfo = await connection . getAccountInfo ( newAccount . publicKey ) ;
64- assert ( accountInfo . lamports === lamports ) ;
65- } ) ;
63+ // Check that the account was created
64+ const accountInfo = await connection . getAccountInfo ( newAccount . publicKey ) ;
65+ assert ( accountInfo . lamports === lamports ) ;
66+ } ) ;
6667} ) ;
0 commit comments