basic-2.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const assert = require('assert');
  2. const anchor = require('@project-serum/anchor');
  3. describe('basic-2', () => {
  4. const provider = anchor.Provider.local()
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(provider)
  7. // Counter for the tests.
  8. const counter = new anchor.web3.Account()
  9. // Program for the tests.
  10. const program = anchor.workspace.Basic2
  11. it('Creates a counter', async () => {
  12. await program.rpc.create(provider.wallet.publicKey, {
  13. accounts: {
  14. counter: counter.publicKey,
  15. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  16. },
  17. signers: [counter],
  18. instructions: [await program.account.counter.createInstruction(counter)],
  19. })
  20. let counterAccount = await program.account.counter(counter.publicKey)
  21. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
  22. assert.ok(counterAccount.count.toNumber() === 0)
  23. })
  24. it('Updates a counter', async () => {
  25. await program.rpc.increment({
  26. accounts: {
  27. counter: counter.publicKey,
  28. authority: provider.wallet.publicKey,
  29. },
  30. })
  31. const counterAccount = await program.account.counter(counter.publicKey)
  32. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
  33. assert.ok(counterAccount.count.toNumber() == 1)
  34. })
  35. })