Skip to content

Commit d63499a

Browse files
committed
Merge branch 'develop' into feature/remove-reused-code
2 parents 37e229a + 5ef8455 commit d63499a

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Features
99
- Remove reused code in `IexecPoco2Delegate` in `contribute(...)` function. (#168)
10+
- Remove unnecessary back and forth transfers in `IexecPoco2Delegate` happening during `claim(..)`. (#167)
1011
- Remove references to blockscout v5. (#161)
1112
- Migrate integration test files to Typescript & Hardhat:
1213
- 000_fullchain.js (#156, #157)

contracts/modules/delegates/IexecPoco2Delegate.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV
6161

6262
unlock(deal.sponsor, taskPrice); // Refund the payer of the task
6363
seize(deal.workerpool.owner, poolstake, _taskid);
64-
reward(KITTY_ADDRESS, poolstake, _taskid); // → Kitty / Burn
65-
lock(KITTY_ADDRESS, poolstake); // → Kitty / Burn
64+
/**
65+
* Reward kitty and lock value on it.
66+
* Next lines optimize simple `reward(kitty, ..)` and `lock(kitty, ..)` calls
67+
* where functions would together uselessly transfer value from main PoCo
68+
* proxy to kitty, then would transfer value back from kitty to main PoCo proxy.
69+
*/
70+
m_frozens[KITTY_ADDRESS] += poolstake; // → Kitty / Burn
71+
emit Reward(KITTY_ADDRESS, poolstake, _taskid);
72+
emit Lock(KITTY_ADDRESS, poolstake);
6673
}
6774

6875
/***************************************************************************

test/byContract/IexecPoco/04_finalize.test.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ describe('IexecPoco2#finalize', async () => {
338338
const sponsorFrozenBefore = await iexecPoco.frozenOf(sponsor.address);
339339

340340
await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
341-
.to.emit(iexecPoco, 'TaskFinalize')
342341
.to.changeTokenBalances(
343342
iexecPoco,
344343
[requester, sponsor, appProvider, datasetProvider],
@@ -348,7 +347,8 @@ describe('IexecPoco2#finalize', async () => {
348347
appPrice, // app provider is rewarded
349348
0, // but dataset provider is not rewarded
350349
],
351-
);
350+
)
351+
.to.emit(iexecPoco, 'TaskFinalize');
352352
expect(await iexecPoco.frozenOf(requester.address)).to.be.equal(
353353
requesterFrozenBefore - taskPrice,
354354
);
@@ -517,22 +517,18 @@ describe('IexecPoco2#finalize', async () => {
517517
(await iexecPoco.viewTask(kittyFillingDeal.taskId)).finalDeadline,
518518
);
519519
await expect(iexecPoco.claim(kittyFillingDeal.taskId))
520-
.to.emit(iexecPoco, 'Transfer')
521-
.withArgs(iexecPoco.address, kittyAddress, kittyFillingSchedulerTaskStake)
522-
.to.emit(iexecPoco, 'Reward')
523-
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
524-
.to.emit(iexecPoco, 'Transfer')
525-
.withArgs(kittyAddress, iexecPoco.address, kittyFillingSchedulerTaskStake)
526-
.to.emit(iexecPoco, 'Lock')
527-
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake)
528520
.to.changeTokenBalances(
529521
iexecPoco,
530522
[iexecPoco, kittyAddress],
531523
[
532524
-workerpoolPriceToFillKitty, // deal payer is refunded
533525
0,
534526
],
535-
);
527+
)
528+
.to.emit(iexecPoco, 'Reward')
529+
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
530+
.to.emit(iexecPoco, 'Lock')
531+
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake);
536532
const kittyFrozenAfterClaim = (await iexecPoco.frozenOf(kittyAddress)).toNumber();
537533
expect(kittyFrozenAfterClaim).to.equal(
538534
kittyFrozenBeforeClaim + kittyFillingSchedulerTaskStake,
@@ -579,6 +575,11 @@ describe('IexecPoco2#finalize', async () => {
579575
.reveal(taskId, resultDigest)
580576
.then((tx) => tx.wait());
581577
await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
578+
.to.changeTokenBalances(
579+
iexecPoco,
580+
[iexecPoco, scheduler, kittyAddress],
581+
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
582+
)
582583
.to.emit(iexecPoco, 'TaskFinalize')
583584
.to.emit(iexecPoco, 'Seize')
584585
.withArgs(kittyAddress, expectedSchedulerKittyPartReward, taskId)
@@ -589,12 +590,7 @@ describe('IexecPoco2#finalize', async () => {
589590
expectedSchedulerKittyPartReward,
590591
)
591592
.to.emit(iexecPoco, 'Reward')
592-
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId)
593-
.to.changeTokenBalances(
594-
iexecPoco,
595-
[iexecPoco, scheduler, kittyAddress],
596-
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
597-
);
593+
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId);
598594
expect(await iexecPoco.frozenOf(kittyAddress)).to.equal(
599595
kittyFrozenAfterClaim - expectedSchedulerKittyPartReward,
600596
);

test/byContract/IexecPoco/06_claim.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,8 @@ describe('IexecPoco2#claim', async () => {
144144
.withArgs(sponsor.address, taskPrice)
145145
.to.emit(iexecPoco, 'Seize')
146146
.withArgs(scheduler.address, schedulerTaskStake, taskId)
147-
.to.emit(iexecPoco, 'Transfer')
148-
.withArgs(iexecPoco.address, kittyAddress, schedulerTaskStake)
149147
.to.emit(iexecPoco, 'Reward')
150148
.withArgs(kittyAddress, schedulerTaskStake, taskId)
151-
.to.emit(iexecPoco, 'Transfer')
152-
.withArgs(kittyAddress, iexecPoco.address, schedulerTaskStake)
153149
.to.emit(iexecPoco, 'Lock')
154150
.withArgs(kittyAddress, schedulerTaskStake);
155151
for (const worker of workers) {

0 commit comments

Comments
 (0)