test.ts 1.2 KB

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