From 783f99de22a78f393a9a2a060538fd90dcf63fdc Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 29 May 2024 11:41:16 +0200 Subject: [PATCH] add test to matchOrders onlyAuthorized onlyNotExpired --- test/beacon/Voucher.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/beacon/Voucher.test.ts b/test/beacon/Voucher.test.ts index 8bd4d67..7c6a4b0 100644 --- a/test/beacon/Voucher.test.ts +++ b/test/beacon/Voucher.test.ts @@ -326,6 +326,30 @@ describe('Voucher', function () { expect(await voucher.getSponsoredAmount(dealId)).to.be.equal(0); }); + it('Should match orders with an authorized account', async () => { + await addEligibleAssets([app, dataset, workerpool]); + await voucherAsOwner.authorizeAccount(anyone.address).then((tx) => tx.wait()); + await expect( + voucherAsAnyone.matchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder), + ) + .to.emit(voucher, 'OrdersMatchedWithVoucher') + .withArgs(dealId); + }); + + it('Should not match orders when sender is not allowed', async () => { + await expect( + voucherAsAnyone.matchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder), + ).to.be.revertedWith('Voucher: sender is not authorized'); + }); + + it('Should not match orders when voucher is expired', async () => { + const expirationDate = await voucher.getExpiration(); + await time.setNextBlockTimestamp(expirationDate); + await expect( + voucherAsOwner.matchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder), + ).to.be.revertedWith('Voucher: voucher is expired'); + }); + it('Should not match orders when non-sponsored amount is not transferable', async () => { await expect(voucher.matchOrders(appOrder, datasetOrder, workerpoolOrder, requestOrder)) .to.be.revertedWithCustomError(iexecPocoInstance, 'ERC20InsufficientAllowance')