bankrun.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, it } from 'node:test';
  2. import * as anchor from '@coral-xyz/anchor';
  3. import { Program } from '@coral-xyz/anchor';
  4. import { BankrunProvider } from 'anchor-bankrun';
  5. import { assert } from 'chai';
  6. import { startAnchor } from 'solana-bankrun';
  7. import type { ProcessingInstructionsProgram } from '../target/types/processing_instructions_program';
  8. const IDL = require('../target/idl/processing_instructions_program.json');
  9. const PROGRAM_ID = new anchor.web3.PublicKey(IDL.address);
  10. describe('Bankrun - processing_instructions_program', async () => {
  11. // Start the Bankrun context
  12. const context = await startAnchor('', [{ name: 'processing_instructions_program', programId: PROGRAM_ID }], []);
  13. const provider = new BankrunProvider(context);
  14. anchor.setProvider(provider);
  15. const program = new anchor.Program<ProcessingInstructionsProgram>(IDL, provider);
  16. const payer = provider.wallet as anchor.Wallet;
  17. it('Tests the go_to_park function', async () => {
  18. // Define the test parameters
  19. const height = 6;
  20. const name = 'Alice';
  21. // Call the go_to_park function in the Solana program
  22. const tx = await program.methods
  23. .goToPark(height, name)
  24. .accounts({
  25. user: payer.publicKey,
  26. })
  27. .signers([payer.payer])
  28. .rpc();
  29. console.log('Your transaction signature', tx);
  30. // Assertions can be made here based on expected behavior
  31. // Since we are using msg! for console messages, we don't have a direct way to capture these outputs in tests
  32. // However, we can still verify the transaction was successful
  33. assert.isNotNull(tx, 'Transaction should be successful');
  34. });
  35. });