From d4c33d94a0554b18f27b4a8ab1ca5515e7a316d2 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 27 May 2024 08:52:34 +0200 Subject: [PATCH 01/13] Revert "Resize PR" This reverts commit 201eb48269710b18addb6fecc0f33fef46da5ae9. --- test/beacon/Voucher.test.ts | 50 ++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index ffd5b3e5..8163d884 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -597,7 +597,55 @@ describe('Voucher', function () { describe('Should claim task when deal is not matched by voucher', async () => {}); - describe('Should claim task when already claimed on PoCo', async () => {}); + describe('Should claim task when already claimed on PoCo', async () => { + it('Classic', async () => + await runTest(voucherMatchOrders, iexecPocoInstance.claim, [taskId])); + it('Boost', async () => + await runTest(voucherMatchOrdersBoost, iexecPocoInstance.claimBoost, [ + dealId, + '0', + ])); + + async function runTest( + matchOrdersFunction: any, + pocoClaimFunction: any, + pocoClaimArgs: string[], + ) { + await addEligibleAssets([app, dataset, workerpool]); + await matchOrdersFunction(); + const { + voucherCreditBalance: voucherCreditBalancePreClaim, + voucherRlcBalance: voucherRlcBalancePreClaim, + requesterRlcBalance: requesterRlcBalancePreClaim, + } = await getVoucherAndRequesterBalances(); + // The voucher should've fully sponsored the deal. + const dealSponsoredAmount = await voucher.getSponsoredAmount(dealId); + const taskSponsoredAmount = dealSponsoredAmount / volume; + expect(dealSponsoredAmount).to.be.equal(dealPrice); + expect(taskSponsoredAmount).to.be.equal(taskPrice); + + // Claim task on PoCo. + await pocoClaimFunction(...pocoClaimArgs); + // Claim task on voucher + await expect(voucher.claim(dealId, taskIndex)) + .to.emit(voucherHub, 'VoucherRefunded') + .withArgs(voucherAddress, taskSponsoredAmount) + .to.emit(voucher, 'TaskClaimedWithVoucher') + .withArgs(dealId, taskIndex); + const { + voucherCreditBalance: voucherCreditBalancePostClaim, + voucherRlcBalance: voucherRlcBalancePostClaim, + requesterRlcBalance: requesterRlcBalancePostClaim, + } = await getVoucherAndRequesterBalances(); + // Voucher credit and RLC balances should increase while staying equal. + expect(voucherCreditBalancePostClaim) + .to.be.equal(voucherCreditBalancePreClaim + taskPrice) + .to.be.equal(voucherRlcBalancePostClaim) + .to.be.equal(voucherRlcBalancePreClaim + taskPrice); + // Requester balance should stay unchanged. + expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); + } + }); describe('Should not claim task twice', async () => {}); From 3ded718250b86acf49edbceaa7e6d75c2d976ae0 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 27 May 2024 08:52:53 +0200 Subject: [PATCH 02/13] Revert "Resize PR" This reverts commit 6ebd8a71c61e4c1407526b4ffc3c1d6c1c12e63b. --- test/beacon/Voucher.test.ts | 261 ++++++++++++++++++++++++++++++++++-- 1 file changed, 253 insertions(+), 8 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 8163d884..6c74484f 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -588,14 +588,176 @@ describe('Voucher', function () { } }); - describe('Should claim task when deal is partially sponsored', async () => {}); + describe('Should claim task when deal is partially sponsored', async () => { + it('Classic', async () => await runTest(voucherMatchOrders)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost)); + + async function runTest(matchOrdersFunction: any) { + await addEligibleAssets([app, dataset]); // workerpool not eligible. + const dealNonSponsoredAmount = workerpoolPrice; + const taskNonSponsoredAmount = dealNonSponsoredAmount / volume; + // Deposit non-sponsored amount for requester and approve voucher. + await iexecPocoInstance + .transfer(requester, dealNonSponsoredAmount) + .then((tx) => tx.wait()); + await iexecPocoInstance + .connect(requester) + .approve(voucherAddress, dealNonSponsoredAmount) + .then((tx) => tx.wait()); + // Match orders + await matchOrdersFunction(); + const { + voucherCreditBalance: voucherCreditBalancePreClaim, + voucherRlcBalance: voucherRlcBalancePreClaim, + requesterRlcBalance: requesterRlcBalancePreClaim, + } = await getVoucherAndRequesterBalances(); + // The voucher should've partially sponsored the deal. + const dealSponsoredAmount = await voucher.getSponsoredAmount(dealId); + const taskSponsoredAmount = dealSponsoredAmount / volume; + expect(dealSponsoredAmount).to.be.equal(dealPrice - dealNonSponsoredAmount); + expect(taskSponsoredAmount).to.be.equal(taskPrice - taskNonSponsoredAmount); + + // Claim + await expect(voucher.claim(dealId, taskIndex)) + .to.emit(voucherHub, 'VoucherRefunded') + .withArgs(voucherAddress, taskSponsoredAmount) + .to.emit(voucher, 'TaskClaimedWithVoucher') + .withArgs(dealId, taskIndex); + const { + voucherCreditBalance: voucherCreditBalancePostClaim, + voucherRlcBalance: voucherRlcBalancePostClaim, + requesterRlcBalance: requesterRlcBalancePostClaim, + } = await getVoucherAndRequesterBalances(); + // Voucher credit and RLC balances should increase while staying equal. + expect(voucherCreditBalancePostClaim) + .to.be.equal(voucherCreditBalancePreClaim + taskSponsoredAmount) + .to.be.equal(voucherRlcBalancePostClaim) + .to.be.equal(voucherRlcBalancePreClaim + taskSponsoredAmount); + // Requester balance should increase. + expect(requesterRlcBalancePostClaim).to.be.equal( + requesterRlcBalancePreClaim + taskNonSponsoredAmount, + ); + } + }); // TODO when volume can be > 1 - describe('Should claim task when deal is partially sponsored and sponsored amount is not divisible by volume', async () => {}); + describe('Should claim task when deal is partially sponsored and sponsored amount is not divisible by volume', async () => { + it.skip('Classic', async () => await runTest(voucherMatchOrders)); + it.skip('Boost', async () => await runTest(voucherMatchOrdersBoost)); - describe('Should claim task when deal is not sponsored but matched by voucher', async () => {}); + async function runTest(matchOrdersFunction: any) { + // Use another voucher with a small amount of credits. + const smallVoucherValue = 1n; + voucher = await voucherHubAsVoucherCreationManager + .createVoucher(voucherOwner2, voucherType, smallVoucherValue) + .then((tx) => tx.wait()) + .then(() => voucherHub.getVoucher(voucherOwner1)) + .then((voucherAddress) => + Voucher__factory.connect(voucherAddress, voucherOwner1), + ); + } + }); + + describe('Should claim task when deal is not sponsored but matched by voucher', async () => { + it('Classic', async () => await runTest(voucherMatchOrders)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost)); + + async function runTest(matchOrdersFunction: any) { + // Assets are not eligible. + // Deposit dealPrice amount for requester and approve voucher. + await iexecPocoInstance + .transfer(requester, dealPrice) + .then((tx) => tx.wait()) + .then(() => + iexecPocoInstance.connect(requester).approve(voucherAddress, dealPrice), + ) + .then((tx) => tx.wait()); + // Match orders + await matchOrdersFunction(); + const { + voucherCreditBalance: voucherCreditBalancePreClaim, + voucherRlcBalance: voucherRlcBalancePreClaim, + requesterRlcBalance: requesterRlcBalancePreClaim, + } = await getVoucherAndRequesterBalances(); + // The voucher should not sponsor the deal. + const dealSponsoredAmount = await voucher.getSponsoredAmount(dealId); + expect(dealSponsoredAmount).to.be.equal(0); + + // Claim + await expect(voucher.claim(dealId, taskIndex)) + .to.emit(voucher, 'TaskClaimedWithVoucher') + .withArgs(dealId, taskIndex) + .and.to.not.emit(voucherHub, 'VoucherRefunded'); + const { + voucherCreditBalance: voucherCreditBalancePostClaim, + voucherRlcBalance: voucherRlcBalancePostClaim, + requesterRlcBalance: requesterRlcBalancePostClaim, + } = await getVoucherAndRequesterBalances(); + // Voucher credit and RLC balances should stay unchanged. + expect(voucherCreditBalancePostClaim) + .to.be.equal(voucherCreditBalancePreClaim) + .to.be.equal(voucherRlcBalancePostClaim) + .to.be.equal(voucherRlcBalancePreClaim); + // Requester balance should increase. + expect(requesterRlcBalancePostClaim).to.be.equal( + requesterRlcBalancePreClaim + taskPrice, + ); + } + }); + + describe('Should claim task when deal is not matched by voucher', async () => { + // Match orders directly on PoCo by requester. + const pocoMatchOrders = async () => + await iexecPocoInstance + .connect(requester) + .sponsorMatchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder) + .then((tx) => tx.wait()); + + const pocoMatchOrdersBoost = async () => + await iexecPocoInstance + .connect(requester) + .sponsorMatchOrdersBoost(appOrder, datasetOrder, workerpoolOrder, requestOrder) + .then((tx) => tx.wait()); + + it('Classic', async () => await runTest(pocoMatchOrders)); + it('Boost', async () => await runTest(pocoMatchOrdersBoost)); + + async function runTest(matchOrdersFunction: any) { + // Assets are not eligible. + // Deposit dealPrice amount for requester. + await iexecPocoInstance.transfer(requester, dealPrice).then((tx) => tx.wait()); + // Match orders. + await matchOrdersFunction(); + const { + voucherCreditBalance: voucherCreditBalancePreClaim, + voucherRlcBalance: voucherRlcBalancePreClaim, + requesterRlcBalance: requesterRlcBalancePreClaim, + } = await getVoucherAndRequesterBalances(); + // The voucher should not sponsor the deal. + const dealSponsoredAmount = await voucher.getSponsoredAmount(dealId); + expect(dealSponsoredAmount).to.be.equal(0); - describe('Should claim task when deal is not matched by voucher', async () => {}); + // Claim + await expect(voucher.claim(dealId, taskIndex)) + .to.emit(voucher, 'TaskClaimedWithVoucher') + .withArgs(dealId, taskIndex) + .and.to.not.emit(voucherHub, 'VoucherRefunded'); + const { + voucherCreditBalance: voucherCreditBalancePostClaim, + voucherRlcBalance: voucherRlcBalancePostClaim, + requesterRlcBalance: requesterRlcBalancePostClaim, + } = await getVoucherAndRequesterBalances(); + // Voucher credit and RLC balances should stay unchanged. + expect(voucherCreditBalancePostClaim) + .to.be.equal(voucherCreditBalancePreClaim) + .to.be.equal(voucherRlcBalancePostClaim) + .to.be.equal(voucherRlcBalancePreClaim); + // Requester balance should increase. + expect(requesterRlcBalancePostClaim).to.be.equal( + requesterRlcBalancePreClaim + taskPrice, + ); + } + }); describe('Should claim task when already claimed on PoCo', async () => { it('Classic', async () => @@ -647,13 +809,96 @@ describe('Voucher', function () { } }); - describe('Should not claim task twice', async () => {}); + describe('Should not claim task twice', async () => { + it('Classic', async () => await runTest(voucherMatchOrders)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost)); - describe('Should not claim task when deal not found', async () => {}); + async function runTest(matchOrdersFunction: any) { + await addEligibleAssets([app, dataset, workerpool]); + await matchOrdersFunction(); + const { + voucherCreditBalance: voucherCreditBalancePreClaim, + voucherRlcBalance: voucherRlcBalancePreClaim, + requesterRlcBalance: requesterRlcBalancePreClaim, + } = await getVoucherAndRequesterBalances(); + // The voucher should've fully sponsored the deal. + const dealSponsoredAmount = await voucher.getSponsoredAmount(dealId); + const taskSponsoredAmount = dealSponsoredAmount / volume; + expect(dealSponsoredAmount).to.be.equal(dealPrice); + expect(taskSponsoredAmount).to.be.equal(taskPrice); - describe('Should not claim task when task not found', async () => {}); + // Claim task + await expect(voucher.claim(dealId, taskIndex)) + .to.emit(voucherHub, 'VoucherRefunded') + .withArgs(voucherAddress, taskSponsoredAmount) + .to.emit(voucher, 'TaskClaimedWithVoucher') + .withArgs(dealId, taskIndex); + const { + voucherCreditBalance: voucherCreditBalancePostClaim, + voucherRlcBalance: voucherRlcBalancePostClaim, + requesterRlcBalance: requesterRlcBalancePostClaim, + } = await getVoucherAndRequesterBalances(); + // Voucher credit and RLC balances should increase while staying equal. + expect(voucherCreditBalancePostClaim) + .to.be.equal(voucherCreditBalancePreClaim + taskPrice) + .to.be.equal(voucherRlcBalancePostClaim) + .to.be.equal(voucherRlcBalancePreClaim + taskPrice); + // Requester balance should stay unchanged. + expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); + + // Second claim should revert. + await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( + 'Voucher: task already claimed', + ); + } + }); + + describe('Should not claim task when deal not found', async () => { + it('Classic', async () => await runTest()); + it('Boost', async () => await runTest()); + + async function runTest() { + await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( + 'Voucher: deal not found', + ); + } + }); - describe('Should not claim task when PoCo claim reverts', async () => {}); + describe('Should not claim task when task not found', async () => { + it('Classic', async () => await runTest(voucherMatchOrders, false)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); + + async function runTest(matchOrdersFunction: any, isBoost: boolean) { + await addEligibleAssets([app, dataset, workerpool]); + await matchOrdersFunction(); + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); + // Claim task + const badTaskIndex = 99; + if (isBoost) { + await expect(voucher.claim(dealId, badTaskIndex)).to.be.revertedWith( + 'PocoBoost: Unknown task', + ); + } else { + await expect(voucher.claim(dealId, badTaskIndex)).to.be.revertedWithoutReason(); + } + } + }); + + describe('Should not claim task when PoCo claim reverts', async () => { + it('Classic', async () => await runTest(voucherMatchOrders, false)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); + + async function runTest(matchOrdersFunction: any, isBoost: boolean) { + await addEligibleAssets([app, dataset, workerpool]); + await matchOrdersFunction(); + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); + // Claim task + await iexecPocoInstance.willRevertOnClaim().then((tx) => tx.wait()); + await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( + 'IexecPocoMock: Failed to claim' + (isBoost ? ' boost' : ''), + ); + } + }); }); async function addEligibleAssets(assets: string[]) { From 3895dd734e456dcd277ae5acb2c2b2b66ebf6611 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 27 May 2024 09:01:50 +0200 Subject: [PATCH 03/13] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba23a7ec..11822d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## vNEXT +- Claim task part 2 - Add voucher tests. (#21) - Claim task part 1 - Solidity with minimal tests. (#20) - Refactor voucher tests file. (#18) - Use real poco address if available at deployment. (#17) From 4e726611ca439542430af5ed9403fc9f698c93f1 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 27 May 2024 10:03:14 +0200 Subject: [PATCH 04/13] Clean --- test/beacon/Voucher.test.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 6c74484f..c6ba04de 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -553,9 +553,9 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders)); it('Boost', async () => await runTest(voucherMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -592,7 +592,7 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders)); it('Boost', async () => await runTest(voucherMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { await addEligibleAssets([app, dataset]); // workerpool not eligible. const dealNonSponsoredAmount = workerpoolPrice; const taskNonSponsoredAmount = dealNonSponsoredAmount / volume; @@ -605,7 +605,7 @@ describe('Voucher', function () { .approve(voucherAddress, dealNonSponsoredAmount) .then((tx) => tx.wait()); // Match orders - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -645,7 +645,7 @@ describe('Voucher', function () { it.skip('Classic', async () => await runTest(voucherMatchOrders)); it.skip('Boost', async () => await runTest(voucherMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { // Use another voucher with a small amount of credits. const smallVoucherValue = 1n; voucher = await voucherHubAsVoucherCreationManager @@ -662,7 +662,7 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders)); it('Boost', async () => await runTest(voucherMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { // Assets are not eligible. // Deposit dealPrice amount for requester and approve voucher. await iexecPocoInstance @@ -673,7 +673,7 @@ describe('Voucher', function () { ) .then((tx) => tx.wait()); // Match orders - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -722,12 +722,12 @@ describe('Voucher', function () { it('Classic', async () => await runTest(pocoMatchOrders)); it('Boost', async () => await runTest(pocoMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { // Assets are not eligible. // Deposit dealPrice amount for requester. await iexecPocoInstance.transfer(requester, dealPrice).then((tx) => tx.wait()); // Match orders. - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -769,12 +769,12 @@ describe('Voucher', function () { ])); async function runTest( - matchOrdersFunction: any, + matchOrdersBoostOrClassic: any, pocoClaimFunction: any, pocoClaimArgs: string[], ) { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -813,9 +813,9 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders)); it('Boost', async () => await runTest(voucherMatchOrdersBoost)); - async function runTest(matchOrdersFunction: any) { + async function runTest(matchOrdersBoostOrClassic: any) { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); const { voucherCreditBalance: voucherCreditBalancePreClaim, voucherRlcBalance: voucherRlcBalancePreClaim, @@ -868,9 +868,9 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders, false)); it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); - async function runTest(matchOrdersFunction: any, isBoost: boolean) { + async function runTest(matchOrdersBoostOrClassic: any, isBoost: boolean) { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); // Claim task const badTaskIndex = 99; @@ -888,9 +888,9 @@ describe('Voucher', function () { it('Classic', async () => await runTest(voucherMatchOrders, false)); it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); - async function runTest(matchOrdersFunction: any, isBoost: boolean) { + async function runTest(matchOrdersBoostOrClassic: any, isBoost: boolean) { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersFunction(); + await matchOrdersBoostOrClassic(); expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); // Claim task await iexecPocoInstance.willRevertOnClaim().then((tx) => tx.wait()); From b42ab027f87b9db2c3e64cfc9d92673594a8839a Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 27 May 2024 17:06:04 +0200 Subject: [PATCH 05/13] Update tests --- contracts/beacon/Voucher.sol | 3 +++ package-lock.json | 2 +- test/beacon/Voucher.test.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contracts/beacon/Voucher.sol b/contracts/beacon/Voucher.sol index dedd751f..3c7200ad 100644 --- a/contracts/beacon/Voucher.sol +++ b/contracts/beacon/Voucher.sol @@ -230,6 +230,9 @@ contract Voucher is OwnableUpgradeable, IVoucher { // If the voucher did fully/partially sponsor the deal then mint voucher // credits back. voucherHub.refundVoucher(taskSponsoredAmount); + $._voucherMatchedDeals[dealId].sponsoredAmount = + voucherMatchedDeal.sponsoredAmount - + uint64(taskSponsoredAmount); } if (taskSponsoredAmount < taskPrice) { // If the deal was not sponsored or partially sponsored diff --git a/package-lock.json b/package-lock.json index e65d62ee..7cd88d69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -942,7 +942,7 @@ }, "node_modules/@iexec/poco": { "version": "5.5.0", - "resolved": "git+ssh://git@github.com/iExecBlockchainComputing/PoCo.git#757f53cf2c9508c7bc6dd9373702c42a26b3044f", + "resolved": "git+ssh://git@github.com/iExecBlockchainComputing/PoCo.git#eab98cafa11ee112f44704e5e775e2d502b26571", "license": "Apache-2.0", "dependencies": { "@iexec/interface": "3.0.35-8", diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index c6ba04de..4fddcd37 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -585,6 +585,10 @@ describe('Voucher', function () { .to.be.equal(voucherRlcBalancePreClaim + taskPrice); // Requester balance should stay unchanged. expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); + // Sponsored amount should decrease + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal( + dealSponsoredAmount - taskPrice, + ); } }); @@ -637,6 +641,10 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal( requesterRlcBalancePreClaim + taskNonSponsoredAmount, ); + // Sponsored amount should decrease + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal( + dealSponsoredAmount - taskSponsoredAmount, + ); } }); @@ -702,6 +710,8 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal( requesterRlcBalancePreClaim + taskPrice, ); + // Sponsored amount should stay unchanged. + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(0); } }); @@ -756,6 +766,8 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal( requesterRlcBalancePreClaim + taskPrice, ); + // Sponsored amount should stay unchanged. + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); } }); @@ -806,6 +818,10 @@ describe('Voucher', function () { .to.be.equal(voucherRlcBalancePreClaim + taskPrice); // Requester balance should stay unchanged. expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); + // Sponsored amount should decrease + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal( + dealSponsoredAmount - taskSponsoredAmount, + ); } }); From 47dd27add5722bb81ba1f94a52b24eaa4ccdaa8c Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Tue, 28 May 2024 15:33:01 +0200 Subject: [PATCH 06/13] Update tests --- test/beacon/Voucher.test.ts | 128 ++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 56 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index ee24b872..3ba7e50b 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -596,10 +596,10 @@ describe('Voucher', function () { }); describe('Should claim task when deal is partially sponsored', async () => { - it('Classic', async () => await runTest(voucherMatchOrders)); - it('Boost', async () => await runTest(voucherMatchOrdersBoost)); + it('Classic', async () => await runTest(voucherMatchOrders, claim)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost)); - async function runTest(matchOrdersBoostOrClassic: any) { + async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { await addEligibleAssets([app, dataset]); // workerpool not eligible. const dealNonSponsoredAmount = workerpoolPrice; const taskNonSponsoredAmount = dealNonSponsoredAmount / volume; @@ -625,7 +625,7 @@ describe('Voucher', function () { expect(taskSponsoredAmount).to.be.equal(taskPrice - taskNonSponsoredAmount); // Claim - await expect(voucher.claim(dealId, taskIndex)) + await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') @@ -653,10 +653,10 @@ describe('Voucher', function () { // TODO when volume can be > 1 describe('Should claim task when deal is partially sponsored and sponsored amount is not divisible by volume', async () => { - it.skip('Classic', async () => await runTest(voucherMatchOrders)); - it.skip('Boost', async () => await runTest(voucherMatchOrdersBoost)); + it.skip('Classic', async () => await runTest(voucherMatchOrders, claim)); + it.skip('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost)); - async function runTest(matchOrdersBoostOrClassic: any) { + async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { // Use another voucher with a small amount of credits. const smallVoucherValue = 1n; voucher = await voucherHubAsVoucherCreationManager @@ -670,10 +670,10 @@ describe('Voucher', function () { }); describe('Should claim task when deal is not sponsored but matched by voucher', async () => { - it('Classic', async () => await runTest(voucherMatchOrders)); - it('Boost', async () => await runTest(voucherMatchOrdersBoost)); + it('Classic', async () => await runTest(voucherMatchOrders, claim)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost)); - async function runTest(matchOrdersBoostOrClassic: any) { + async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { // Assets are not eligible. // Deposit dealPrice amount for requester and approve voucher. await iexecPocoInstance @@ -695,7 +695,7 @@ describe('Voucher', function () { expect(dealSponsoredAmount).to.be.equal(0); // Claim - await expect(voucher.claim(dealId, taskIndex)) + await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') .withArgs(dealId, taskIndex) .and.to.not.emit(voucherHub, 'VoucherRefunded'); @@ -732,10 +732,10 @@ describe('Voucher', function () { .sponsorMatchOrdersBoost(appOrder, datasetOrder, workerpoolOrder, requestOrder) .then((tx) => tx.wait()); - it('Classic', async () => await runTest(pocoMatchOrders)); - it('Boost', async () => await runTest(pocoMatchOrdersBoost)); + it('Classic', async () => await runTest(pocoMatchOrders, claim)); + it('Boost', async () => await runTest(pocoMatchOrdersBoost, claimBoost)); - async function runTest(matchOrdersBoostOrClassic: any) { + async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { // Assets are not eligible. // Deposit dealPrice amount for requester. await iexecPocoInstance.transfer(requester, dealPrice).then((tx) => tx.wait()); @@ -751,7 +751,7 @@ describe('Voucher', function () { expect(dealSponsoredAmount).to.be.equal(0); // Claim - await expect(voucher.claim(dealId, taskIndex)) + await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') .withArgs(dealId, taskIndex) .and.to.not.emit(voucherHub, 'VoucherRefunded'); @@ -775,18 +775,17 @@ describe('Voucher', function () { }); describe('Should claim task when already claimed on PoCo', async () => { - it('Classic', async () => - await runTest(voucherMatchOrders, iexecPocoInstance.claim, [taskId])); + const pocoClaim = () => iexecPocoInstance.claim(taskId); + const pocoClaimBoost = () => iexecPocoInstance.claimBoost(dealId, taskIndex); + + it('Classic', async () => await runTest(voucherMatchOrders, pocoClaim, claim)); it('Boost', async () => - await runTest(voucherMatchOrdersBoost, iexecPocoInstance.claimBoost, [ - dealId, - '0', - ])); + await runTest(voucherMatchOrdersBoost, pocoClaimBoost, claimBoost)); async function runTest( matchOrdersBoostOrClassic: any, - pocoClaimFunction: any, - pocoClaimArgs: string[], + pocoClaimBoostOrClassic: any, + claimBoostOrClassic: any, ) { await addEligibleAssets([app, dataset, workerpool]); await matchOrdersBoostOrClassic(); @@ -802,9 +801,9 @@ describe('Voucher', function () { expect(taskSponsoredAmount).to.be.equal(taskPrice); // Claim task on PoCo. - await pocoClaimFunction(...pocoClaimArgs); + await pocoClaimBoostOrClassic(); // Claim task on voucher - await expect(voucher.claim(dealId, taskIndex)) + await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') @@ -829,10 +828,10 @@ describe('Voucher', function () { }); describe('Should not claim task twice', async () => { - it('Classic', async () => await runTest(voucherMatchOrders)); - it('Boost', async () => await runTest(voucherMatchOrdersBoost)); + it('Classic', async () => await runTest(voucherMatchOrders, claim)); + it('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost)); - async function runTest(matchOrdersBoostOrClassic: any) { + async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { await addEligibleAssets([app, dataset, workerpool]); await matchOrdersBoostOrClassic(); const { @@ -847,7 +846,7 @@ describe('Voucher', function () { expect(taskSponsoredAmount).to.be.equal(taskPrice); // Claim task - await expect(voucher.claim(dealId, taskIndex)) + await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') @@ -866,57 +865,74 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); // Second claim should revert. - await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( + await expect(claimBoostOrClassic()).to.be.revertedWith( 'Voucher: task already claimed', ); } }); describe('Should not claim task when deal not found', async () => { - it('Classic', async () => await runTest()); - it('Boost', async () => await runTest()); + it('Classic', async function () { + await expect(voucher.claim(taskId)).to.be.revertedWith('Voucher: deal not found'); + }); - async function runTest() { - await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( - 'Voucher: deal not found', + it('Boost', async function () { + await expect(voucher.claimBoost(dealId, taskIndex)).to.be.revertedWith( + 'Voucher: boost deal not found', ); - } + }); }); describe('Should not claim task when task not found', async () => { - it('Classic', async () => await runTest(voucherMatchOrders, false)); - it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); + it('Classic', async function () { + await addEligibleAssets([app, dataset, workerpool]); + await voucherMatchOrders(); + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); + // Claim task + const badTaskIndex = 99; + const badTaskId = ethers.keccak256( + ethers.AbiCoder.defaultAbiCoder().encode( + ['bytes32', 'uint256'], + [dealId, badTaskIndex], + ), + ); + // await expect(iexecPocoInstance.claim(badTaskId)).to.be.revertedWithoutReason(); + await expect(voucher.claim(badTaskId)).to.be.revertedWithoutReason(); + }); - async function runTest(matchOrdersBoostOrClassic: any, isBoost: boolean) { + it('Boost', async function () { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersBoostOrClassic(); + await voucherMatchOrdersBoost(); expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); // Claim task const badTaskIndex = 99; - if (isBoost) { - await expect(voucher.claim(dealId, badTaskIndex)).to.be.revertedWith( - 'PocoBoost: Unknown task', - ); - } else { - await expect(voucher.claim(dealId, badTaskIndex)).to.be.revertedWithoutReason(); - } - } + await expect(voucher.claimBoost(dealId, badTaskIndex)).to.be.revertedWith( + 'PocoBoost: Unknown task', + ); + }); }); describe('Should not claim task when PoCo claim reverts', async () => { - it('Classic', async () => await runTest(voucherMatchOrders, false)); - it('Boost', async () => await runTest(voucherMatchOrdersBoost, true)); - - async function runTest(matchOrdersBoostOrClassic: any, isBoost: boolean) { + it('Classic', async function () { await addEligibleAssets([app, dataset, workerpool]); - await matchOrdersBoostOrClassic(); + await voucherMatchOrders(); expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); + await iexecPocoInstance.willRevertOnClaim().then((tx) => tx.wait()); // Claim task + await expect(voucher.claim(taskId)).to.be.revertedWith( + 'IexecPocoMock: Failed to claim', + ); + }); + it('Boost', async function () { + await addEligibleAssets([app, dataset, workerpool]); + await voucherMatchOrdersBoost(); + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealPrice); await iexecPocoInstance.willRevertOnClaim().then((tx) => tx.wait()); - await expect(voucher.claim(dealId, taskIndex)).to.be.revertedWith( - 'IexecPocoMock: Failed to claim' + (isBoost ? ' boost' : ''), + // Claim task + await expect(voucher.claimBoost(dealId, taskIndex)).to.be.revertedWith( + 'IexecPocoMock: Failed to claim boost', ); - } + }); }); }); From b48adb4c997d3619fad2599701059f2c6d455905 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Tue, 28 May 2024 17:58:44 +0200 Subject: [PATCH 07/13] Update tests --- test/beacon/Voucher.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 694db95a..07b96508 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -629,7 +629,7 @@ describe('Voucher', function () { .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(dealId, taskIndex); + .withArgs(taskId); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, @@ -697,7 +697,7 @@ describe('Voucher', function () { // Claim await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(dealId, taskIndex) + .withArgs(taskId) .and.to.not.emit(voucherHub, 'VoucherRefunded'); const { voucherCreditBalance: voucherCreditBalancePostClaim, @@ -753,7 +753,7 @@ describe('Voucher', function () { // Claim await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(dealId, taskIndex) + .withArgs(taskId) .and.to.not.emit(voucherHub, 'VoucherRefunded'); const { voucherCreditBalance: voucherCreditBalancePostClaim, @@ -807,7 +807,7 @@ describe('Voucher', function () { .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(dealId, taskIndex); + .withArgs(taskId); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, @@ -850,7 +850,7 @@ describe('Voucher', function () { .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(dealId, taskIndex); + .withArgs(taskId); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, From 2db1d73bc9e9b7b4747fe852cb311a955d2931cc Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Tue, 28 May 2024 18:33:50 +0200 Subject: [PATCH 08/13] Fix tests --- contracts/mocks/IexecPocoMock.sol | 8 ++++---- test/beacon/Voucher.test.ts | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/contracts/mocks/IexecPocoMock.sol b/contracts/mocks/IexecPocoMock.sol index d1d40a28..062c2649 100644 --- a/contracts/mocks/IexecPocoMock.sol +++ b/contracts/mocks/IexecPocoMock.sol @@ -97,7 +97,7 @@ contract IexecPocoMock is ERC20 { if (shouldRevertOnClaim) { revert("IexecPocoMock: Failed to claim"); } - // This simulates non existent tasks. + // This simulates non existent task/deal. if (taskId != mockTaskId) { revert(); // no reason, same as PoCo. } @@ -105,12 +105,12 @@ contract IexecPocoMock is ERC20 { _mint(deal.sponsor, deal.app.price + deal.dataset.price + deal.workerpool.price); } - function claimBoost(bytes32, uint256 taskIndex) external { + function claimBoost(bytes32 dealId, uint256 taskIndex) external { if (shouldRevertOnClaim) { revert("IexecPocoMock: Failed to claim boost"); } - // This simulates non existent tasks. - if (taskIndex != mockTaskIndex) { + // This simulates non existent task/deal. + if (dealId != mockDealId || taskIndex != mockTaskIndex) { revert("PocoBoost: Unknown task"); // same as PoCo. } task.status = IexecLibCore_v5.TaskStatusEnum.FAILED; diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 07b96508..671b8139 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -873,12 +873,14 @@ describe('Voucher', function () { describe('Should not claim task when deal not found', async () => { it('Classic', async function () { - await expect(voucher.claim(taskId)).to.be.revertedWith('Voucher: deal not found'); + const badTaskId = ethers.randomBytes(32); + await expect(voucher.claim(badTaskId)).to.be.revertedWithoutReason(); }); it('Boost', async function () { - await expect(voucher.claimBoost(dealId, taskIndex)).to.be.revertedWith( - 'Voucher: boost deal not found', + const badDealId = ethers.randomBytes(32); + await expect(voucher.claimBoost(badDealId, taskIndex)).to.be.revertedWith( + 'PocoBoost: Unknown task', ); }); }); From 27f13e0d0998c3ad6ec32b824596a2f59aa6e482 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Wed, 29 May 2024 15:41:11 +0200 Subject: [PATCH 09/13] Update tests --- test/beacon/Voucher.test.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 8838167b..25bfb44b 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -588,7 +588,7 @@ describe('Voucher', function () { .to.be.equal(voucherRlcBalancePreClaim + taskPrice); // Requester balance should stay unchanged. expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); - // Sponsored amount not should decrease + // Sponsored amount should stay unchanged expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); } }); @@ -642,10 +642,8 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal( requesterRlcBalancePreClaim + taskNonSponsoredAmount, ); - // Sponsored amount should decrease - expect(await voucher.getSponsoredAmount(dealId)).to.be.equal( - dealSponsoredAmount - taskSponsoredAmount, - ); + // Sponsored amount should stay unchanged + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); } }); @@ -818,10 +816,8 @@ describe('Voucher', function () { .to.be.equal(voucherRlcBalancePreClaim + taskPrice); // Requester balance should stay unchanged. expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); - // Sponsored amount should decrease - expect(await voucher.getSponsoredAmount(dealId)).to.be.equal( - dealSponsoredAmount - taskSponsoredAmount, - ); + // Sponsored amount should stay unchanged + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); } }); @@ -861,10 +857,12 @@ describe('Voucher', function () { .to.be.equal(voucherRlcBalancePreClaim + taskPrice); // Requester balance should stay unchanged. expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); + // Sponsored amount should stay unchanged + expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); // Second claim should revert. await expect(claimBoostOrClassic()).to.be.revertedWith( - 'Voucher: task already claimed', + 'Voucher: task already refunded', ); } }); From cdd72bf433c8cbfaf485432dc4315db8d4006308 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Wed, 29 May 2024 19:00:19 +0200 Subject: [PATCH 10/13] Fix test --- test/beacon/Voucher.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 45093f22..c4e91c32 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -637,7 +637,7 @@ describe('Voucher', function () { async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) { await addEligibleAssets([app, dataset]); // workerpool not eligible. - const dealNonSponsoredAmount = workerpoolPrice; + const dealNonSponsoredAmount = workerpoolPrice * volume; const taskNonSponsoredAmount = dealNonSponsoredAmount / volume; // Deposit non-sponsored amount for requester and approve voucher. await iexecPocoInstance @@ -685,8 +685,7 @@ describe('Voucher', function () { } }); - // TODO when volume can be > 1 - describe('Should claim task when deal is partially sponsored and sponsored amount is not divisible by volume', async () => { + describe('[TODO] Should claim task when deal is partially sponsored and sponsored amount is not divisible by volume', async () => { it.skip('Classic', async () => await runTest(voucherMatchOrders, claim)); it.skip('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost)); From f6bde9d3b05f4dc269fc4a2c8f158c473f471061 Mon Sep 17 00:00:00 2001 From: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:18:03 +0200 Subject: [PATCH 11/13] Update test/beacon/Voucher.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémy James Toussaint <33313130+jeremyjams@users.noreply.github.com> --- test/beacon/Voucher.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index c4e91c32..7cbf0f63 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -695,9 +695,9 @@ describe('Voucher', function () { voucher = await voucherHubAsVoucherCreationManager .createVoucher(voucherOwner2, voucherType, smallVoucherValue) .then((tx) => tx.wait()) - .then(() => voucherHub.getVoucher(voucherOwner1)) + .then(() => voucherHub.getVoucher(voucherOwner2)) .then((voucherAddress) => - Voucher__factory.connect(voucherAddress, voucherOwner1), + Voucher__factory.connect(voucherAddress, voucherOwner2), ); } }); From 3e93fe96f6d6e01f4251070eaa49844c6f9c8ca8 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:25:09 +0200 Subject: [PATCH 12/13] Remove redundant verifications --- test/beacon/Voucher.test.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 7cbf0f63..023d6f05 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -664,8 +664,7 @@ describe('Voucher', function () { await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') .withArgs(voucherAddress, taskSponsoredAmount) - .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(taskId); + .to.emit(voucher, 'TaskClaimedWithVoucher'); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, @@ -730,7 +729,6 @@ describe('Voucher', function () { // Claim await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(taskId) .and.to.not.emit(voucherHub, 'VoucherRefunded'); const { voucherCreditBalance: voucherCreditBalancePostClaim, @@ -786,7 +784,6 @@ describe('Voucher', function () { // Claim await expect(claimBoostOrClassic()) .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(taskId) .and.to.not.emit(voucherHub, 'VoucherRefunded'); const { voucherCreditBalance: voucherCreditBalancePostClaim, @@ -838,9 +835,7 @@ describe('Voucher', function () { // Claim task on voucher await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') - .withArgs(voucherAddress, taskSponsoredAmount) - .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(taskId); + .to.emit(voucher, 'TaskClaimedWithVoucher'); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, @@ -879,9 +874,7 @@ describe('Voucher', function () { // Claim task await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') - .withArgs(voucherAddress, taskSponsoredAmount) - .to.emit(voucher, 'TaskClaimedWithVoucher') - .withArgs(taskId); + .to.emit(voucher, 'TaskClaimedWithVoucher'); const { voucherCreditBalance: voucherCreditBalancePostClaim, voucherRlcBalance: voucherRlcBalancePostClaim, From 41674c8d411b0de771d273509e5150b90886f5e7 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:46:56 +0200 Subject: [PATCH 13/13] Check task status after poco claim --- test/beacon/Voucher.test.ts | 10 ++++++++-- test/utils/poco-utils.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 023d6f05..7329c17d 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -18,7 +18,7 @@ import { Voucher__factory, } from '../../typechain-types'; import { random } from '../utils/address-utils'; -import { createMockOrder } from '../utils/poco-utils'; +import { TaskStatusEnum, createMockOrder } from '../utils/poco-utils'; const voucherType = 0; const duration = 3600; @@ -628,6 +628,10 @@ describe('Voucher', function () { expect(requesterRlcBalancePostClaim).to.be.equal(requesterRlcBalancePreClaim); // Sponsored amount should stay unchanged expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(dealSponsoredAmount); + // Check task status. + expect((await iexecPocoInstance.viewTask(taskId)).status).to.equal( + TaskStatusEnum.FAILED, + ); } }); @@ -832,6 +836,9 @@ describe('Voucher', function () { // Claim task on PoCo. await pocoClaimBoostOrClassic(); + expect((await iexecPocoInstance.viewTask(taskId)).status).to.equal( + TaskStatusEnum.FAILED, + ); // Claim task on voucher await expect(claimBoostOrClassic()) .to.emit(voucherHub, 'VoucherRefunded') @@ -924,7 +931,6 @@ describe('Voucher', function () { [dealId, badTaskIndex], ), ); - // await expect(iexecPocoInstance.claim(badTaskId)).to.be.revertedWithoutReason(); await expect(voucher.claim(badTaskId)).to.be.revertedWithoutReason(); }); diff --git a/test/utils/poco-utils.ts b/test/utils/poco-utils.ts index 5fc5fb1a..bcb30145 100644 --- a/test/utils/poco-utils.ts +++ b/test/utils/poco-utils.ts @@ -3,6 +3,14 @@ import { ethers } from 'hardhat'; +export enum TaskStatusEnum { + UNSET, + ACTIVE, + REVEALING, + COMPLETED, + FAILED, +} + export function createMockOrder() { return { app: ethers.ZeroAddress,