Skip to content

Commit

Permalink
Add partial sponsoring test
Browse files Browse the repository at this point in the history
  • Loading branch information
zguesmi committed Jun 10, 2024
1 parent a8bde54 commit 5840dba
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions test/beacon/Voucher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit 5840dba

Please sign in to comment.