@@ -213,6 +213,7 @@ describe('Integration tests', function () {
213213 const volume = 1 ;
214214 const disposableWorkers = [ worker1 , worker2 , worker3 , worker4 , worker5 ] ;
215215 const workers = disposableWorkers . slice ( 0 , workerNumber ) ;
216+ const acounts = [ requester , scheduler , appProvider , datasetProvider , ...workers ] ;
216217 // Create deal.
217218 const orders = buildOrders ( {
218219 assets : ordersAssets ,
@@ -233,20 +234,19 @@ describe('Integration tests', function () {
233234 ) ;
234235 const schedulerRewardPerTask = workerpoolPrice - workerRewardPerTask ;
235236 // Check initial balances.
236- let proxyInitBalance = dealPrice + schedulerStakePerDeal ;
237237 let accountsInitBalances = [
238- { signer : requester , balance : 0 , frozen : dealPrice } ,
239- { signer : scheduler , balance : 0 , frozen : schedulerStakePerDeal } ,
240- { signer : appProvider , balance : 0 , frozen : 0 } ,
241- { signer : datasetProvider , balance : 0 , frozen : 0 } ,
238+ {
239+ address : proxyAddress ,
240+ balance : ( await iexecPoco . balanceOf ( proxyAddress ) ) . toNumber ( ) ,
241+ frozen : ( await iexecPoco . frozenOf ( proxyAddress ) ) . toNumber ( ) ,
242+ } ,
242243 ] ;
243- for ( let i = 0 ; i < workerNumber ; i ++ ) {
244- accountsInitBalances . push ( { signer : workers [ i ] , balance : 0 , frozen : 0 } ) ;
244+ for ( const account of acounts ) {
245+ let address = account . address ;
246+ let balance = ( await iexecPoco . balanceOf ( account . address ) ) . toNumber ( ) ;
247+ let frozen = ( await iexecPoco . frozenOf ( account . address ) ) . toNumber ( ) ;
248+ accountsInitBalances . push ( { address, balance, frozen } ) ;
245249 }
246- await checkBalancesAndFrozens ( {
247- proxyBalance : proxyInitBalance ,
248- accounts : accountsInitBalances ,
249- } ) ;
250250 for ( let i = 0 ; i < workerNumber ; i ++ ) {
251251 expect ( await iexecPoco . viewScore ( workers [ i ] . address ) ) . to . be . equal ( 0 ) ;
252252 }
@@ -272,44 +272,22 @@ describe('Integration tests', function () {
272272 expect ( ( await iexecPoco . viewTask ( taskId ) ) . status ) . to . equal (
273273 TaskStatusEnum . COMPLETED ,
274274 ) ;
275- let proxyFinalBalance = proxyInitBalance - ( dealPrice + schedulerStakePerDeal ) ;
276- let accountsFinalBalances = [
277- {
278- signer : requester ,
279- balance : accountsInitBalances [ 0 ] . balance ,
280- frozen : accountsInitBalances [ 0 ] . frozen - taskPrice ,
281- } ,
282- {
283- signer : scheduler ,
284- balance :
285- accountsInitBalances [ 1 ] . balance +
286- ( schedulerStakePerTask + schedulerRewardPerTask ) ,
287- frozen : accountsInitBalances [ 1 ] . frozen - schedulerStakePerTask ,
288- } ,
289- {
290- signer : appProvider ,
291- balance : accountsInitBalances [ 2 ] . balance + appPrice ,
292- frozen : accountsInitBalances [ 2 ] . frozen ,
293- } ,
294- {
295- signer : datasetProvider ,
296- balance : accountsInitBalances [ 3 ] . balance + datasetPrice ,
297- frozen : accountsInitBalances [ 3 ] . frozen ,
298- } ,
275+ const expectedBalanceChanges = [
276+ - ( dealPrice + schedulerStakePerDeal ) ,
277+ 0 ,
278+ schedulerStakePerTask + schedulerRewardPerTask ,
279+ appPrice ,
280+ datasetPrice ,
299281 ] ;
282+ const expectedFrozenChanges = [ 0 , - taskPrice , - schedulerStakePerTask , 0 , 0 ] ;
300283 for ( let i = 0 ; i < workerNumber ; i ++ ) {
301- accountsFinalBalances . push ( {
302- signer : workers [ i ] ,
303- balance :
304- accountsInitBalances [ 4 + i ] . balance +
305- workerStake +
306- workerRewardPerTask / workerNumber ,
307- frozen : accountsInitBalances [ 4 + i ] . frozen ,
308- } ) ;
284+ expectedBalanceChanges . push ( workerStake + workerRewardPerTask / workerNumber ) ;
285+ expectedFrozenChanges . push ( 0 ) ;
309286 }
310- await checkBalancesAndFrozens ( {
311- proxyBalance : proxyFinalBalance ,
312- accounts : accountsFinalBalances ,
287+ await changesInBalancesAndFrozens ( {
288+ accountsInitBalances,
289+ balanceChanges : expectedBalanceChanges ,
290+ frozenChanges : expectedFrozenChanges ,
313291 } ) ;
314292 for ( let i = 0 ; i < workerNumber ; i ++ ) {
315293 if ( workerNumber == 1 ) {
@@ -335,3 +313,21 @@ async function checkBalancesAndFrozens(args: {
335313 expect ( await iexecPoco . frozenOf ( account . signer . address ) ) . to . equal ( account . frozen , message ) ;
336314 }
337315}
316+
317+ async function changesInBalancesAndFrozens ( args : {
318+ accountsInitBalances : { address : string ; balance : number ; frozen : number } [ ] ;
319+ balanceChanges : number [ ] ;
320+ frozenChanges : number [ ] ;
321+ } ) {
322+ for ( let i = 0 ; i < args . accountsInitBalances . length ; i ++ ) {
323+ const message = `Failed with account at index ${ i } ` ;
324+ expect ( await iexecPoco . balanceOf ( args . accountsInitBalances [ i ] . address ) ) . to . equal (
325+ args . accountsInitBalances [ i ] . balance + args . balanceChanges [ i ] ,
326+ message ,
327+ ) ;
328+ expect ( await iexecPoco . frozenOf ( args . accountsInitBalances [ i ] . address ) ) . to . equal (
329+ args . accountsInitBalances [ i ] . frozen + args . frozenChanges [ i ] ,
330+ message ,
331+ ) ;
332+ }
333+ }
0 commit comments