errors.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const assert = require("assert");
  2. //const anchor = require('@project-serum/anchor');
  3. const anchor = require("/home/armaniferrante/Documents/code/src/github.com/project-serum/anchor/ts");
  4. describe("errors", () => {
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(anchor.Provider.local());
  7. const program = anchor.workspace.Errors;
  8. it("Emits a Hello error", async () => {
  9. try {
  10. const tx = await program.rpc.hello();
  11. assert.ok(false);
  12. } catch (err) {
  13. const errMsg =
  14. "This is an error message clients will automatically display";
  15. assert.equal(err.toString(), errMsg);
  16. assert.equal(err.msg, errMsg);
  17. assert.equal(err.code, 100);
  18. }
  19. });
  20. it("Emits a HelloNoMsg error", async () => {
  21. try {
  22. const tx = await program.rpc.helloNoMsg();
  23. assert.ok(false);
  24. } catch (err) {
  25. const errMsg = "HelloNoMsg";
  26. assert.equal(err.toString(), errMsg);
  27. assert.equal(err.msg, errMsg);
  28. assert.equal(err.code, 100 + 123);
  29. }
  30. });
  31. it("Emits a HelloNext error", async () => {
  32. try {
  33. const tx = await program.rpc.helloNext();
  34. assert.ok(false);
  35. } catch (err) {
  36. const errMsg = "HelloNext";
  37. assert.equal(err.toString(), errMsg);
  38. assert.equal(err.msg, errMsg);
  39. assert.equal(err.code, 100 + 124);
  40. }
  41. });
  42. });