Skip to content

Commit

Permalink
check erc transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
gfournieriExec committed Jun 10, 2024
1 parent 5efcfc4 commit 147329d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
19 changes: 13 additions & 6 deletions contracts/beacon/Voucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ contract Voucher is Initializable, IVoucher {
// If the deal was not sponsored or partially sponsored
// by the voucher then send the non-sponsored part back
// to the requester.
IERC20(iexecPoco).transfer(requester, taskPrice - taskSponsoredAmount);
if (!IERC20(iexecPoco).transfer(requester, taskPrice - taskSponsoredAmount)) {
revert("Voucher: transfer to requester failed");
}
}
}
}
Expand Down Expand Up @@ -432,11 +434,16 @@ contract Voucher is Initializable, IVoucher {
if (sponsoredAmount != dealPrice) {
// Transfer non-sponsored amount from the iExec account of the
// requester to the iExec account of the voucher
IERC20(iexecPoco).transferFrom(
requestOrder.requester,
address(this),
dealPrice - sponsoredAmount
);
if (
!IERC20(iexecPoco).transferFrom(
requestOrder.requester,
address(this),
dealPrice - sponsoredAmount
)
) {
// SRLC
revert("Voucher: Transfer of non-sponsored amount failed");
}
}
}
}
44 changes: 44 additions & 0 deletions test/beacon/Voucher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,28 @@ describe('Voucher', function () {
),
).to.be.revertedWith('IexecPocoMock: Failed to sponsorMatchOrdersBoost');
});

it('Should not match orders boost when SRLC transfer fails', async () => {
const noSponsoredValue = appPrice * volume;
await addEligibleAssets([dataset, workerpool]);
await iexecPocoInstance
.transfer(requester, noSponsoredValue)
.then((tx) => tx.wait());

await iexecPocoInstance
.connect(requester)
.approve(await voucherAsOwner.getAddress(), noSponsoredValue)
.then((tx) => tx.wait());
await iexecPocoInstance.willRevertOnTransferFrom().then((tx) => tx.wait());
await expect(
voucherAsOwner.matchOrdersBoost(
appOrder,
datasetOrder,
workerpoolOrder,
requestOrder,
),
).to.be.revertedWith('Voucher: Transfer of non-sponsored amount failed');
});
});
});

Expand Down Expand Up @@ -1049,6 +1071,28 @@ describe('Voucher', function () {
);
});
});
describe('Should not claim task when SLRC transfer fails', async () => {
it('Classic', async () => await runTest(voucherMatchOrders, claim));
it('Boost', async () => await runTest(voucherMatchOrdersBoost, claimBoost));

async function runTest(matchOrdersBoostOrClassic: any, claimBoostOrClassic: any) {
await addEligibleAssets([app, dataset]); // workerpool not eligible.
const dealNonSponsoredAmount = workerpoolPrice * 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());
await matchOrdersBoostOrClassic();
await iexecPocoInstance.willRevertOnTransfer().then((tx) => tx.wait());
await expect(claimBoostOrClassic()).to.be.revertedWith(
'Voucher: transfer to requester failed',
);
}
});
});

async function addEligibleAssets(assets: string[]) {
Expand Down

0 comments on commit 147329d

Please sign in to comment.