Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## vNEXT

### Updated contracts
- [x] `IexecPoco2Delegate.sol`

### Features
- Remove unnecessary back and forth transfers in `IexecPoco2Delegate` happening during `claim(..)`. (#167)
- Remove references to blockscout v5. (#161)
- Migrate integration test files to Typescript & Hardhat:
- 000_fullchain.js (#156, #157)
Expand Down
11 changes: 9 additions & 2 deletions contracts/modules/delegates/IexecPoco2Delegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV

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

/***************************************************************************
Expand Down
30 changes: 13 additions & 17 deletions test/byContract/IexecPoco/04_finalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ describe('IexecPoco2#finalize', async () => {
const sponsorFrozenBefore = await iexecPoco.frozenOf(sponsor.address);

await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
.to.emit(iexecPoco, 'TaskFinalize')
.to.changeTokenBalances(
iexecPoco,
[requester, sponsor, appProvider, datasetProvider],
Expand All @@ -348,7 +347,8 @@ describe('IexecPoco2#finalize', async () => {
appPrice, // app provider is rewarded
0, // but dataset provider is not rewarded
],
);
)
.to.emit(iexecPoco, 'TaskFinalize');
expect(await iexecPoco.frozenOf(requester.address)).to.be.equal(
requesterFrozenBefore - taskPrice,
);
Expand Down Expand Up @@ -517,22 +517,18 @@ describe('IexecPoco2#finalize', async () => {
(await iexecPoco.viewTask(kittyFillingDeal.taskId)).finalDeadline,
);
await expect(iexecPoco.claim(kittyFillingDeal.taskId))
.to.emit(iexecPoco, 'Transfer')
.withArgs(iexecPoco.address, kittyAddress, kittyFillingSchedulerTaskStake)
.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(kittyAddress, iexecPoco.address, kittyFillingSchedulerTaskStake)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake)
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, kittyAddress],
[
-workerpoolPriceToFillKitty, // deal payer is refunded
0,
],
);
)
.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake);
const kittyFrozenAfterClaim = (await iexecPoco.frozenOf(kittyAddress)).toNumber();
expect(kittyFrozenAfterClaim).to.equal(
kittyFrozenBeforeClaim + kittyFillingSchedulerTaskStake,
Expand Down Expand Up @@ -579,6 +575,11 @@ describe('IexecPoco2#finalize', async () => {
.reveal(taskId, resultDigest)
.then((tx) => tx.wait());
await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, scheduler, kittyAddress],
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
)
.to.emit(iexecPoco, 'TaskFinalize')
.to.emit(iexecPoco, 'Seize')
.withArgs(kittyAddress, expectedSchedulerKittyPartReward, taskId)
Expand All @@ -589,12 +590,7 @@ describe('IexecPoco2#finalize', async () => {
expectedSchedulerKittyPartReward,
)
.to.emit(iexecPoco, 'Reward')
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId)
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, scheduler, kittyAddress],
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
);
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId);
expect(await iexecPoco.frozenOf(kittyAddress)).to.equal(
kittyFrozenAfterClaim - expectedSchedulerKittyPartReward,
);
Expand Down
4 changes: 0 additions & 4 deletions test/byContract/IexecPoco/06_claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,8 @@ describe('IexecPoco2#claim', async () => {
.withArgs(sponsor.address, taskPrice)
.to.emit(iexecPoco, 'Seize')
.withArgs(scheduler.address, schedulerTaskStake, taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(iexecPoco.address, kittyAddress, schedulerTaskStake)
Comment on lines -147 to -148
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have the same here ?

await expect(iexecPoco.claim(kittyFillingDeal.taskId))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, I screened it first then moved on since test were OK.
I found a framework issue which forces us to check token balance changes before checking events, otherwise event checking never works ..!
We need to update that in both projects in next PRs (FYI @iExecBlockchainComputing/team-blockchain)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the point, we should keep in mind this !

.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, schedulerTaskStake, taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(kittyAddress, iexecPoco.address, schedulerTaskStake)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, schedulerTaskStake);
for (const worker of workers) {
Expand Down
Loading