litesvm.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import assert from 'node:assert';
  2. import { Program } from '@coral-xyz/anchor';
  3. import { Keypair } from '@solana/web3.js';
  4. import { LiteSVMProvider, fromWorkspace } from 'anchor-litesvm';
  5. import { CreateSystemAccount } from '../target/types/create_system_account';
  6. const IDL = require('../target/idl/create_system_account.json');
  7. it('Create the account', async () => {
  8. const client = fromWorkspace('');
  9. const provider = new LiteSVMProvider(client);
  10. const payer = provider.wallet.payer;
  11. const program = new Program<CreateSystemAccount>(IDL, provider);
  12. const connection = provider.connection;
  13. // Generate a new keypair for the new account
  14. const newKeypair = new Keypair();
  15. await program.methods
  16. .createSystemAccount()
  17. .accounts({
  18. payer: payer.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.lamports === lamports);
  28. });