-
Notifications
You must be signed in to change notification settings - Fork 14
clean and migrate callback erc1154 UT file part 1 #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e882ed1
5828c2a
5cbafb6
6a16426
e991668
36a69a0
4f98577
37a9704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use another random address to avoid confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about that PoCo/test/byContract/IexecPoco/IexecPoco1.test.ts Lines 121 to 124 in 4821374
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 () => { | ||||||||||
[ | ||||||||||
{ | ||||||||||
|
@@ -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( | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.