basic-2.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.rpc.create(provider.wallet.publicKey, {
  14. accounts: {
  15. counter: counter.publicKey,
  16. user: provider.wallet.publicKey,
  17. systemProgram: SystemProgram.programId,
  18. },
  19. signers: [counter],
  20. });
  21. let counterAccount = await program.account.counter.fetch(counter.publicKey);
  22. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  23. assert.ok(counterAccount.count.toNumber() === 0);
  24. });
  25. it("Updates a counter", async () => {
  26. await program.rpc.increment({
  27. accounts: {
  28. counter: counter.publicKey,
  29. authority: provider.wallet.publicKey,
  30. },
  31. });
  32. const counterAccount = await program.account.counter.fetch(
  33. counter.publicKey
  34. );
  35. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  36. assert.ok(counterAccount.count.toNumber() == 1);
  37. });
  38. });