test.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import {
  2. PublicKey,
  3. Transaction,
  4. TransactionInstruction,
  5. } from '@solana/web3.js';
  6. import { start } from 'solana-bankrun';
  7. import { describe, test } from 'node:test';
  8. describe('hello-solana', async () => {
  9. // load program in solana-bankrun
  10. const PROGRAM_ID = PublicKey.unique();
  11. const context = await start([{ name: 'hello_solana_program', programId: PROGRAM_ID }],[]);
  12. const client = context.banksClient;
  13. const payer = context.payer;
  14. test('Say hello!', async () => {
  15. const blockhash = context.lastBlockhash;
  16. // We set up our instruction first.
  17. let ix = new TransactionInstruction({
  18. keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }],
  19. programId: PROGRAM_ID,
  20. data: Buffer.alloc(0), // No data
  21. });
  22. const tx = new Transaction();
  23. tx.recentBlockhash = blockhash;
  24. tx.add(ix).sign(payer);
  25. // Now we process the transaction
  26. let transaction = await client.processTransaction(tx);
  27. console.log(transaction?.meta?.logMessages);
  28. });
  29. });