@@ -17,13 +17,13 @@ import {
1717} from '../../../typechain' ;
1818import { TAG_TEE } from '../../../utils/constants' ;
1919import {
20+ IexecOrders ,
2021 OrdersActors ,
2122 OrdersAssets ,
2223 OrdersPrices ,
2324 buildOrders ,
2425 signOrders ,
2526} from '../../../utils/createOrders' ;
26- import { encodeMatchOrdersCalldata } from '../../../utils/odb-tools' ;
2727import { getDealId , getIexecAccounts } from '../../../utils/poco-tools' ;
2828import { getFunctionSelectors } from '../../../utils/proxy-tools' ;
2929import { IexecWrapper } from '../../utils/IexecWrapper' ;
@@ -159,13 +159,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
159159 const initialBalance = await iexecPoco . balanceOf ( requester . address ) ;
160160 const initialTotalSupply = await iexecPoco . totalSupply ( ) ;
161161
162- // Encode the matchOrders operation with its selector
163- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...orders . toArray ( ) ) ;
164-
165162 const tx = await rlcInstanceAsRequester . approveAndCall (
166163 proxyAddress ,
167164 dealCost ,
168- matchOrdersCalldata ,
165+ await matchOrdersCalldata ( orders ) ,
169166 ) ;
170167
171168 // Verify RLC transfer from requester to proxy
@@ -230,14 +227,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
230227 iexecWrapper . hashOrders ( ordersWithoutDataset ) ;
231228
232229 const dealId = getDealId ( iexecWrapper . getDomain ( ) , ordersWithoutDataset . requester ) ;
233- const matchOrdersCalldata = encodeMatchOrdersCalldata (
234- ...ordersWithoutDataset . toArray ( ) ,
235- ) ;
236-
237- const tx = rlcInstanceAsRequester . approveAndCall (
230+ const tx = await rlcInstanceAsRequester . approveAndCall (
238231 proxyAddress ,
239232 dealCost ,
240- matchOrdersCalldata ,
233+ await matchOrdersCalldata ( ordersWithoutDataset ) ,
241234 ) ;
242235
243236 await expect ( tx )
@@ -286,11 +279,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
286279 await iexecWrapper . depositInIexecAccount ( scheduler , schedulerStake ) ;
287280
288281 const initialBalance = await iexecPoco . balanceOf ( requester . address ) ;
289- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...orders . toArray ( ) ) ;
290282 await rlcInstanceAsRequester . approveAndCall (
291283 proxyAddress ,
292284 dealCost ,
293- matchOrdersCalldata ,
285+ await matchOrdersCalldata ( orders ) ,
294286 ) ;
295287
296288 // The available balance remains unchanged because the deposit is immediately frozen
@@ -308,10 +300,13 @@ describe('IexecEscrowToken-receiveApproval', () => {
308300 } ) ;
309301
310302 const dealCost = ( appPrice + datasetPrice + workerpoolPrice ) * volume ;
311- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...orders . toArray ( ) ) ;
312303
313304 await expect (
314- rlcInstanceAsRequester . approveAndCall ( proxyAddress , dealCost , matchOrdersCalldata ) ,
305+ rlcInstanceAsRequester . approveAndCall (
306+ proxyAddress ,
307+ dealCost ,
308+ await matchOrdersCalldata ( orders ) ,
309+ ) ,
315310 ) . to . be . revertedWithCustomError ( iexecPoco , 'CallerIsNotTheRequester' ) ;
316311 } ) ;
317312
@@ -335,14 +330,13 @@ describe('IexecEscrowToken-receiveApproval', () => {
335330 await iexecWrapper . depositInIexecAccount ( scheduler , schedulerStake ) ;
336331
337332 const insufficientAmount = dealCost - 1n ;
338- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...orders . toArray ( ) ) ;
339333
340334 // Should revert from matchOrders due to insufficient balance
341335 await expect (
342336 rlcInstanceAsRequester . approveAndCall (
343337 proxyAddress ,
344338 insufficientAmount ,
345- matchOrdersCalldata ,
339+ await matchOrdersCalldata ( orders ) ,
346340 ) ,
347341 ) . to . be . revertedWith ( 'IexecEscrow: Transfer amount exceeds balance' ) ;
348342 } ) ;
@@ -391,12 +385,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
391385
392386 await signOrders ( iexecWrapper . getDomain ( ) , orders1 , ordersActors ) ;
393387
394- const calldata1 = encodeMatchOrdersCalldata ( ...orders1 . toArray ( ) ) ;
395-
396388 const tx1 = await rlcInstanceAsRequester . approveAndCall (
397389 proxyAddress ,
398390 dealCost ,
399- calldata1 ,
391+ await matchOrdersCalldata ( orders1 ) ,
400392 ) ;
401393
402394 const dealId1 = getDealId ( iexecWrapper . getDomain ( ) , orders1 . requester ) ;
@@ -416,12 +408,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
416408
417409 await signOrders ( iexecWrapper . getDomain ( ) , orders2 , ordersActors ) ;
418410
419- const calldata2 = encodeMatchOrdersCalldata ( ...orders2 . toArray ( ) ) ;
420-
421411 const tx2 = await rlcInstanceAsRequester . approveAndCall (
422412 proxyAddress ,
423413 dealCost ,
424- calldata2 ,
414+ await matchOrdersCalldata ( orders2 ) ,
425415 ) ;
426416
427417 const dealId2 = getDealId ( iexecWrapper . getDomain ( ) , orders2 . requester ) ;
@@ -448,12 +438,11 @@ describe('IexecEscrowToken-receiveApproval', () => {
448438 await iexecWrapper . depositInIexecAccount ( scheduler , schedulerStake ) ;
449439
450440 const dealCost = 0n ;
451- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...ordersZeroPrice . toArray ( ) ) ;
452441
453442 const tx = await rlcInstanceAsRequester . approveAndCall (
454443 proxyAddress ,
455444 dealCost ,
456- matchOrdersCalldata ,
445+ await matchOrdersCalldata ( ordersZeroPrice ) ,
457446 ) ;
458447
459448 await expect ( tx )
@@ -502,12 +491,10 @@ describe('IexecEscrowToken-receiveApproval', () => {
502491 volume : volume ,
503492 } ) ;
504493
505- const matchOrdersCalldata = encodeMatchOrdersCalldata ( ...orders . toArray ( ) ) ;
506-
507494 const tx = rlcInstanceAsRequester . approveAndCall (
508495 proxyAddress ,
509496 depositAmount ,
510- matchOrdersCalldata ,
497+ await matchOrdersCalldata ( orders ) ,
511498 ) ;
512499 await expect ( tx ) . to . be . revertedWithCustomError ( iexecPoco , 'OperationFailed' ) ;
513500
@@ -526,3 +513,14 @@ describe('IexecEscrowToken-receiveApproval', () => {
526513 } ) ;
527514 } ) ;
528515} ) ;
516+
517+ /**
518+ * Helper function to simplify matchOrders calldata creation.
519+ */
520+ async function matchOrdersCalldata ( orders : IexecOrders ) {
521+ // Calldata can also be created using
522+ // IexecInterfaceToken__factory.createInterface().encodeFunctionData('matchOrders', orders);
523+ return await iexecPoco . matchOrders
524+ . populateTransaction ( ...orders . toArray ( ) )
525+ . then ( ( tx ) => tx . data ) ;
526+ }
0 commit comments