bankrun.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { describe, it } from 'node:test';
  2. import * as anchor from '@coral-xyz/anchor';
  3. import { PublicKey } from '@solana/web3.js';
  4. import { Keypair, SystemProgram } from '@solana/web3.js';
  5. import { BankrunProvider } from 'anchor-bankrun';
  6. import { assert } from 'chai';
  7. import { startAnchor } from 'solana-bankrun';
  8. import type { CreateSystemAccount } from '../target/types/create_system_account';
  9. const IDL = require('../target/idl/create_system_account.json');
  10. const PROGRAM_ID = new PublicKey(IDL.address);
  11. describe('Create a system account', async () => {
  12. const context = await startAnchor('', [{ name: 'create_system_account', programId: PROGRAM_ID }], []);
  13. const provider = new BankrunProvider(context);
  14. const wallet = provider.wallet as anchor.Wallet;
  15. const program = new anchor.Program<CreateSystemAccount>(IDL, provider);
  16. const connection = provider.connection;
  17. it('Create the account', async () => {
  18. // Generate a new keypair for the new account
  19. const newKeypair = new Keypair();
  20. await program.methods
  21. .createSystemAccount()
  22. .accounts({
  23. payer: wallet.publicKey,
  24. newAccount: newKeypair.publicKey,
  25. })
  26. .signers([newKeypair])
  27. .rpc();
  28. // Minimum balance for rent exemption for new account
  29. const lamports = await connection.getMinimumBalanceForRentExemption(0);
  30. // Check that the account was created
  31. const accountInfo = await connection.getAccountInfo(newKeypair.publicKey);
  32. assert(accountInfo.lamports === lamports);
  33. });
  34. });