bankrun.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 Idl from '../target/idl/rent_example.json';
  7. import type { RentExample } from '../target/types/rent_example';
  8. const IDL = require('../target/idl/rent_example.json');
  9. const PROGRAM_ID = new PublicKey(IDL.address);
  10. describe('Bankrun example', async () => {
  11. const context = await startAnchor('', [{ name: 'rent_example', programId: PROGRAM_ID }], []);
  12. const provider = new BankrunProvider(context);
  13. const wallet = provider.wallet as anchor.Wallet;
  14. const program = new anchor.Program<RentExample>(IDL, provider);
  15. it('Create the account', async () => {
  16. const newKeypair = anchor.web3.Keypair.generate();
  17. const addressData: anchor.IdlTypes<RentExample>['addressData'] = {
  18. name: 'Marcus',
  19. address: '123 Main St. San Francisco, CA',
  20. };
  21. // We're just going to serialize our object here so we can check
  22. // the size on the client side against the program logs
  23. //
  24. const addressDataBuffer = new anchor.BorshCoder(Idl as anchor.Idl).types.encode('AddressData', addressData);
  25. console.log(`Address data buffer length: ${addressDataBuffer.length}`);
  26. await program.methods
  27. .createSystemAccount(addressData)
  28. .accounts({
  29. payer: wallet.publicKey,
  30. newAccount: newKeypair.publicKey,
  31. })
  32. .signers([wallet.payer, newKeypair])
  33. .rpc();
  34. });
  35. });