anchor/tests/interface/tests/interface.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

const anchor = require("@coral-xyz/anchor");
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.
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);
const stateAccount = await counter.state.fetch();
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 () => {
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) => {
if (err.toString().split("custom program error: 0x3a98").length !== 2) {
2021-02-07 07:45:10 -08:00
return false;
}
return true;
}
);
});
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,
},
});
const stateAccount = await counter.state.fetch();
assert.isTrue(stateAccount.count.eq(new anchor.BN(3)));
2021-02-07 07:45:10 -08:00
});
});