basic-2.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const assert = require("assert");
  2. const anchor = require("@project-serum/anchor");
  3. const { SystemProgram } = anchor.web3;
  4. describe("basic-2", () => {
  5. const provider = anchor.AnchorProvider.local();
  6. // Configure the client to use the local cluster.
  7. anchor.setProvider(provider);
  8. // Counter for the tests.
  9. const counter = anchor.web3.Keypair.generate();
  10. // Program for the tests.
  11. const program = anchor.workspace.Basic2;
  12. it("Creates a counter", async () => {
  13. await program.methods
  14. .create(provider.wallet.publicKey)
  15. .accounts({
  16. counter: counter.publicKey,
  17. user: provider.wallet.publicKey,
  18. systemProgram: SystemProgram.programId,
  19. })
  20. .signers([counter])
  21. .rpc();
  22. let counterAccount = await program.account.counter.fetch(counter.publicKey);
  23. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  24. assert.ok(counterAccount.count.toNumber() === 0);
  25. });
  26. it("Updates a counter", async () => {
  27. await program.methods
  28. .increment()
  29. .accounts({
  30. counter: counter.publicKey,
  31. authority: provider.wallet.publicKey,
  32. })
  33. .rpc();
  34. const counterAccount = await program.account.counter.fetch(
  35. counter.publicKey
  36. );
  37. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
  38. assert.ok(counterAccount.count.toNumber() == 1);
  39. });
  40. });