-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathbankrun.test.ts
65 lines (58 loc) · 1.64 KB
/
bankrun.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { describe, it } from 'node:test';
import * as anchor from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
import { BankrunProvider } from 'anchor-bankrun';
import { startAnchor } from 'solana-bankrun';
import type { Hand } from '../target/types/hand';
import type { Lever } from '../target/types/lever';
const HAND_IDL = require('../target/idl/hand.json');
const LEVER_IDL = require('../target/idl/lever.json');
const HAND_PROGRAM_ID = new PublicKey(HAND_IDL.address);
const LEVER_PROGRAM_ID = new PublicKey(LEVER_IDL.address);
describe('cpi', async () => {
const context = await startAnchor(
'',
[
{
name: 'hand',
programId: HAND_PROGRAM_ID,
},
{
name: 'lever',
programId: LEVER_PROGRAM_ID,
},
],
[],
);
const provider = new BankrunProvider(context);
const hand = new anchor.Program<Hand>(HAND_IDL, provider);
const lever = new anchor.Program<Lever>(LEVER_IDL, provider);
// Generate a new keypair for the power account
const powerAccount = new anchor.web3.Keypair();
it('Initialize the lever!', async () => {
await lever.methods
.initialize()
.accounts({
power: powerAccount.publicKey,
user: provider.wallet.publicKey,
})
.signers([powerAccount])
.rpc();
});
it('Pull the lever!', async () => {
await hand.methods
.pullLever('Chris')
.accounts({
power: powerAccount.publicKey,
})
.rpc();
});
it('Pull it again!', async () => {
await hand.methods
.pullLever('Ashley')
.accounts({
power: powerAccount.publicKey,
})
.rpc();
});
});