diff --git a/test/renderers/js-experimental/pdasPage.test.ts b/test/renderers/js-experimental/pdasPage.test.ts new file mode 100644 index 000000000..4330e90c4 --- /dev/null +++ b/test/renderers/js-experimental/pdasPage.test.ts @@ -0,0 +1,39 @@ +import test from 'ava'; +import { + accountNode, + pdaLinkNode, + pdaNode, + programNode, + visit, +} from '../../../src'; +import { getRenderMapVisitor } from '../../../src/renderers/js-experimental/getRenderMapVisitor'; +import { renderMapContains } from './_setup'; + +test('it renders an empty array seed used on a pda', (t) => { + // Given the following program with 1 account and 1 pda with empty seeds. + const node = programNode({ + name: 'splToken', + publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + accounts: [ + accountNode({ + name: 'testAccount', + discriminators: [], + pda: pdaLinkNode('testPda'), + }), + ], + pdas: [ + // Empty array seeds. + pdaNode('testPda', []), + ], + }); + + // When we render it. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect the following function and and empty seeds + // array used on program derived address function. + renderMapContains(t, renderMap, 'pdas/testPda.ts', [ + /export async function findTestPdaPda/, + /getProgramDerivedAddress\({ programAddress, seeds: \[\] }\)/, + ]); +}); diff --git a/test/renderers/rust/accountsPage.test.ts b/test/renderers/rust/accountsPage.test.ts index 3b20ddba5..901cd9d1e 100644 --- a/test/renderers/rust/accountsPage.test.ts +++ b/test/renderers/rust/accountsPage.test.ts @@ -7,7 +7,7 @@ import { pdaNode, programNode, variablePdaSeedNode, - visit, + visit } from '../../../src'; import { getRenderMapVisitor } from '../../../src/renderers/rust/getRenderMapVisitor'; import { codeContains } from './_setup'; @@ -42,3 +42,32 @@ test('it renders a byte array seed used on an account', (t) => { `&byte_array_seed,`, ]); }); + +test('it renders an empty array seed used on an account', (t) => { + // Given the following program with 1 account and 1 pda with empty seeds. + const node = programNode({ + name: 'splToken', + publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + accounts: [ + accountNode({ + name: 'testAccount', + discriminators: [], + pda: pdaLinkNode('testPda'), + }), + ], + pdas: [ + // Empty array seeds. + pdaNode('testPda', []), + ], + }); + + // When we render it. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect the following identifier and reference to the byte array + // as a parameters to be rendered. + codeContains(t, renderMap.get('accounts/test_account.rs'), [ + /pub fn find_pda\(/, + /&\[\s*\]/, + ]); +});