Skip to content

Commit

Permalink
Add accountsPage test for empty seed PDAs
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Jan 31, 2024
1 parent 32960d0 commit f3b64de
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
30 changes: 30 additions & 0 deletions test/renderers/js-experimental/accountsPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 PDA helpers for PDA with no seeds', (t) => {
// Given the following program with 1 account and 1 pda with empty seeds.
const node = programNode({
name: 'myProgram',
publicKey: '1111',
accounts: [accountNode({ name: 'foo', pda: pdaLinkNode('bar') })],
pdas: [pdaNode('bar', [])],
});

// When we render it.
const renderMap = visit(node, getRenderMapVisitor());

// Then we expect the following fetch helper functions delegating to findBarPda.
renderMapContains(t, renderMap, 'accounts/foo.ts', [
'export async function fetchFooFromSeeds',
'export async function fetchMaybeFooFromSeeds',
'await findBarPda({ programAddress })',
]);
});
31 changes: 7 additions & 24 deletions test/renderers/js-experimental/pdasPage.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import test from 'ava';
import {
accountNode,
pdaLinkNode,
pdaNode,
programNode,
visit,
} from '../../../src';
import { 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', []),
],
name: 'myProgram',
publicKey: '1111',
pdas: [pdaNode('foo', [])],
});

// 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',
// Then we expect the following PDA function using an empty seeds array to derive the address.
renderMapContains(t, renderMap, 'pdas/foo.ts', [
'export async function findFooPda',
'getProgramDerivedAddress({ programAddress, seeds: [] })',
]);
});

0 comments on commit f3b64de

Please sign in to comment.