interface.js 1.4 KB

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