counter_seahorse.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js';
  4. import { assert } from 'chai';
  5. import type { CounterSeahorse } from '../target/types/counter_seahorse';
  6. describe('counter_seahorse', () => {
  7. // Configure the client to use the local cluster.
  8. anchor.setProvider(anchor.AnchorProvider.env());
  9. const program = anchor.workspace.CounterSeahorse as Program<CounterSeahorse>;
  10. it('Increment counter', async () => {
  11. const seed = 69;
  12. const counter = PublicKey.findProgramAddressSync([Buffer.from([0x45])], program.programId)[0];
  13. // Initialize counter
  14. await program.methods
  15. .initializeCounter(seed)
  16. .accounts({
  17. payer: program.provider.publicKey,
  18. })
  19. .rpc();
  20. // Increment counter
  21. await program.methods
  22. .increment()
  23. .accounts({
  24. counter,
  25. })
  26. .rpc();
  27. const count = (await program.account.counter.fetch(counter)).count.toNumber();
  28. assert(count === 1, 'Expected count to be 1');
  29. });
  30. });