2022-12-16 05:21:50 -08:00
|
|
|
const anchor = require("@coral-xyz/anchor");
|
2022-03-24 08:44:33 -07:00
|
|
|
const { assert } = require("chai");
|
|
|
|
const nativeAssert = require("assert");
|
2021-02-07 07:45:10 -08:00
|
|
|
|
|
|
|
describe("interface", () => {
|
|
|
|
// Configure the client to use the local cluster.
|
2022-04-11 12:48:58 -07:00
|
|
|
anchor.setProvider(anchor.AnchorProvider.env());
|
2021-02-07 07:45:10 -08:00
|
|
|
|
|
|
|
const counter = anchor.workspace.Counter;
|
|
|
|
const counterAuth = anchor.workspace.CounterAuth;
|
|
|
|
it("Is initialized!", async () => {
|
|
|
|
await counter.state.rpc.new(counterAuth.programId);
|
|
|
|
|
2021-05-25 20:04:05 -07:00
|
|
|
const stateAccount = await counter.state.fetch();
|
2022-03-24 08:44:33 -07:00
|
|
|
assert.isTrue(stateAccount.count.eq(new anchor.BN(0)));
|
|
|
|
assert.isTrue(stateAccount.authProgram.equals(counterAuth.programId));
|
2021-02-07 07:45:10 -08:00
|
|
|
});
|
|
|
|
|
2021-08-06 12:52:54 -07:00
|
|
|
it("Should fail to go from even to even", async () => {
|
2022-03-24 08:44:33 -07:00
|
|
|
await nativeAssert.rejects(
|
2021-02-07 07:45:10 -08:00
|
|
|
async () => {
|
|
|
|
await counter.state.rpc.setCount(new anchor.BN(4), {
|
|
|
|
accounts: {
|
|
|
|
authProgram: counterAuth.programId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
(err) => {
|
2022-02-15 15:16:06 -08:00
|
|
|
if (err.toString().split("custom program error: 0x3a98").length !== 2) {
|
2021-02-07 07:45:10 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-15 15:16:06 -08:00
|
|
|
it("Should succeed to go from even to odd", async () => {
|
2021-02-07 07:45:10 -08:00
|
|
|
await counter.state.rpc.setCount(new anchor.BN(3), {
|
|
|
|
accounts: {
|
|
|
|
authProgram: counterAuth.programId,
|
|
|
|
},
|
|
|
|
});
|
2021-05-25 20:04:05 -07:00
|
|
|
const stateAccount = await counter.state.fetch();
|
2022-03-24 08:44:33 -07:00
|
|
|
assert.isTrue(stateAccount.count.eq(new anchor.BN(3)));
|
2021-02-07 07:45:10 -08:00
|
|
|
});
|
|
|
|
});
|