litesvm.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { LiteSVMProvider, fromWorkspace } from 'anchor-litesvm';
  3. import type { RentExample } from '../target/types/rent_example';
  4. const IDL = require('../target/idl/rent_example.json');
  5. describe('rent example', () => {
  6. // Configure the Anchor provider & load the program IDL for LiteSVM
  7. // The IDL gives you a typescript module
  8. const client = fromWorkspace('');
  9. const provider = new LiteSVMProvider(client);
  10. const payer = provider.wallet.payer;
  11. const program = new anchor.Program<RentExample>(IDL, provider);
  12. it('Create the account', async () => {
  13. const newKeypair = anchor.web3.Keypair.generate();
  14. const addressData: anchor.IdlTypes<RentExample>['addressData'] = {
  15. name: 'Marcus',
  16. address: '123 Main St. San Francisco, CA',
  17. };
  18. // We're just going to serialize our object here so we can check
  19. // the size on the client side against the program logs
  20. //
  21. const addressDataBuffer = new anchor.BorshCoder(IDL as anchor.Idl).types.encode('AddressData', addressData);
  22. console.log(`Address data buffer length: ${addressDataBuffer.length}`);
  23. await program.methods
  24. .createSystemAccount(addressData)
  25. .accounts({
  26. payer: payer.publicKey,
  27. newAccount: newKeypair.publicKey,
  28. })
  29. .signers([payer, newKeypair])
  30. .rpc();
  31. });
  32. });