Skip to content

Commit ae6bd75

Browse files
committed
chore: add bankrun test
1 parent 371c8a6 commit ae6bd75

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

basics/account-data/poseidon/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
"@types/bn.js": "^5.1.0",
1212
"@types/chai": "^4.3.0",
1313
"@types/mocha": "^9.0.0",
14+
"anchor-bankrun": "^0.5.0",
1415
"chai": "^4.3.4",
1516
"mocha": "^9.0.3",
1617
"prettier": "^2.6.2",
18+
"solana-bankrun": "^0.4.0",
1719
"ts-mocha": "^10.0.0",
1820
"typescript": "^4.3.5"
1921
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, it } from 'node:test';
2+
import * as anchor from '@coral-xyz/anchor';
3+
import { PublicKey } from '@solana/web3.js';
4+
import { BankrunProvider } from 'anchor-bankrun';
5+
import { startAnchor } from 'solana-bankrun';
6+
import type { AccountData } from '../target/types/account_data';
7+
8+
const IDL = require('../target/idl/account_data.json');
9+
const PROGRAM_ID = new PublicKey(IDL.address);
10+
11+
describe('Account Data!', async () => {
12+
const context = await startAnchor('', [{ name: 'account_data', programId: PROGRAM_ID }], []);
13+
const provider = new BankrunProvider(context);
14+
15+
const payer = provider.wallet as anchor.Wallet;
16+
const program = new anchor.Program<AccountData>(IDL, provider);
17+
18+
// Generate a new keypair for the addressInfo account
19+
const [addressInfoAccount] = PublicKey.findProgramAddressSync([Buffer.from('address_info'), payer.publicKey.toBuffer()], program.programId);
20+
21+
it('Create the address info account', async () => {
22+
console.log(`Payer Address : ${payer.publicKey}`);
23+
console.log(`Address Info Acct : ${addressInfoAccount}`);
24+
25+
// Instruction Ix data
26+
const addressInfo = {
27+
name: 'Joe C',
28+
houseNumber: 136,
29+
street: 'Mile High Dr.',
30+
city: 'Solana Beach',
31+
};
32+
33+
await program.methods
34+
.createAddressInfo(addressInfo.name, addressInfo.houseNumber, addressInfo.street, addressInfo.city)
35+
.accounts({
36+
addressInfo: addressInfoAccount,
37+
payer: payer.publicKey,
38+
})
39+
.rpc();
40+
});
41+
42+
it("Read the new account's data", async () => {
43+
const addressInfo = await program.account.addressInfo.fetch(addressInfoAccount);
44+
console.log(`Name : ${addressInfo.name}`);
45+
console.log(`House Num: ${addressInfo.houseNumber}`);
46+
console.log(`Street : ${addressInfo.street}`);
47+
console.log(`City : ${addressInfo.city}`);
48+
});
49+
});

0 commit comments

Comments
 (0)