@@ -313,10 +313,86 @@ describe('Integration tests', function () {
313313 }
314314 } ) ;
315315
316- // TODO implement the following tests.
317-
318- it ( '[3] Sponsorship, beneficiary, callback, BoT, no replication' , async function ( ) { } ) ;
316+ it ( '[3] Sponsorship, beneficiary, callback, BoT, no replication' , async function ( ) {
317+ const volume = 3 ;
318+ // Create deal.
319+ const orders = buildOrders ( {
320+ assets : ordersAssets ,
321+ prices : ordersPrices ,
322+ requester : requester . address ,
323+ tag : standardDealTag ,
324+ beneficiary : beneficiary . address ,
325+ callback : callbackAddress ,
326+ volume,
327+ trust : 1 ,
328+ } ) ;
329+ const { dealId, dealPrice, schedulerStakePerDeal } =
330+ await iexecWrapper . signAndSponsorMatchOrders ( ...orders . toArray ( ) ) ;
331+ const taskPrice = appPrice + datasetPrice + workerpoolPrice ;
332+ const schedulerStakePerTask = schedulerStakePerDeal / volume ;
333+ const workerRewardPerTask = await iexecWrapper . computeWorkerRewardPerTask (
334+ dealId ,
335+ PocoMode . CLASSIC ,
336+ ) ;
337+ const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask ;
338+ // Save frozens
339+ const accounts = [ sponsor , requester , scheduler , appProvider , datasetProvider , worker1 ] ;
340+ const accountsInitialFrozens = await getInitialFrozens ( accounts ) ;
341+ // Finalize each task and check balance changes.
342+ for ( let taskIndex = 0 ; taskIndex < volume ; taskIndex ++ ) {
343+ const taskId = await iexecWrapper . initializeTask ( dealId , taskIndex ) ;
344+ const { workerStakePerTask } = await iexecWrapper . contributeToTask (
345+ dealId ,
346+ taskIndex ,
347+ callbackResultDigest ,
348+ worker1 ,
349+ ) ;
350+ await iexecPoco
351+ . connect ( worker1 )
352+ . reveal ( taskId , callbackResultDigest )
353+ . then ( ( tx ) => tx . wait ( ) ) ;
354+ const finalizeTx = await iexecPoco
355+ . connect ( scheduler )
356+ . finalize ( taskId , results , resultsCallback ) ;
357+ expect ( ( await iexecPoco . viewTask ( taskId ) ) . status ) . to . equal ( TaskStatusEnum . COMPLETED ) ;
358+ // Multiply amount by the number of finalized tasks to correctly compute
359+ // stake and reward amounts.
360+ const completedTasks = taskIndex + 1 ;
361+ // Verify token balance changes
362+ const expectedProxyBalanceChange = - (
363+ taskPrice * completedTasks +
364+ schedulerStakePerTask * completedTasks
365+ ) ;
366+ expect ( finalizeTx ) . to . changeTokenBalances (
367+ iexecPoco ,
368+ [ proxyAddress , sponsor , scheduler , appProvider , datasetProvider , worker1 ] ,
369+ [
370+ expectedProxyBalanceChange , // Proxy
371+ - taskPrice * completedTasks , // Sponsor
372+ schedulerStakePerTask + schedulerRewardPerTask , // Scheduler
373+ appPrice , // AppProvider
374+ datasetPrice , // DatasetProvider
375+ workerStakePerTask + workerRewardPerTask , // Worker
376+ ] ,
377+ ) ;
378+ // Calculate expected frozen changes
379+ const expectedFrozenChanges = [
380+ 0 , // Proxy
381+ - taskPrice * completedTasks , // Sponsor
382+ 0 , // Requester
383+ - schedulerStakePerTask * completedTasks , // Scheduler
384+ 0 , // AppProvider
385+ 0 , // DatasetProvider
386+ 0 , // Worker
387+ ] ;
388+ await changesInFrozen ( {
389+ accountsInitialFrozens,
390+ frozenChanges : expectedFrozenChanges ,
391+ } ) ;
392+ }
393+ } ) ;
319394
395+ // TODO implement the following tests.
320396 it ( '[4] No sponsorship, beneficiary, callback, BoT, no replication' , async function ( ) { } ) ;
321397
322398 it ( '[5] No sponsorship, no beneficiary, no callback, no BoT, no replication' , async function ( ) { } ) ;
0 commit comments