test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { RentExample } from "../target/types/rent_example";
  3. import Idl from "../target/idl/rent_example.json";
  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(
  19. Idl as anchor.Idl
  20. ).types.encode("AddressData", addressData);
  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. })
  28. .signers([wallet.payer, newKeypair])
  29. .rpc();
  30. });
  31. });