basic-2.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import assert from 'assert'
  2. import * as anchor from '@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. })