anchor/examples/interface/tests/interface.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-02-07 07:45:10 -08:00
const anchor = require('@project-serum/anchor');
const assert = require("assert");
describe("interface", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
const counter = anchor.workspace.Counter;
const counterAuth = anchor.workspace.CounterAuth;
it("Is initialized!", async () => {
await counter.state.rpc.new(counterAuth.programId);
const stateAccount = await counter.state();
assert.ok(stateAccount.count.eq(new anchor.BN(0)));
assert.ok(stateAccount.authProgram.equals(counterAuth.programId));
});
it("Should fail to go from even to event", async () => {
await assert.rejects(
async () => {
await counter.state.rpc.setCount(new anchor.BN(4), {
accounts: {
authProgram: counterAuth.programId,
},
});
},
(err) => {
if (err.toString().split("custom program error: 0x32").length !== 2) {
return false;
}
return true;
}
);
});
it("Shold succeed to go from even to odd", async () => {
await counter.state.rpc.setCount(new anchor.BN(3), {
accounts: {
authProgram: counterAuth.programId,
},
});
const stateAccount = await counter.state();
assert.ok(stateAccount.count.eq(new anchor.BN(3)));
});
});