Skip to content

Commit 4102e9e

Browse files
f - refactor recurring collector test
1 parent 8b28b5d commit 4102e9e

File tree

7 files changed

+745
-653
lines changed

7 files changed

+745
-653
lines changed

packages/horizon/test/payments/recurring-collector/RecurringCollector.t.sol

-652
This file was deleted.

packages/horizon/test/payments/recurring-collector/RecurringCollectorHelper.t.sol

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ pragma solidity 0.8.27;
44
import { IRecurringCollector } from "../../../contracts/interfaces/IRecurringCollector.sol";
55
import { RecurringCollector } from "../../../contracts/payments/collectors/RecurringCollector.sol";
66
import { AuthorizableHelper } from "../../utilities/Authorizable.t.sol";
7+
import { Bounder } from "../../utils/Bounder.t.sol";
78

8-
contract RecurringCollectorHelper is AuthorizableHelper {
9+
contract RecurringCollectorHelper is AuthorizableHelper, Bounder {
910
RecurringCollector public collector;
1011

1112
constructor(
@@ -43,4 +44,19 @@ contract RecurringCollectorHelper is AuthorizableHelper {
4344

4445
return signedRCAU;
4546
}
47+
48+
function withElapsedAcceptDeadline(
49+
IRecurringCollector.RecurringCollectionAgreement memory rca
50+
) public view returns (IRecurringCollector.RecurringCollectionAgreement memory) {
51+
require(block.timestamp > 0, "block.timestamp can't be zero");
52+
rca.acceptDeadline = bound(rca.acceptDeadline, 0, block.timestamp - 1);
53+
return rca;
54+
}
55+
56+
function withOKAcceptDeadline(
57+
IRecurringCollector.RecurringCollectionAgreement memory rca
58+
) public view returns (IRecurringCollector.RecurringCollectionAgreement memory) {
59+
rca.acceptDeadline = boundTimestampMin(rca.acceptDeadline, block.timestamp);
60+
return rca;
61+
}
4662
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.27;
3+
4+
import { IRecurringCollector } from "../../../contracts/interfaces/IRecurringCollector.sol";
5+
6+
import { RecurringCollectorSharedTest } from "./shared.t.sol";
7+
8+
contract RecurringCollectorAcceptTest is RecurringCollectorSharedTest {
9+
/*
10+
* TESTS
11+
*/
12+
13+
/* solhint-disable graph/func-name-mixedcase */
14+
15+
function test_Accept(FuzzyAcceptableRCA memory fuzzyAcceptableRCA) public {
16+
_fuzzyAuthorizeAndAccept(fuzzyAcceptableRCA);
17+
}
18+
19+
function test_Accept_Revert_WhenAcceptanceDeadlineElapsed(
20+
IRecurringCollector.SignedRCA memory fuzzySignedRCA,
21+
uint256 unboundedSkip
22+
) public {
23+
skip(boundSkipFloor(unboundedSkip, 1));
24+
fuzzySignedRCA.rca = _recurringCollectorHelper.withElapsedAcceptDeadline(fuzzySignedRCA.rca);
25+
26+
bytes memory expectedErr = abi.encodeWithSelector(
27+
IRecurringCollector.RecurringCollectorAgreementAcceptanceElapsed.selector,
28+
fuzzySignedRCA.rca.acceptDeadline
29+
);
30+
vm.expectRevert(expectedErr);
31+
vm.prank(fuzzySignedRCA.rca.dataService);
32+
_recurringCollector.accept(fuzzySignedRCA);
33+
}
34+
35+
function test_Accept_Revert_WhenAlreadyAccepted(FuzzyAcceptableRCA memory fuzzyAcceptableRCA) public {
36+
IRecurringCollector.SignedRCA memory signedRCA = _fuzzyAuthorizeAndAccept(fuzzyAcceptableRCA);
37+
38+
bytes memory expectedErr = abi.encodeWithSelector(
39+
IRecurringCollector.RecurringCollectorAgreementAlreadyAccepted.selector,
40+
signedRCA.rca.agreementId
41+
);
42+
vm.expectRevert(expectedErr);
43+
vm.prank(signedRCA.rca.dataService);
44+
_recurringCollector.accept(signedRCA);
45+
}
46+
47+
/* solhint-enable graph/func-name-mixedcase */
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.27;
3+
4+
import { IRecurringCollector } from "../../../contracts/interfaces/IRecurringCollector.sol";
5+
6+
import { RecurringCollectorSharedTest } from "./shared.t.sol";
7+
8+
contract RecurringCollectorCancelTest is RecurringCollectorSharedTest {
9+
/*
10+
* TESTS
11+
*/
12+
13+
/* solhint-disable graph/func-name-mixedcase */
14+
15+
function test_Cancel(FuzzyAcceptableRCA memory fuzzyAcceptableRCA) public {
16+
_fuzzyAuthorizeAndAccept(fuzzyAcceptableRCA);
17+
_cancel(fuzzyAcceptableRCA.rca);
18+
}
19+
20+
function test_Cancel_Revert_WhenNotAccepted(
21+
IRecurringCollector.RecurringCollectionAgreement memory fuzzyRCA
22+
) public {
23+
bytes memory expectedErr = abi.encodeWithSelector(
24+
IRecurringCollector.RecurringCollectorAgreementNeverAccepted.selector,
25+
fuzzyRCA.agreementId
26+
);
27+
vm.expectRevert(expectedErr);
28+
vm.prank(fuzzyRCA.dataService);
29+
_recurringCollector.cancel(fuzzyRCA.agreementId);
30+
}
31+
32+
function test_Cancel_Revert_WhenNotDataService(
33+
FuzzyAcceptableRCA memory fuzzyAcceptableRCA,
34+
address notDataService
35+
) public {
36+
vm.assume(fuzzyAcceptableRCA.rca.dataService != notDataService);
37+
38+
_fuzzyAuthorizeAndAccept(fuzzyAcceptableRCA);
39+
40+
bytes memory expectedErr = abi.encodeWithSelector(
41+
IRecurringCollector.RecurringCollectorDataServiceNotAuthorized.selector,
42+
fuzzyAcceptableRCA.rca.agreementId,
43+
notDataService
44+
);
45+
vm.expectRevert(expectedErr);
46+
vm.prank(notDataService);
47+
_recurringCollector.cancel(fuzzyAcceptableRCA.rca.agreementId);
48+
}
49+
/* solhint-enable graph/func-name-mixedcase */
50+
}

0 commit comments

Comments
 (0)