@@ -129,8 +129,8 @@ describe('Integration tests', function () {
129129 ) ;
130130 const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask ;
131131 // Save frozens
132- const accounts = [ requester , scheduler , appProvider , datasetProvider , ... workers ] ;
133- const accountsInitialFrozens = await getInitialFrozens ( accounts ) ;
132+ const accounts = [ requester , scheduler , appProvider , datasetProvider ] ;
133+ const accountsInitialFrozens = await getInitialFrozens ( [ ... accounts , ... workers ] ) ;
134134 // Track initial scores
135135 // Finalize each task and check balance changes.
136136 const workerStakePerTask = await iexecPoco
@@ -169,10 +169,6 @@ describe('Integration tests', function () {
169169 // stake and reward amounts.
170170 const completedTasks = taskIndex + 1 ;
171171 // Verify token balance changes
172- const expectedProxyBalanceChange = - (
173- taskPrice * completedTasks +
174- schedulerStakePerTask * completedTasks
175- ) ;
176172 const winningWorkers = contributions
177173 . filter (
178174 ( contribution ) => contribution . result === 'iExec BOT ' + taskIndex . toString ( ) ,
@@ -186,15 +182,41 @@ describe('Integration tests', function () {
186182 const nonParticipantWorkers = workers . filter (
187183 ( worker ) => ! winningWorkers . includes ( worker ) && ! loosingWorkers . includes ( worker ) ,
188184 ) ;
185+ const participantWorkers = workers . filter (
186+ ( worker ) => ! nonParticipantWorkers . includes ( worker ) ,
187+ ) ;
188+ const totalWorkerPoolReward =
189+ workerpoolPrice + workerStakePerTask * loosingWorkers . length ; // bad wrokers lose their stake and add it to the pool price
190+ // compute expected worker reward for current task
191+ const workerRewardPerTask = await computeWorkerRewardForCurrentTask (
192+ totalWorkerPoolReward ,
193+ dealId ,
194+ ) ;
189195 const expectedWorkerBalanceChange =
190196 workerStakePerTask + workerRewardPerTask / winningWorkers . length ;
191- expect ( finalizeTx ) . to . changeTokenBalances (
197+ // compute expected scheduler reward for current task
198+ const schedulerRewardPerTask = totalWorkerPoolReward - workerRewardPerTask ;
199+ const expectedSchedulerBalanceChange = schedulerStakePerTask + schedulerRewardPerTask ;
200+
201+ const expectedProxyBalanceChange = - (
202+ taskPrice +
203+ workerStakePerTask * participantWorkers . length +
204+ schedulerStakePerTask
205+ ) ;
206+
207+ await expect ( finalizeTx ) . to . changeTokenBalances (
192208 iexecPoco ,
193- [ proxyAddress , ...accounts ] ,
209+ [
210+ proxyAddress ,
211+ ...accounts ,
212+ ...winningWorkers ,
213+ ...loosingWorkers ,
214+ ...nonParticipantWorkers ,
215+ ] ,
194216 [
195217 expectedProxyBalanceChange , // Proxy
196- - taskPrice * completedTasks , // Requester
197- schedulerStakePerTask + schedulerRewardPerTask , // Scheduler
218+ - 0 , // Requester
219+ expectedSchedulerBalanceChange , // Scheduler
198220 appPrice , // AppProvider
199221 datasetPrice , // DatasetProvider
200222 ...winningWorkers . map ( ( ) => expectedWorkerBalanceChange ) , // winning workers
@@ -245,6 +267,11 @@ describe('Integration tests', function () {
245267 }
246268 return scores ;
247269 }
270+
271+ async function computeWorkerRewardForCurrentTask ( totalPoolReward : number , dealId : string ) {
272+ const deal = await iexecPoco . viewDeal ( dealId ) ;
273+ return ( totalPoolReward * ( 100 - deal . schedulerRewardRatio . toNumber ( ) ) ) / 100 ;
274+ }
248275} ) ;
249276
250277async function checkFrozenChanges (
0 commit comments