From 5840dba479c389056886c916c4ab179aa5487d2e Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:21:39 +0200 Subject: [PATCH] Add partial sponsoring test --- test/beacon/Voucher.test.ts | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index daa9c8b..f6a6f12 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -330,6 +330,49 @@ describe('Voucher', function () { expect(await voucherAsOwner.getSponsoredAmount(dealId)).to.be.equal(dealPrice); }); + it('Should match orders with partial sponsored amount', async () => { + await addEligibleAssets([app, dataset]); // not workerpool. + // Deposit non-sponsored amount in requester's account and approve voucher. + const dealSponsoredAmount = (appPrice + datasetPrice) * volume; + const dealNonSponsoredAmount = dealPrice - dealSponsoredAmount; + await iexecPocoInstance + .transfer(requester, dealSponsoredAmount) + .then((tx) => tx.wait()); + // Allow voucher to spend non-sponsored amount. + await iexecPocoInstance + .connect(requester) + .approve(voucherAddress, dealPrice) + .then((tx) => tx.wait()); + // Save initial balances. + const voucherInitialCreditBalance = await voucherAsOwner.getBalance(); + const voucherInitialRlcBalance = await getVoucherBalanceOnIexecPoco(); + const requesterInitialRlcBalance = await getRequesterBalanceOnIexecPoco(); + + expect( + await voucherAsOwner.matchOrders.staticCall( + appOrder, + datasetOrder, + workerpoolOrder, + requestOrder, + ), + ).to.be.equal(dealId); + await expect( + voucherAsOwner.matchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder), + ) + .to.emit(voucherAsOwner, 'OrdersMatchedWithVoucher') + .withArgs(dealId); + expect(await voucherAsOwner.getSponsoredAmount(dealId)).to.be.equal( + dealSponsoredAmount, + ); + expect(await voucherAsOwner.getBalance()) + .to.be.equal(voucherInitialCreditBalance - dealSponsoredAmount) + .to.be.equal(await getVoucherBalanceOnIexecPoco()) + .to.be.equal(voucherInitialRlcBalance - dealSponsoredAmount); + expect(await getRequesterBalanceOnIexecPoco()).to.be.equal( + requesterInitialRlcBalance - dealNonSponsoredAmount, + ); + }); + it('Should match orders with full non-sponsored amount', async () => { const voucherInitialCreditBalance = await voucherAsOwner.getBalance(); const voucherInitialSrlcBalance = await getVoucherBalanceOnIexecPoco(); @@ -383,10 +426,6 @@ describe('Voucher', function () { ).to.be.revertedWith('Voucher: voucher is expired'); }); - it('TODO - Should match orders with partial sponsored amount', async () => { - // TODO - }); - it('Should match orders without dataset', async () => { const mockOrder = createMockOrder(); const appOrder = { ...mockOrder, app: app, appprice: appPrice, volume: volume };