@@ -70,7 +70,11 @@ test('test composer build txn', async () => {
7070 function : '0x1::coin::withdraw' ,
7171 functionArguments : [ CallArgument . newSigner ( 0 ) , 1 ] ,
7272 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
73- moduleAbi : coin_module . abi ! ,
73+ moduleAbi : coin_module . abi ,
74+ moduleBytecodes : [ coin_module . bytecode ] ,
75+ options : {
76+ allowFetch : false ,
77+ } ,
7478 } ) ;
7579
7680 // Passing the coin value to the 0x1::coin::coin_to_fungible_asset to convert a coin
@@ -80,15 +84,23 @@ test('test composer build txn', async () => {
8084 // coin[0] represents the first return value from the first call you added.
8185 functionArguments : [ coin [ 0 ] ] ,
8286 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
83- moduleAbi : coin_module . abi ! ,
87+ moduleAbi : coin_module . abi ,
88+ moduleBytecodes : [ coin_module . bytecode ] ,
89+ options : {
90+ allowFetch : false ,
91+ } ,
8492 } ) ;
8593
8694 // Deposit the fungibleAsset converted from second call.
8795 await builder . addBatchedCalls ( {
8896 function : '0x1::primary_fungible_store::deposit' ,
8997 functionArguments : [ '0x1' , fungibleAsset [ 0 ] ] ,
9098 typeArguments : [ ] ,
91- moduleAbi : primary_fungible_store_module . abi ! ,
99+ moduleAbi : primary_fungible_store_module . abi ,
100+ moduleBytecodes : [ primary_fungible_store_module . bytecode ] ,
101+ options : {
102+ allowFetch : false ,
103+ } ,
92104 } ) ;
93105
94106 const tx = builder . build ( ) ;
@@ -108,7 +120,11 @@ test('test composer build Payload', async () => {
108120 function : '0x1::coin::withdraw' ,
109121 functionArguments : [ CallArgument . newSigner ( 0 ) , 1 ] ,
110122 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
111- moduleAbi : coin_module . abi ! ,
123+ moduleAbi : coin_module . abi ,
124+ moduleBytecodes : [ coin_module . bytecode ] ,
125+ options : {
126+ allowFetch : false ,
127+ } ,
112128 } ) ;
113129
114130 // Passing the coin value to the 0x1::coin::coin_to_fungible_asset to convert a coin
@@ -119,14 +135,22 @@ test('test composer build Payload', async () => {
119135 functionArguments : [ coin [ 0 ] ] ,
120136 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
121137 moduleAbi : coin_module . abi ! ,
138+ moduleBytecodes : [ coin_module . bytecode ] ,
139+ options : {
140+ allowFetch : false ,
141+ } ,
122142 } ) ;
123143
124144 // Deposit the fungibleAsset converted from second call.
125145 await builder . addBatchedCalls ( {
126146 function : '0x1::primary_fungible_store::deposit' ,
127147 functionArguments : [ '0x1' , fungibleAsset [ 0 ] ] ,
128148 typeArguments : [ ] ,
129- moduleAbi : primary_fungible_store_module . abi ! ,
149+ moduleAbi : primary_fungible_store_module . abi ,
150+ moduleBytecodes : [ primary_fungible_store_module . bytecode ] ,
151+ options : {
152+ allowFetch : false ,
153+ } ,
130154 } ) ;
131155
132156 const payload = builder . build_payload ( ) ;
@@ -148,7 +172,11 @@ test('test composer build Txn', async () => {
148172 function : '0x1::coin::withdraw' ,
149173 functionArguments : [ CallArgument . newSigner ( 0 ) , 1 ] ,
150174 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
151- moduleAbi : coin_module . abi ! ,
175+ moduleAbi : coin_module . abi ,
176+ moduleBytecodes : [ coin_module . bytecode ] ,
177+ options : {
178+ allowFetch : false ,
179+ } ,
152180 } ) ;
153181
154182 // Passing the coin value to the 0x1::coin::coin_to_fungible_asset to convert a coin
@@ -158,15 +186,23 @@ test('test composer build Txn', async () => {
158186 // coin[0] represents the first return value from the first call you added.
159187 functionArguments : [ coin [ 0 ] ] ,
160188 typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
161- moduleAbi : coin_module . abi ! ,
189+ moduleAbi : coin_module . abi ,
190+ moduleBytecodes : [ coin_module . bytecode ] ,
191+ options : {
192+ allowFetch : false ,
193+ } ,
162194 } ) ;
163195
164196 // Deposit the fungibleAsset converted from second call.
165197 await builder . addBatchedCalls ( {
166198 function : '0x1::primary_fungible_store::deposit' ,
167199 functionArguments : [ '0x1' , fungibleAsset [ 0 ] ] ,
168200 typeArguments : [ ] ,
169- moduleAbi : primary_fungible_store_module . abi ! ,
201+ moduleAbi : primary_fungible_store_module . abi ,
202+ moduleBytecodes : [ primary_fungible_store_module . bytecode ] ,
203+ options : {
204+ allowFetch : false ,
205+ } ,
170206 } ) ;
171207
172208 return builder ;
@@ -175,3 +211,74 @@ test('test composer build Txn', async () => {
175211
176212 expect ( txn ) . toBeDefined ( ) ;
177213} ) ;
214+
215+ test ( 'test composer with fetch enabled' , async ( ) => {
216+ const builder = new AptosScriptComposer ( new AptosConfig ( { network : Network . TESTNET } ) ) ;
217+
218+ // Test with allowFetch enabled (default behavior)
219+ // This should automatically fetch the module from the chain without needing to store it first
220+ const coin = await builder . addBatchedCalls ( {
221+ function : '0x1::coin::withdraw' ,
222+ functionArguments : [ CallArgument . newSigner ( 0 ) , 1000000 ] , // 0.01 APT
223+ typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
224+ // Note: Not providing moduleAbi or moduleBytecodes - should be fetched automatically
225+ options : {
226+ allowFetch : true , // Explicitly enable fetch (this is the default)
227+ } ,
228+ } ) ;
229+
230+ // Test chaining with another function that also uses fetch
231+ const fungibleAsset = await builder . addBatchedCalls ( {
232+ function : '0x1::coin::coin_to_fungible_asset' ,
233+ functionArguments : [ coin [ 0 ] ] ,
234+ typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
235+ // Again, not providing moduleAbi or moduleBytecodes
236+ options : {
237+ allowFetch : true ,
238+ } ,
239+ } ) ;
240+
241+ // Final deposit call
242+ await builder . addBatchedCalls ( {
243+ function : '0x1::primary_fungible_store::deposit' ,
244+ functionArguments : [ '0x1' , fungibleAsset [ 0 ] ] ,
245+ typeArguments : [ ] ,
246+ // Testing default behavior (allowFetch should be true by default)
247+ // options: { allowFetch: true } // This is the default, so we can omit it
248+ } ) ;
249+
250+ const tx = builder . build ( ) ;
251+ expect ( tx ) . toBeDefined ( ) ;
252+ expect ( tx . length ) . toBeGreaterThan ( 0 ) ;
253+ } ) ;
254+
255+ test ( 'test composer fetch vs no-fetch behavior' , async ( ) => {
256+ // Test that fetch is required when allowFetch is false and no ABI/bytecode provided
257+ const builder = new AptosScriptComposer ( new AptosConfig ( { network : Network . TESTNET } ) ) ;
258+
259+ // This should fail because allowFetch is false but no moduleAbi provided
260+ await expect (
261+ builder . addBatchedCalls ( {
262+ function : '0x1::coin::withdraw' ,
263+ functionArguments : [ CallArgument . newSigner ( 0 ) , 1000000 ] ,
264+ typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
265+ options : {
266+ allowFetch : false ,
267+ } ,
268+ } )
269+ ) . rejects . toThrow ( 'Module ABI is required when auto-fetch is disabled' ) ;
270+
271+ // This should also fail because allowFetch is false but no moduleBytecodes provided
272+ await expect (
273+ builder . addBatchedCalls ( {
274+ function : '0x1::coin::withdraw' ,
275+ functionArguments : [ CallArgument . newSigner ( 0 ) , 1000000 ] ,
276+ typeArguments : [ '0x1::aptos_coin::AptosCoin' ] ,
277+ moduleAbi : coin_module . abi ,
278+ // Missing moduleBytecodes
279+ options : {
280+ allowFetch : false ,
281+ } ,
282+ } )
283+ ) . rejects . toThrow ( 'Module bytecode is required when auto-fetch is disabled' ) ;
284+ } ) ;
0 commit comments