basic-2.js 1.3 KB

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