rent.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { Rent } from "../target/types/rent";
  4. describe("rent", () => {
  5. // Configure the client to use the local cluster.
  6. const provider = anchor.AnchorProvider.env();
  7. anchor.setProvider(provider);
  8. // Generate a new keypair for the data account for the program
  9. const dataAccount = anchor.web3.Keypair.generate();
  10. const wallet = provider.wallet;
  11. const connection = provider.connection;
  12. const program = anchor.workspace.Rent as Program<Rent>;
  13. it("Is initialized!", async () => {
  14. // Initialize data account for the program, which is required by Solang
  15. const tx = await program.methods
  16. .new()
  17. .accounts({ dataAccount: dataAccount.publicKey })
  18. .signers([dataAccount])
  19. .rpc();
  20. console.log("Your transaction signature", tx);
  21. });
  22. it("Create new account", async () => {
  23. // Generate a new keypair for the new account
  24. const newAccount = anchor.web3.Keypair.generate();
  25. // Number of bytes of space to allocate for the account
  26. const space = 100;
  27. // Create a new account via a Cross Program Invocation to the system program
  28. const tx = await program.methods
  29. .createSystemAccount(
  30. new anchor.BN(space) // space
  31. )
  32. .accounts({
  33. payer: wallet.publicKey,
  34. newAccount: newAccount.publicKey,
  35. })
  36. .signers([newAccount]) // new account keypair required as signer
  37. .rpc();
  38. console.log("Your transaction signature", tx);
  39. });
  40. });