litesvm.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. describe('anchor', () => {
  8. let client: any;
  9. let provider: LiteSVMProvider;
  10. let program: Program<CreateSystemAccount>;
  11. let payer: Keypair;
  12. let connection: LiteSVMProvider['connection'];
  13. before(async () => {
  14. client = fromWorkspace('');
  15. provider = new LiteSVMProvider(client);
  16. payer = provider.wallet.payer;
  17. program = new Program<CreateSystemAccount>(IDL, provider);
  18. connection = provider.connection;
  19. });
  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: payer.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. });