counter_seahorse.ts 1.1 KB

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