test.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import * as anchor from "@project-serum/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. const addressDataBuffer = new anchor.BorshCoder(IDL).types.encode("AddressData", addressData);
  15. console.log(`Address data buffer length: ${addressDataBuffer.length}`);
  16. await program.methods.createSystemAccount(addressData)
  17. .accounts({
  18. payer: wallet.publicKey,
  19. newAccount: newKeypair.publicKey,
  20. systemProgram: anchor.web3.SystemProgram.programId
  21. })
  22. .signers([wallet.payer, newKeypair])
  23. .rpc();
  24. });
  25. });