anchor/tests/interface/tests/interface.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

const anchor = require("@project-serum/anchor");
2021-02-07 07:45:10 -08:00
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.fetch();
2021-02-07 07:45:10 -08:00
assert.ok(stateAccount.count.eq(new anchor.BN(0)));
assert.ok(stateAccount.authProgram.equals(counterAuth.programId));
});
2021-08-06 12:52:54 -07:00
it("Should fail to go from even to even", async () => {
2021-02-07 07:45:10 -08:00
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.fetch();
2021-02-07 07:45:10 -08:00
assert.ok(stateAccount.count.eq(new anchor.BN(3)));
});
});