bankrun.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { describe, it } from "node:test";
  2. import * as anchor from "@coral-xyz/anchor";
  3. import { Keypair, PublicKey } from "@solana/web3.js";
  4. import { BankrunProvider } from "anchor-bankrun";
  5. import { startAnchor } from "solana-bankrun";
  6. import type { AccountDataAnchorProgram } from "../target/types/account_data_anchor_program";
  7. import IDL from "../target/idl/account_data_anchor_program.json" with {
  8. type: "json",
  9. };
  10. const PROGRAM_ID = new PublicKey(IDL.address);
  11. describe("Account Data!", async () => {
  12. const context = await startAnchor(
  13. "",
  14. [{ name: "account_data_anchor_program", programId: PROGRAM_ID }],
  15. [],
  16. );
  17. const provider = new BankrunProvider(context);
  18. const payer = provider.wallet as anchor.Wallet;
  19. const program = new anchor.Program<AccountDataAnchorProgram>(IDL, provider);
  20. // Generate a new keypair for the addressInfo account
  21. const addressInfoAccount = new Keypair();
  22. it("Create the address info account", async () => {
  23. console.log(`Payer Address : ${payer.publicKey}`);
  24. console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`);
  25. // Instruction Ix data
  26. const addressInfo = {
  27. name: "Joe C",
  28. houseNumber: 136,
  29. street: "Mile High Dr.",
  30. city: "Solana Beach",
  31. };
  32. await program.methods
  33. .createAddressInfo(
  34. addressInfo.name,
  35. addressInfo.houseNumber,
  36. addressInfo.street,
  37. addressInfo.city,
  38. )
  39. .accounts({
  40. addressInfo: addressInfoAccount.publicKey,
  41. payer: payer.publicKey,
  42. })
  43. .signers([addressInfoAccount])
  44. .rpc();
  45. });
  46. it("Read the new account's data", async () => {
  47. const addressInfo = await program.account.addressInfo.fetch(
  48. addressInfoAccount.publicKey,
  49. );
  50. console.log(`Name : ${addressInfo.name}`);
  51. console.log(`House Num: ${addressInfo.houseNumber}`);
  52. console.log(`Street : ${addressInfo.street}`);
  53. console.log(`City : ${addressInfo.city}`);
  54. });
  55. });