Skip to content

Commit

Permalink
Add empty array seeds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Jan 30, 2024
1 parent 7bfef45 commit 2bccc58
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
39 changes: 39 additions & 0 deletions test/renderers/js-experimental/pdasPage.test.ts
Original file line number Diff line number Diff line change
@@ -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: \[\] }\)/,
]);
});
31 changes: 30 additions & 1 deletion test/renderers/rust/accountsPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
pdaNode,
programNode,
variablePdaSeedNode,
visit,
visit
} from '../../../src';
import { getRenderMapVisitor } from '../../../src/renderers/rust/getRenderMapVisitor';
import { codeContains } from './_setup';
Expand Down Expand Up @@ -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*\]/,
]);
});

0 comments on commit 2bccc58

Please sign in to comment.