test.ts 1.2 KB

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