-
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 in js-experimental (#158)
* Refactor code normalization in js tests * Add accountsPage test for empty seed PDAs
- Loading branch information
1 parent
b974da0
commit 24cb013
Showing
4 changed files
with
77 additions
and
94 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
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/, | ||
/getProgramDerivedAddress\({ programAddress, seeds: \[\] }\)/, | ||
// 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: [] })', | ||
]); | ||
}); |
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