bankrun.test.ts 1.5 KB

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