basic-2.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.Provider.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.rpc.create(provider.wallet.publicKey, {
  14. accounts: {
  15. counter: counter.publicKey,
  16. user: provider.wallet.publicKey,
  17. systemProgram: SystemProgram.programId,
  18. },
  19. signers: [counter],
  20. })
  21. let counterAccount = await program.account.counter.fetch(counter.publicKey)
  22. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
  23. assert.ok(counterAccount.count.toNumber() === 0)
  24. })
  25. it('Updates a counter', async () => {
  26. await program.rpc.increment({
  27. accounts: {
  28. counter: counter.publicKey,
  29. authority: provider.wallet.publicKey,
  30. },
  31. })
  32. const counterAccount = await program.account.counter.fetch(counter.publicKey)
  33. assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
  34. assert.ok(counterAccount.count.toNumber() == 1)
  35. })
  36. })