test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import * as anchor from "@coral-xyz/anchor"
  2. import { CreateSystemAccount } from "../target/types/create_system_account"
  3. import { Keypair, SystemProgram } from "@solana/web3.js"
  4. import { assert } from "chai"
  5. describe("Create a system account", () => {
  6. const provider = anchor.AnchorProvider.env()
  7. anchor.setProvider(provider)
  8. const wallet = provider.wallet as anchor.Wallet
  9. const connection = provider.connection
  10. const program = anchor.workspace
  11. .CreateSystemAccount as anchor.Program<CreateSystemAccount>
  12. it("Create the account", async () => {
  13. // Generate a new keypair for the new account
  14. const newKeypair = new Keypair()
  15. await program.methods
  16. .createSystemAccount()
  17. .accounts({
  18. payer: wallet.publicKey,
  19. newAccount: newKeypair.publicKey,
  20. systemProgram: SystemProgram.programId,
  21. })
  22. .signers([newKeypair])
  23. .rpc()
  24. // Minimum balance for rent exemption for new account
  25. const lamports = await connection.getMinimumBalanceForRentExemption(0)
  26. // Check that the account was created
  27. const accountInfo = await connection.getAccountInfo(newKeypair.publicKey)
  28. assert((accountInfo.owner = SystemProgram.programId))
  29. assert(accountInfo.lamports === lamports)
  30. })
  31. })