forked from coral-xyz/anchor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.js
45 lines (40 loc) · 1.32 KB
/
interface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.fetch();
assert.ok(stateAccount.count.eq(new anchor.BN(0)));
assert.ok(stateAccount.authProgram.equals(counterAuth.programId));
});
it("Should fail to go from even to even", 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: 0x3a98").length !== 2) {
return false;
}
return true;
}
);
});
it("Should 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();
assert.ok(stateAccount.count.eq(new anchor.BN(3)));
});
});