basic-4.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const assert = require("assert");
  2. const anchor = require("@project-serum/anchor");
  3. describe("basic-4", () => {
  4. const provider = anchor.AnchorProvider.local();
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(provider);
  7. const program = anchor.workspace.Basic4;
  8. it("Is runs the constructor", async () => {
  9. // #region ctor
  10. // Initialize the program's state struct.
  11. await program.state.rpc.new({
  12. accounts: {
  13. authority: provider.wallet.publicKey,
  14. },
  15. });
  16. // #endregion ctor
  17. // Fetch the state struct from the network.
  18. // #region accessor
  19. const state = await program.state.fetch();
  20. // #endregion accessor
  21. assert.ok(state.count.eq(new anchor.BN(0)));
  22. });
  23. it("Executes a method on the program", async () => {
  24. // #region instruction
  25. await program.state.rpc.increment({
  26. accounts: {
  27. authority: provider.wallet.publicKey,
  28. },
  29. });
  30. // #endregion instruction
  31. const state = await program.state.fetch();
  32. assert.ok(state.count.eq(new anchor.BN(1)));
  33. });
  34. });