test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { PdaRentPayer } from "../target/types/pda_rent_payer";
  3. describe("PDA Rent-Payer", () => {
  4. const provider = anchor.AnchorProvider.env();
  5. anchor.setProvider(provider);
  6. const wallet = provider.wallet as anchor.Wallet;
  7. const program = anchor.workspace.PdaRentPayer as anchor.Program<PdaRentPayer>;
  8. function deriveRentVaultPda() {
  9. const pda = anchor.web3.PublicKey.findProgramAddressSync(
  10. [Buffer.from("rent_vault")],
  11. program.programId
  12. );
  13. console.log(`PDA: ${pda[0].toBase58()}`);
  14. return pda;
  15. }
  16. it("Initialize the Rent Vault", async () => {
  17. const [rentVaultPda, _] = deriveRentVaultPda();
  18. await program.methods
  19. .initRentVault(new anchor.BN(1000000000))
  20. .accounts({
  21. rentVault: rentVaultPda,
  22. payer: wallet.publicKey,
  23. })
  24. .signers([wallet.payer])
  25. .rpc();
  26. });
  27. it("Create a new account using the Rent Vault", async () => {
  28. const newAccount = anchor.web3.Keypair.generate();
  29. const [rentVaultPda, _] = deriveRentVaultPda();
  30. await program.methods
  31. .createNewAccount()
  32. .accounts({
  33. newAccount: newAccount.publicKey,
  34. rentVault: rentVaultPda,
  35. })
  36. .signers([wallet.payer])
  37. .rpc();
  38. });
  39. });