basic-2.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const assert = require("assert");
  2. const anchor = require("@project-serum/anchor");
  3. const { SystemProgram } = anchor.web3;
  4. describe("basic-2", () => {
  5. const provider = anchor.AnchorProvider.local();
  6. // Configure the client to use the local cluster.
  7. anchor.setProvider(provider);
  8. // Counter for the tests.
  9. const counter = anchor.web3.Keypair.generate();
  10. // Program for the tests.
  11. const program = anchor.workspace.Basic2;
  12. it("Creates a counter", async () => {
  13. await program.methods.create(provider.wallet.publicKey).
  14. accounts({
  15. counter: counter.publicKey,
  16. user: provider.wallet.publicKey,
  17. systemProgram: SystemProgram.programId,
  18. }).signers([counter]).rpc();
  19. let counterAccount = await program.account.counter.fetch(counter.publicKey);
  20. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  21. assert.ok(counterAccount.count.toNumber() === 0);
  22. });
  23. it("Updates a counter", async () => {
  24. await program.methods.increment().
  25. accounts({
  26. counter: counter.publicKey,
  27. authority: provider.wallet.publicKey,
  28. }).rpc();
  29. const counterAccount = await program.account.counter.fetch(
  30. counter.publicKey
  31. );
  32. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  33. assert.ok(counterAccount.count.toNumber() == 1);
  34. });
  35. });