programAddressOverride.test.ts 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { address, generateKeyPairSigner } from '@solana/web3.js';
  2. import test from 'ava';
  3. import { getInitializeMintInstruction } from '../src/index.js';
  4. test('it can override the program address of an instruction', async (t) => {
  5. // Note: this test does not need to run the generated instruction
  6. // Given: a program address that we want to create instructions for
  7. const TOKEN_22_PROGRAM_ADDRESS = address(
  8. 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'
  9. );
  10. // When we generate an initialize mint instruction with the program address
  11. const mintAddress = (await generateKeyPairSigner()).address;
  12. const mintAuthorityAddress = (await generateKeyPairSigner()).address;
  13. const mintInstruction = getInitializeMintInstruction(
  14. {
  15. mint: mintAddress,
  16. decimals: 2,
  17. mintAuthority: mintAuthorityAddress,
  18. },
  19. { programAddress: TOKEN_22_PROGRAM_ADDRESS }
  20. );
  21. // Then: the generated instruction has the correct program address
  22. t.is(mintInstruction.programAddress, TOKEN_22_PROGRAM_ADDRESS);
  23. });