counter_seahorse.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
  4. import { assert } from "chai";
  5. import { CounterSeahorse } from "../target/types/counter_seahorse";
  6. describe("counter_seahorse", () => {
  7. // Configure the client to use the local cluster.
  8. anchor.setProvider(anchor.AnchorProvider.env());
  9. const program = anchor.workspace.CounterSeahorse as Program<CounterSeahorse>;
  10. it("Increment counter", async () => {
  11. const seed = 69;
  12. const counter = PublicKey.findProgramAddressSync(
  13. [Buffer.from([0x45])],
  14. program.programId
  15. )[0];
  16. // Initialize counter
  17. await program.methods
  18. .initializeCounter(seed)
  19. .accounts({
  20. payer: program.provider.publicKey,
  21. })
  22. .rpc();
  23. // Increment counter
  24. await program.methods
  25. .increment()
  26. .accounts({
  27. counter,
  28. })
  29. .rpc();
  30. const count = (
  31. await program.account.counter.fetch(counter)
  32. ).count.toNumber();
  33. assert(count === 1, "Expected count to be 1");
  34. });
  35. });