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

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-01-23 16:54:13 -08:00
const assert = require("assert");
const anchor = require("@coral-xyz/anchor");
2021-01-22 05:19:43 -08:00
2021-01-23 16:54:13 -08:00
describe("basic-4", () => {
const provider = anchor.AnchorProvider.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 () => {
// #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,
},
});
// #endregion ctor
2021-01-22 05:19:43 -08:00
// Fetch the state struct from the network.
// #region accessor
const state = await program.state.fetch();
// #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 () => {
// #region instruction
2021-01-23 16:54:13 -08:00
await program.state.rpc.increment({
accounts: {
authority: provider.wallet.publicKey,
},
});
// #endregion instruction
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
});
});