anchor/examples/tutorial/basic-4/tests/basic-4.js

37 lines
958 B
JavaScript
Raw Normal View History

2021-01-23 16:54:13 -08:00
const assert = require("assert");
const anchor = require("@project-serum/anchor");
2021-01-22 05:19:43 -08:00
2021-01-23 16:54:13 -08:00
describe("basic-4", () => {
const provider = anchor.Provider.local();
2021-01-22 05:19:43 -08:00
// Configure the client to use the local cluster.
2021-01-23 16:54:13 -08:00
anchor.setProvider(provider);
2021-01-22 05:19:43 -08:00
2021-01-23 16:54:13 -08:00
const program = anchor.workspace.Basic4;
2021-01-22 05:19:43 -08:00
2021-01-23 16:54:13 -08:00
it("Is runs the constructor", async () => {
2021-01-22 05:19:43 -08:00
// #region code
// Initialize the program's state struct.
2021-01-23 16:54:13 -08:00
await program.state.rpc.new({
accounts: {
authority: provider.wallet.publicKey,
},
});
2021-01-22 05:19:43 -08:00
// Fetch the state struct from the network.
const state = await program.state();
// #endregion code
2021-01-23 16:54:13 -08:00
assert.ok(state.count.eq(new anchor.BN(0)));
});
2021-01-22 05:19:43 -08:00
2021-01-23 16:54:13 -08:00
it("Executes a method on the program", async () => {
await program.state.rpc.increment({
accounts: {
authority: provider.wallet.publicKey,
},
});
const state = await program.state();
assert.ok(state.count.eq(new anchor.BN(1)));
2021-01-22 05:19:43 -08:00
});
});