interface.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const anchor = require('@project-serum/anchor');
  2. const assert = require("assert");
  3. describe("interface", () => {
  4. // Configure the client to use the local cluster.
  5. anchor.setProvider(anchor.Provider.env());
  6. const counter = anchor.workspace.Counter;
  7. const counterAuth = anchor.workspace.CounterAuth;
  8. it("Is initialized!", async () => {
  9. await counter.state.rpc.new(counterAuth.programId);
  10. const stateAccount = await counter.state();
  11. assert.ok(stateAccount.count.eq(new anchor.BN(0)));
  12. assert.ok(stateAccount.authProgram.equals(counterAuth.programId));
  13. });
  14. it("Should fail to go from even to event", async () => {
  15. await assert.rejects(
  16. async () => {
  17. await counter.state.rpc.setCount(new anchor.BN(4), {
  18. accounts: {
  19. authProgram: counterAuth.programId,
  20. },
  21. });
  22. },
  23. (err) => {
  24. if (err.toString().split("custom program error: 0x32").length !== 2) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. );
  30. });
  31. it("Shold succeed to go from even to odd", async () => {
  32. await counter.state.rpc.setCount(new anchor.BN(3), {
  33. accounts: {
  34. authProgram: counterAuth.programId,
  35. },
  36. });
  37. const stateAccount = await counter.state();
  38. assert.ok(stateAccount.count.eq(new anchor.BN(3)));
  39. });
  40. });