advanceNonceAccount.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {
  2. appendTransactionMessageInstruction,
  3. generateKeyPairSigner,
  4. pipe,
  5. } from '@solana/web3.js';
  6. import test from 'ava';
  7. import { fetchNonce, getAdvanceNonceAccountInstruction } from '../src';
  8. import {
  9. createDefaultSolanaClient,
  10. createDefaultTransaction,
  11. createNonceAccount,
  12. generateKeyPairSignerWithSol,
  13. signAndSendTransaction,
  14. } from './_setup';
  15. test('it advances the nonce account', async (t) => {
  16. // Given an existing nonce account.
  17. const client = createDefaultSolanaClient();
  18. const [payer, nonce, authority] = await Promise.all([
  19. generateKeyPairSignerWithSol(client),
  20. generateKeyPairSigner(),
  21. generateKeyPairSigner(),
  22. ]);
  23. await createNonceAccount(client, payer, nonce, authority);
  24. const originalNonceAccount = await fetchNonce(client.rpc, nonce.address);
  25. // When the authority advances the nonce account.
  26. const createAccount = getAdvanceNonceAccountInstruction({
  27. nonceAccount: nonce.address,
  28. nonceAuthority: authority,
  29. });
  30. await pipe(
  31. await createDefaultTransaction(client, payer),
  32. (tx) => appendTransactionMessageInstruction(createAccount, tx),
  33. (tx) => signAndSendTransaction(client, tx)
  34. );
  35. // Then we expect the blockhash to have been updated.
  36. const updatedNonceAccount = await fetchNonce(client.rpc, nonce.address);
  37. t.not(
  38. originalNonceAccount.data.blockhash,
  39. updatedNonceAccount.data.blockhash
  40. );
  41. });