-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accountsPage test for empty seed PDAs
- Loading branch information
1 parent
32960d0
commit f3b64de
Showing
2 changed files
with
37 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] })', | ||
]); | ||
}); |