test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import * as anchor from "@project-serum/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.initRentVault(new anchor.BN(1000000000))
  19. .accounts({
  20. rentVault: rentVaultPda,
  21. payer: wallet.publicKey,
  22. })
  23. .signers([wallet.payer])
  24. .rpc()
  25. });
  26. it("Create a new account using the Rent Vault", async () => {
  27. const newAccount = anchor.web3.Keypair.generate();
  28. const [rentVaultPda, _] = deriveRentVaultPda();
  29. await program.methods.createNewAccount()
  30. .accounts({
  31. newAccount: newAccount.publicKey,
  32. rentVault: rentVaultPda,
  33. })
  34. .signers([wallet.payer])
  35. .rpc()
  36. });
  37. });