1
1
import {
2
2
accountNode ,
3
3
bytesTypeNode ,
4
+ constantPdaSeedNode ,
5
+ constantPdaSeedNodeFromString ,
4
6
fixedSizeTypeNode ,
7
+ numberTypeNode ,
8
+ numberValueNode ,
5
9
pdaLinkNode ,
6
10
pdaNode ,
7
11
programNode ,
12
+ publicKeyTypeNode ,
8
13
variablePdaSeedNode ,
9
14
} from '@kinobi-so/nodes' ;
10
15
import { visit } from '@kinobi-so/visitors-core' ;
@@ -41,7 +46,7 @@ test('it renders a byte array seed used on an account', () => {
41
46
codeContains ( renderMap . get ( 'accounts/test_account.rs' ) , [ `byte_array_seed: [u8; 32],` , `&byte_array_seed,` ] ) ;
42
47
} ) ;
43
48
44
- test ( 'it renders an empty array seed used on an account ' , ( ) => {
49
+ test ( 'it renders an empty array of seeds for seedless PDAs ' , ( ) => {
45
50
// Given the following program with 1 account and 1 pda with empty seeds.
46
51
const node = programNode ( {
47
52
accounts : [
@@ -66,3 +71,33 @@ test('it renders an empty array seed used on an account', () => {
66
71
// as a parameters to be rendered.
67
72
codeContains ( renderMap . get ( 'accounts/test_account.rs' ) , [ / p u b f n f i n d _ p d a \( / , / & \[ \s * \] / ] ) ;
68
73
} ) ;
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