anchor/examples/errors/tests/errors.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-01-15 23:05:26 -08:00
const assert = require("assert");
2021-01-22 05:29:39 -08:00
const anchor = require('@project-serum/anchor');
2021-01-15 23:05:26 -08:00
describe("errors", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.local());
const program = anchor.workspace.Errors;
it("Emits a Hello error", async () => {
try {
const tx = await program.rpc.hello();
assert.ok(false);
} catch (err) {
const errMsg =
"This is an error message clients will automatically display";
assert.equal(err.toString(), errMsg);
assert.equal(err.msg, errMsg);
assert.equal(err.code, 100);
}
});
it("Emits a HelloNoMsg error", async () => {
try {
const tx = await program.rpc.helloNoMsg();
assert.ok(false);
} catch (err) {
const errMsg = "HelloNoMsg";
assert.equal(err.toString(), errMsg);
assert.equal(err.msg, errMsg);
assert.equal(err.code, 100 + 123);
}
});
it("Emits a HelloNext error", async () => {
try {
const tx = await program.rpc.helloNext();
assert.ok(false);
} catch (err) {
const errMsg = "HelloNext";
assert.equal(err.toString(), errMsg);
assert.equal(err.msg, errMsg);
assert.equal(err.code, 100 + 124);
}
});
});