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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## vNEXT
- Migrate unit test files to Typescript & Hardhat:
- ERC1154 (#145)
- IexecEscrowToken (#141, #143)
- IexecRelay (#140)
- IexecPoco1 (#136, #137)
Expand Down
File renamed without changes.
155 changes: 155 additions & 0 deletions test/byContract/IexecPoco/04_finalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,103 @@ describe('IexecPoco2#finalize', async () => {
expect(task.resultsCallback).to.equal('0x'); // deal without callback
});

it('Should finalize task when callback address is EOA', async () => {
const callbackEOAAddress = ethers.Wallet.createRandom().address;
const orders = buildOrders({
assets: ordersAssets,
requester: requester.address,
prices: ordersPrices,
callback: callbackEOAAddress,
});

const { dealId, taskId, taskIndex } = await iexecWrapper.signAndMatchOrders(
...orders.toArray(),
);
await iexecPoco.initialize(dealId, taskIndex).then((tx) => tx.wait());
const workerTaskStake = await iexecPoco
.viewDeal(dealId)
.then((deal) => deal.workerStake.toNumber());
const { resultHash, resultSeal } = buildResultHashAndResultSeal(
taskId,
callbackResultDigest,
worker1,
);
const schedulerSignature = await buildAndSignContributionAuthorizationMessage(
worker1.address,
taskId,
emptyEnclaveAddress,
scheduler,
);
await iexecWrapper.depositInIexecAccount(worker1, workerTaskStake);
await iexecPoco
.connect(worker1)
.contribute(
taskId,
resultHash,
resultSeal,
emptyEnclaveAddress,
emptyEnclaveSignature,
schedulerSignature,
)
.then((tx) => tx.wait());
await iexecPoco
.connect(worker1)
.reveal(taskId, callbackResultDigest)
.then((tx) => tx.wait());
await expect(iexecPocoAsScheduler.finalize(taskId, results, resultsCallback)).to.emit(
iexecPoco,
'TaskFinalize',
);
});

it('Should finalize task when callback address is non-EIP1154 contract', async () => {
const orders = buildOrders({
assets: ordersAssets,
requester: requester.address,
prices: ordersPrices,
callback: appAddress, // Non-EIP1154 contract
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use another random address to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here the appAddress was to meant to have a smart contract address and not a EOA without code in it

Copy link
Member

Choose a reason for hiding this comment

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

How about that

randomContract = await new OwnableMock__factory()
.connect(anyone)
.deploy()
.then((contract) => contract.deployed());

Or at least add a comment to explain than it's a random contract.

});

const { dealId, taskId, taskIndex } = await iexecWrapper.signAndMatchOrders(
...orders.toArray(),
);
await iexecPoco.initialize(dealId, taskIndex).then((tx) => tx.wait());
const workerTaskStake = await iexecPoco
.viewDeal(dealId)
.then((deal) => deal.workerStake.toNumber());
const { resultHash, resultSeal } = buildResultHashAndResultSeal(
taskId,
callbackResultDigest,
worker1,
);
const schedulerSignature = await buildAndSignContributionAuthorizationMessage(
worker1.address,
taskId,
emptyEnclaveAddress,
scheduler,
);
await iexecWrapper.depositInIexecAccount(worker1, workerTaskStake);
await iexecPoco
.connect(worker1)
.contribute(
taskId,
resultHash,
resultSeal,
emptyEnclaveAddress,
emptyEnclaveSignature,
schedulerSignature,
)
.then((tx) => tx.wait());
await iexecPoco
.connect(worker1)
.reveal(taskId, callbackResultDigest)
.then((tx) => tx.wait());
await expect(iexecPocoAsScheduler.finalize(taskId, results, resultsCallback)).to.emit(
iexecPoco,
'TaskFinalize',
);
});

describe('IexecPoco2#finalize-with-scheduler-kitty-part-reward', async () => {
[
{
Expand Down Expand Up @@ -733,6 +830,64 @@ describe('IexecPoco2#finalize', async () => {
).to.be.revertedWithoutReason(); // require#4
});

it('Should not finalize task when result callback is bad', async () => {
const oracleConsumerInstance = await new TestClient__factory()
.connect(anyone)
.deploy()
.then((contract) => contract.deployed());
const orders = buildOrders({
assets: ordersAssets,
requester: requester.address,
prices: ordersPrices,
callback: oracleConsumerInstance.address,
});

const { dealId, taskId, taskIndex } = await iexecWrapper.signAndMatchOrders(
...orders.toArray(),
);
await iexecPoco.initialize(dealId, taskIndex).then((tx) => tx.wait());
const workerTaskStake = await iexecPoco
.viewDeal(dealId)
.then((deal) => deal.workerStake.toNumber());
const { resultHash, resultSeal } = buildResultHashAndResultSeal(
taskId,
callbackResultDigest,
worker1,
);
const schedulerSignature = await buildAndSignContributionAuthorizationMessage(
worker1.address,
taskId,
emptyEnclaveAddress,
scheduler,
);
await iexecWrapper.depositInIexecAccount(worker1, workerTaskStake);
await iexecPoco
.connect(worker1)
.contribute(
taskId,
resultHash,
resultSeal,
emptyEnclaveAddress,
emptyEnclaveSignature,
schedulerSignature,
)
.then((tx) => tx.wait());
await iexecPoco
.connect(worker1)
.reveal(taskId, callbackResultDigest)
.then((tx) => tx.wait());
const task = await iexecPoco.viewTask(taskId);
expect(task.status).to.equal(TaskStatusEnum.REVEALING);
expect(task.revealCounter).to.equal(1);
// caller is scheduler, task status is revealing, before final deadline,
// reveal counter is reached
// but resultsCallback is bad
const { resultsCallback } = buildResultCallbackAndDigest(567);
await expect(
iexecPocoAsScheduler.finalize(taskId, results, resultsCallback),
).to.be.revertedWithoutReason(); // require#4 (part 2)
});

async function setWorkerScoreInStorage(worker: string, score: number) {
const workerScoreSlot = ethers.utils.hexStripZeros(
ethers.utils.keccak256(
Expand Down