@@ -76,7 +76,7 @@ test('it renders extra arguments that default on each other', async () => {
7676 ] ) ;
7777} ) ;
7878
79- test ( 'it only renders the args variable on the async function if the sync function does not need it ' , async ( ) => {
79+ test ( 'it renders the args variable on the async function only if the extra argument has an async default value ' , async ( ) => {
8080 // Given the following instruction with an async resolver and an extra argument.
8181 const node = programNode ( {
8282 instructions : [
@@ -108,6 +108,46 @@ test('it only renders the args variable on the async function if the sync functi
108108 await codeDoesNotContain ( syncFunction , [ '// Original args.' , 'const args = { ...input }' ] ) ;
109109} ) ;
110110
111+ test ( 'it only renders the args variable on the async function if the extra argument is used in an async default value' , async ( ) => {
112+ // Given the following instruction with an async resolver depending on
113+ // an extra argument such that the instruction has no data arguments.
114+ const node = programNode ( {
115+ instructions : [
116+ instructionNode ( {
117+ accounts : [
118+ instructionAccountNode ( {
119+ defaultValue : resolverValueNode ( 'myAsyncResolver' , { dependsOn : [ argumentValueNode ( 'bar' ) ] } ) ,
120+ isSigner : false ,
121+ isWritable : false ,
122+ name : 'foo' ,
123+ } ) ,
124+ ] ,
125+ extraArguments : [
126+ instructionArgumentNode ( {
127+ name : 'bar' ,
128+ type : numberTypeNode ( 'u64' ) ,
129+ } ) ,
130+ ] ,
131+ name : 'create' ,
132+ } ) ,
133+ ] ,
134+ name : 'myProgram' ,
135+ publicKey : '1111' ,
136+ } ) ;
137+
138+ // When we render it.
139+ const renderMap = visit ( node , getRenderMapVisitor ( { asyncResolvers : [ 'myAsyncResolver' ] } ) ) ;
140+
141+ // And split the async and sync functions.
142+ const [ asyncFunction , syncFunction ] = renderMap
143+ . get ( 'instructions/create.ts' )
144+ . split ( / e x p o r t \s + f u n c t i o n \s + g e t C r e a t e I n s t r u c t i o n / ) ;
145+
146+ // Then we expect only the async function to contain the args variable.
147+ await codeContains ( asyncFunction , [ '// Original args.' , 'const args = { ...input }' ] ) ;
148+ await codeDoesNotContain ( syncFunction , [ '// Original args.' , 'const args = { ...input }' ] ) ;
149+ } ) ;
150+
111151test ( 'it renders instruction accounts with linked PDAs as default value' , async ( ) => {
112152 // Given the following program with a PDA node and an instruction account using it as default value.
113153 const node = programNode ( {
0 commit comments