test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { Keypair, SystemProgram } from '@solana/web3.js';
  3. import { assert } from 'chai';
  4. import type { CreateSystemAccount } from '../target/types/create_system_account';
  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.CreateSystemAccount as anchor.Program<CreateSystemAccount>;
  11. it('Create the account', async () => {
  12. // Generate a new keypair for the new account
  13. const newKeypair = new Keypair();
  14. await program.methods
  15. .createSystemAccount()
  16. .accounts({
  17. payer: wallet.publicKey,
  18. newAccount: newKeypair.publicKey,
  19. })
  20. .signers([newKeypair])
  21. .rpc();
  22. // Minimum balance for rent exemption for new account
  23. const lamports = await connection.getMinimumBalanceForRentExemption(0);
  24. // Check that the account was created
  25. const accountInfo = await connection.getAccountInfo(newKeypair.publicKey);
  26. assert(accountInfo.lamports === lamports);
  27. });
  28. });