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-02-03 00:35:18 -08:00
|
|
|
// #region ctor
|
2021-01-22 05:19:43 -08:00
|
|
|
// 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-02-03 00:35:18 -08:00
|
|
|
// #endregion ctor
|
2021-01-22 05:19:43 -08:00
|
|
|
|
|
|
|
// Fetch the state struct from the network.
|
2021-02-03 00:35:18 -08:00
|
|
|
// #region accessor
|
2021-05-25 20:04:05 -07:00
|
|
|
const state = await program.state.fetch();
|
2021-02-03 00:35:18 -08:00
|
|
|
// #endregion accessor
|
|
|
|
|
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 () => {
|
2021-02-03 00:35:18 -08:00
|
|
|
// #region instruction
|
2021-01-23 16:54:13 -08:00
|
|
|
await program.state.rpc.increment({
|
|
|
|
accounts: {
|
|
|
|
authority: provider.wallet.publicKey,
|
|
|
|
},
|
|
|
|
});
|
2021-02-03 00:35:18 -08:00
|
|
|
// #endregion instruction
|
2021-05-25 20:04:05 -07:00
|
|
|
const state = await program.state.fetch();
|
2021-01-23 16:54:13 -08:00
|
|
|
assert.ok(state.count.eq(new anchor.BN(1)));
|
2021-01-22 05:19:43 -08:00
|
|
|
});
|
|
|
|
});
|