1+ import { describe , it } from "node:test" ;
2+ import * as anchor from "@anchor-lang/core" ;
3+ import { Keypair , PublicKey , SystemProgram , Transaction } from "@solana/web3.js" ;
4+ import { BankrunProvider } from "anchor-bankrun" ;
5+ import { startAnchor } from "solana-bankrun" ;
6+ import IDL from "../target/idl/account_data_anchor_program.json" with { type : "json" } ;
7+ import type { AccountDataAnchorProgram } from "../target/types/account_data_anchor_program" ;
8+ import { assert } from "chai" ;
9+
10+ const PROGRAM_ID = new PublicKey ( IDL . address ) ;
11+
12+
13+ describe ( "anchor-data" , async ( ) => {
14+ const context = await startAnchor ( "" , [ { name :"account_data_anchor_program" , programId :PROGRAM_ID } ] , [ ] ) ;
15+ const provider = new BankrunProvider ( context ) ;
16+ const program = new anchor . Program < AccountDataAnchorProgram > ( IDL , provider ) ;
17+
18+ const addressInfoAccount = new Keypair ( ) ;
19+
20+ await program . methods . createAddressInfo ( "Joe C" , 136 , "Mile High Dr." , "Solana Beach" )
21+ . accounts ( {
22+ addressInfo : addressInfoAccount . publicKey ,
23+ payer : provider . wallet . publicKey ,
24+ } )
25+ . signers ( [ addressInfoAccount ] )
26+ . rpc ( ) ;
27+
28+ assert . ok ( true )
29+ const addressInfo = await program . account . addressInfo . fetch ( addressInfoAccount . publicKey ) ;
30+ console . log ( `Name : ${ addressInfo . name } ` ) ;
31+ console . log ( `House Num: ${ addressInfo . houseNumber } ` ) ;
32+ console . log ( `Street : ${ addressInfo . street } ` ) ;
33+ console . log ( `City : ${ addressInfo . city } ` ) ;
34+
35+
36+ it ( "Read the new account's data" , async ( ) => {
37+ let account = await program . account . addressInfo . fetch ( addressInfoAccount . publicKey ) ;
38+ assert . equal ( account . name , "Joe C" ) ;
39+ assert . equal ( account . houseNumber , 136 ) ;
40+ assert . equal ( account . street , "Mile High Dr." ) ;
41+ assert . equal ( account . city , "Solana Beach" ) ;
42+ } )
43+ } )
0 commit comments