11import {
22 accountNode ,
33 bytesTypeNode ,
4+ constantPdaSeedNode ,
5+ constantPdaSeedNodeFromString ,
46 fixedSizeTypeNode ,
7+ numberTypeNode ,
8+ numberValueNode ,
59 pdaLinkNode ,
610 pdaNode ,
711 programNode ,
12+ publicKeyTypeNode ,
813 variablePdaSeedNode ,
914} from '@kinobi-so/nodes' ;
1015import { visit } from '@kinobi-so/visitors-core' ;
@@ -41,7 +46,7 @@ test('it renders a byte array seed used on an account', () => {
4146 codeContains ( renderMap . get ( 'accounts/test_account.rs' ) , [ `byte_array_seed: [u8; 32],` , `&byte_array_seed,` ] ) ;
4247} ) ;
4348
44- test ( 'it renders an empty array seed used on an account ' , ( ) => {
49+ test ( 'it renders an empty array of seeds for seedless PDAs ' , ( ) => {
4550 // Given the following program with 1 account and 1 pda with empty seeds.
4651 const node = programNode ( {
4752 accounts : [
@@ -66,3 +71,33 @@ test('it renders an empty array seed used on an account', () => {
6671 // as a parameters to be rendered.
6772 codeContains ( renderMap . get ( 'accounts/test_account.rs' ) , [ / p u b f n f i n d _ p d a \( / , / & \[ \s * \] / ] ) ;
6873} ) ;
74+
75+ test ( 'it renders constant PDA seeds as prefix consts' , ( ) => {
76+ // Given the following PDA node attached to an account.
77+ const node = programNode ( {
78+ accounts : [ accountNode ( { discriminators : [ ] , name : 'testAccount' , pda : pdaLinkNode ( 'testPda' ) } ) ] ,
79+ name : 'myProgram' ,
80+ pdas : [
81+ pdaNode ( {
82+ name : 'testPda' ,
83+ seeds : [
84+ constantPdaSeedNodeFromString ( 'utf8' , 'myPrefix' ) ,
85+ variablePdaSeedNode ( 'myAccount' , publicKeyTypeNode ( ) ) ,
86+ constantPdaSeedNode ( numberTypeNode ( 'u64' ) , numberValueNode ( 42 ) ) ,
87+ ] ,
88+ } ) ,
89+ ] ,
90+ publicKey : '1111' ,
91+ } ) ;
92+
93+ // When we render it.
94+ const renderMap = visit ( node , getRenderMapVisitor ( ) ) ;
95+
96+ // Then we expect the following const helpers for constant seeds.
97+ codeContains ( renderMap . get ( 'accounts/test_account.rs' ) , [
98+ '/// 0. `TestAccount::PREFIX.0`' ,
99+ '/// 1. my_account (`Pubkey`)' ,
100+ '/// 2. `TestAccount::PREFIX.1`' ,
101+ / p u b c o n s t P R E F I X : \( \s * & ' s t a t i c \[ u 8 \] , \s * & ' s t a t i c \[ u 8 \] , \s * \) = \( \s * " m y P r e f i x " \. a s _ b y t e s \( \) , \s * 4 2 \. a s _ b y t e s \( \) , \s * \) / ,
102+ ] ) ;
103+ } ) ;
0 commit comments