Skip to content

Commit 5596fba

Browse files
committed
test actions
1 parent f6d70c2 commit 5596fba

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, test } from 'node:test';
2+
import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js';
3+
import { assert } from 'chai';
4+
import { start } from 'solana-bankrun';
5+
6+
describe('hello-solana', async () => {
7+
// load program in solana-bankrun
8+
const PROGRAM_ID = PublicKey.unique();
9+
const context = await start([{ name: 'hello_solana_program', programId: PROGRAM_ID }], []);
10+
const client = context.banksClient;
11+
const payer = context.payer;
12+
13+
test('Say hello!', async () => {
14+
const blockhash = context.lastBlockhash;
15+
// We set up our instruction first.
16+
const ix = new TransactionInstruction({
17+
keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }],
18+
programId: PROGRAM_ID,
19+
data: Buffer.alloc(0), // No data
20+
});
21+
22+
const tx = new Transaction();
23+
tx.recentBlockhash = blockhash;
24+
tx.add(ix).sign(payer);
25+
26+
// Now we process the transaction
27+
const transaction = await client.processTransaction(tx);
28+
29+
assert(transaction.logMessages[0].startsWith(`Program ${PROGRAM_ID}`));
30+
assert(transaction.logMessages[1] === 'Program log: Hello, Solana!');
31+
assert(transaction.logMessages[2] === `Program log: Our program's Program ID: ${PROGRAM_ID}`);
32+
assert(transaction.logMessages[3].startsWith(`Program ${PROGRAM_ID} consumed`));
33+
assert(transaction.logMessages[4] === `Program ${PROGRAM_ID} success`);
34+
assert(transaction.logMessages.length === 5);
35+
});
36+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, test } from 'node:test';
2+
import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js';
3+
import { assert } from 'chai';
4+
import { start } from 'solana-bankrun';
5+
6+
describe('hello-solana', async () => {
7+
// load program in solana-bankrun
8+
const PROGRAM_ID = PublicKey.unique();
9+
const context = await start([{ name: 'steel_hello_solana', programId: PROGRAM_ID }], []);
10+
const client = context.banksClient;
11+
const payer = context.payer;
12+
13+
test('Say hello!', async () => {
14+
const blockhash = context.lastBlockhash;
15+
// We set up our instruction first.
16+
const ix = new TransactionInstruction({
17+
keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }],
18+
programId: PROGRAM_ID,
19+
data: Buffer.alloc(0), // No data
20+
});
21+
22+
const tx = new Transaction();
23+
tx.recentBlockhash = blockhash;
24+
tx.add(ix).sign(payer);
25+
26+
// Now we process the transaction
27+
const transaction = await client.processTransaction(tx);
28+
29+
assert(transaction.logMessages[0].startsWith(`Program ${PROGRAM_ID}`));
30+
assert(transaction.logMessages[1] === 'Program log: Hello, Solana!');
31+
assert(transaction.logMessages[2] === `Program log: Our program's Program ID: ${PROGRAM_ID}`);
32+
assert(transaction.logMessages[3].startsWith(`Program ${PROGRAM_ID} consumed`));
33+
assert(transaction.logMessages[4] === `Program ${PROGRAM_ID} success`);
34+
assert(transaction.logMessages.length === 5);
35+
});
36+
});

0 commit comments

Comments
 (0)