Skip to content

Commit 92e3cd0

Browse files
authored
Test coverage back to 100% (#69)
* add test for token that reverts but doesn't return any data * back to 100% coverage
1 parent a87a61a commit 92e3cd0

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

test/src/PaymentEscrow/capture.t.sol

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {PaymentEscrow} from "../../../src/PaymentEscrow.sol";
77
import {MockRevertOnTransferToken} from "../../mocks/MockRevertOnTransferToken.sol";
88
import {MockFailOnTransferToken} from "../../mocks/MockFailOnTransferToken.sol";
99
import {PaymentEscrowBase} from "../../base/PaymentEscrowBase.sol";
10+
import {MockERC3009Token} from "../../mocks/MockERC3009Token.sol";
1011

1112
contract CaptureTest is PaymentEscrowBase {
1213
function test_reverts_whenNotOperator(uint120 authorizedAmount, address sender) public {
@@ -335,7 +336,9 @@ contract CaptureTest is PaymentEscrowBase {
335336
paymentEscrow.capture(paymentInfo, authorizedAmount, captureFeeBps, invalidFeeReceiver);
336337
}
337338

338-
function test_reverts_ifSendTokensReverts(uint120 authorizedAmount, bytes calldata revertData) public {
339+
function test_reverts_ifSendTokensReverts_undeployedTokenStore(uint120 authorizedAmount, bytes calldata revertData)
340+
public
341+
{
339342
vm.assume(authorizedAmount > 0);
340343
address revertingToken =
341344
address(new MockRevertOnTransferToken(address(preApprovalPaymentCollector), revertData));
@@ -357,6 +360,45 @@ contract CaptureTest is PaymentEscrowBase {
357360
vm.stopPrank();
358361
}
359362

363+
function test_reverts_ifSendTokensReverts_deployedTokenStore(uint120 authorizedAmount, bytes calldata revertData)
364+
public
365+
{
366+
vm.assume(authorizedAmount > 0);
367+
// process a payment first to make sure the token store is deployed
368+
PaymentEscrow.PaymentInfo memory initialPaymentInfo = _createPaymentInfo(payerEOA, authorizedAmount);
369+
bytes memory initialSignature = _signERC3009ReceiveWithAuthorizationStruct(initialPaymentInfo, payer_EOA_PK);
370+
mockERC3009Token.mint(payerEOA, authorizedAmount);
371+
vm.prank(initialPaymentInfo.operator);
372+
paymentEscrow.charge(
373+
initialPaymentInfo,
374+
authorizedAmount,
375+
address(erc3009PaymentCollector),
376+
initialSignature,
377+
initialPaymentInfo.minFeeBps,
378+
initialPaymentInfo.feeReceiver
379+
);
380+
381+
// create a new token that reverts on transfer
382+
address revertingToken =
383+
address(new MockRevertOnTransferToken(address(preApprovalPaymentCollector), revertData));
384+
MockRevertOnTransferToken(revertingToken).mint(payerEOA, authorizedAmount);
385+
386+
PaymentEscrow.PaymentInfo memory paymentInfo = _createPaymentInfo(payerEOA, authorizedAmount);
387+
paymentInfo.token = revertingToken;
388+
389+
vm.prank(payerEOA);
390+
MockRevertOnTransferToken(revertingToken).approve(address(preApprovalPaymentCollector), authorizedAmount);
391+
vm.prank(payerEOA);
392+
preApprovalPaymentCollector.preApprove(paymentInfo);
393+
394+
vm.startPrank(paymentInfo.operator);
395+
paymentEscrow.authorize(paymentInfo, authorizedAmount, address(preApprovalPaymentCollector), "");
396+
397+
vm.expectRevert(abi.encodeWithSelector(MockRevertOnTransferToken.CustomRevert.selector, revertData));
398+
paymentEscrow.capture(paymentInfo, authorizedAmount, paymentInfo.minFeeBps, paymentInfo.feeReceiver);
399+
vm.stopPrank();
400+
}
401+
360402
function test_reverts_ifSendTokensFails(uint120 authorizedAmount) public {
361403
vm.assume(authorizedAmount > 0);
362404
address revertingToken = address(new MockFailOnTransferToken(address(preApprovalPaymentCollector)));

0 commit comments

Comments
 (0)