Skip to content

Commit 4b0a650

Browse files
committed
Add a test to check the program address config works as expected
1 parent 19cdccd commit 4b0a650

File tree

2 files changed

+52
-0
lines changed

2 files changed

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

packages/renderers-js/test/instructionsPage.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,27 @@ test('it can override the import of a resolver value node', async () => {
397397
someModule: ['myResolver'],
398398
});
399399
});
400+
401+
test('it renders optional config that can override the program address', async () => {
402+
// Given the following instruction
403+
const node = programNode({
404+
instructions: [
405+
instructionNode({
406+
accounts: [],
407+
name: 'myInstruction',
408+
}),
409+
],
410+
name: 'myProgram',
411+
publicKey: '1111',
412+
});
413+
414+
// When we render it.
415+
const renderMap = visit(node, getRenderMapVisitor());
416+
417+
// Then we expect an optional config parameter with an optional programAddress field
418+
// And we expect this to be used to override programAddress if it is set
419+
await renderMapContains(renderMap, 'instructions/myInstruction.ts', [
420+
'config?: { programAddress?: TProgramAddress }',
421+
'programAddress = config?.programAddress ?? MY_PROGRAM_PROGRAM_ADDRESS',
422+
]);
423+
});

0 commit comments

Comments
 (0)