test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. })
  21. .signers([newKeypair])
  22. .rpc()
  23. // Minimum balance for rent exemption for new account
  24. const lamports = await connection.getMinimumBalanceForRentExemption(0)
  25. // Check that the account was created
  26. const accountInfo = await connection.getAccountInfo(newKeypair.publicKey)
  27. assert((accountInfo.owner = SystemProgram.programId))
  28. assert(accountInfo.lamports === lamports)
  29. })
  30. })