@gatedpath/receptor-mock 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {EligibilityStatus, IRedbellyVerifier} from "../IRedbellyVerifier.sol";
5
+
6
+ /// @notice The read function exposed by `@iden3/contracts` 1.x `ZKPVerifier` (read at 1.4.8):
7
+ /// the public mapping `proofs[sender][requestId]`. This is the shape the Redbelly docs example
8
+ /// (`docs.redbelly.network/pages/methods/proof-by-query/contract-example/`) is written against.
9
+ interface IIden3ZKPVerifierV1 {
10
+ function proofs(address sender, uint64 requestId) external view returns (bool);
11
+ }
12
+
13
+ /// @notice The read function exposed by `@iden3/contracts` 2.x `ZKPVerifierBase`,
14
+ /// `EmbeddedZKPVerifier` and `UniversalVerifier` through `IZKPVerifier` (read at 2.5.0).
15
+ /// Reverts when the request id was never set.
16
+ interface IIden3ZKPVerifierV2 {
17
+ function isProofVerified(address sender, uint64 requestId) external view returns (bool);
18
+ }
19
+
20
+ /// @notice The read function exposed by `@iden3/contracts` 3.x `Verifier`, `EmbeddedVerifier`
21
+ /// and `UniversalVerifier` through `IVerifier` (read at 3.4.0, the npm `latest`, and at master
22
+ /// commit 610249b of 15 June 2026). Request ids widened to `uint256`. Reverts when the request
23
+ /// id was never set.
24
+ interface IIden3VerifierV3 {
25
+ function isRequestProofVerified(address sender, uint256 requestId) external view returns (bool);
26
+ }
27
+
28
+ /// @title Iden3VerifierAdapter
29
+ /// @notice Presents a deployed Iden3 verifier-family contract as an `IRedbellyVerifier`.
30
+ /// @dev The Iden3 packages pin `pragma solidity 0.8.27` exactly, so they cannot be imported into
31
+ /// a 0.8.30 build; the three interfaces above restate only the one read function each release
32
+ /// exposes. Pick the `Surface` that matches the release the target was compiled from. A revert
33
+ /// from the target (2.x and 3.x revert for an unknown request id) reads as not eligible: a
34
+ /// request that was never set admits nobody. The target must have code: a call to an empty
35
+ /// address would return no data, and a return-data decoding failure is not caught by `try`.
36
+ contract Iden3VerifierAdapter is IRedbellyVerifier {
37
+ /// @notice Which `@iden3/contracts` release line the target exposes.
38
+ enum Surface {
39
+ ZKPVerifierV1,
40
+ ZKPVerifierV2,
41
+ VerifierV3
42
+ }
43
+
44
+ /// @notice Thrown when the target has no code.
45
+ error TargetHasNoCode(address target);
46
+
47
+ /// @notice The Iden3 verifier being adapted.
48
+ address public immutable target;
49
+
50
+ /// @notice The release line the target exposes.
51
+ Surface public immutable surface;
52
+
53
+ /// @param target_ A deployed Iden3 verifier-family contract.
54
+ /// @param surface_ The release line it was compiled from.
55
+ constructor(address target_, Surface surface_) {
56
+ if (target_.code.length == 0) revert TargetHasNoCode(target_);
57
+ target = target_;
58
+ surface = surface_;
59
+ }
60
+
61
+ /// @inheritdoc IRedbellyVerifier
62
+ function isEligible(address wallet, uint64 requestId) public view returns (bool) {
63
+ if (surface == Surface.ZKPVerifierV1) {
64
+ try IIden3ZKPVerifierV1(target).proofs(wallet, requestId) returns (bool verified) {
65
+ return verified;
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+ if (surface == Surface.ZKPVerifierV2) {
71
+ try IIden3ZKPVerifierV2(target).isProofVerified(wallet, requestId) returns (bool verified) {
72
+ return verified;
73
+ } catch {
74
+ return false;
75
+ }
76
+ }
77
+ try IIden3VerifierV3(target).isRequestProofVerified(wallet, uint256(requestId)) returns (bool verified) {
78
+ return verified;
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ /// @inheritdoc IRedbellyVerifier
85
+ /// @dev A real verifier only knows accepted or not, so this returns `Valid` or `NeverIssued`.
86
+ function eligibilityStatus(address wallet, uint64 requestId) external view returns (EligibilityStatus) {
87
+ return isEligible(wallet, requestId) ? EligibilityStatus.Valid : EligibilityStatus.NeverIssued;
88
+ }
89
+ }
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {EligibilityStatus, IRedbellyVerifier} from "../IRedbellyVerifier.sol";
5
+
6
+ /// @notice The per-wallet getter a `VCVerifierBaseContract` child exposes when it follows
7
+ /// Redbelly's archived example (`github.com/redbellynetwork/receptor-verifier-contract-example`,
8
+ /// `src/AvererVerifierContract.sol`, commit 07c9849 of 7 April 2025): the child declares
9
+ /// `mapping(address => bool) public verificationStatus` and sets it in `_postVerification`.
10
+ /// The example's deployment at 0x5c414F9243588750E4BB1Ec181270ad42A0b791F on chain 153 answers
11
+ /// this selector (0xadafb3d4) and returns true for the wallet in the example's sample credential
12
+ /// (read 2026-09-12).
13
+ interface IVCVerifierChild {
14
+ function verificationStatus(address wallet) external view returns (bool);
15
+ }
16
+
17
+ /// @title VCVerifierAdapter
18
+ /// @notice Presents a `VCVerifierBaseContract` child as an `IRedbellyVerifier`.
19
+ /// @dev Coded against the child's `verificationStatus(address)` getter, the only per-wallet read
20
+ /// that is verifiable from a public source. The base contract itself ships in the GitHub Packages
21
+ /// npm package `receptor-standardvc-sc` under the redbellynetwork scope, which refuses unauthenticated
22
+ /// reads, so its own ABI is **verify**: from the example we know `verifyCredential(string issuerDid,
23
+ /// string canonicalVc, string canonicalProof)` is the external entry point and
24
+ /// `_postVerification(address)` the internal hook, and the deployed example also answers the
25
+ /// `credentialType()` selector; nothing else about the base is confirmed. A child that records
26
+ /// verification under a different name needs its own adapter.
27
+ ///
28
+ /// The standard-VC path has no request id: one verifier contract checks one credential type,
29
+ /// fixed at construction. `requestId` is therefore ignored; deploy one adapter per verifier.
30
+ /// The target must have code for the same reason as in `Iden3VerifierAdapter`.
31
+ contract VCVerifierAdapter is IRedbellyVerifier {
32
+ /// @notice Thrown when the target has no code.
33
+ error TargetHasNoCode(address target);
34
+
35
+ /// @notice The `VCVerifierBaseContract` child being adapted.
36
+ address public immutable target;
37
+
38
+ /// @param target_ A deployed `VCVerifierBaseContract` child exposing `verificationStatus(address)`.
39
+ constructor(address target_) {
40
+ if (target_.code.length == 0) revert TargetHasNoCode(target_);
41
+ target = target_;
42
+ }
43
+
44
+ /// @inheritdoc IRedbellyVerifier
45
+ /// @dev `requestId` is ignored; see the contract notes.
46
+ function isEligible(
47
+ address wallet,
48
+ uint64 /* requestId */
49
+ )
50
+ public
51
+ view
52
+ returns (bool)
53
+ {
54
+ try IVCVerifierChild(target).verificationStatus(wallet) returns (bool verified) {
55
+ return verified;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+
61
+ /// @inheritdoc IRedbellyVerifier
62
+ /// @dev A real verifier only knows accepted or not, so this returns `Valid` or `NeverIssued`.
63
+ function eligibilityStatus(address wallet, uint64 requestId) external view returns (EligibilityStatus) {
64
+ return isEligible(wallet, requestId) ? EligibilityStatus.Valid : EligibilityStatus.NeverIssued;
65
+ }
66
+ }
@@ -0,0 +1,146 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {GatedTest} from "./GatedTest.sol";
5
+ import {GatedCounter} from "./examples/GatedCounter.sol";
6
+ import {FakeIden3V1, FakeIden3V2, FakeIden3V3} from "./fakes/FakeIden3Verifiers.sol";
7
+ import {FakeVCVerifierChild, RevertingTarget} from "./fakes/FakeVCVerifierChild.sol";
8
+ import {Gated} from "../src/Gated.sol";
9
+ import {EligibilityStatus} from "../src/IRedbellyVerifier.sol";
10
+ import {Iden3VerifierAdapter} from "../src/adapters/Iden3VerifierAdapter.sol";
11
+ import {VCVerifierAdapter} from "../src/adapters/VCVerifierAdapter.sol";
12
+
13
+ contract AdaptersTest is GatedTest {
14
+ uint64 internal constant REQUEST_ID = 26;
15
+ address internal alice = makeAddr("alice");
16
+ address internal bob = makeAddr("bob");
17
+
18
+ function setUp() public {
19
+ _deployMock();
20
+ }
21
+
22
+ function _assertStatusIsValidOrNeverIssued(Iden3VerifierAdapter adapter, address wallet) internal view {
23
+ EligibilityStatus s = adapter.eligibilityStatus(wallet, REQUEST_ID);
24
+ assertTrue(
25
+ s == EligibilityStatus.Valid || s == EligibilityStatus.NeverIssued,
26
+ "adapters report Valid or NeverIssued only"
27
+ );
28
+ assertEq(s == EligibilityStatus.Valid, adapter.isEligible(wallet, REQUEST_ID));
29
+ }
30
+
31
+ function test_iden3V1MapsProofsMapping() public {
32
+ FakeIden3V1 fake = new FakeIden3V1();
33
+ Iden3VerifierAdapter adapter =
34
+ new Iden3VerifierAdapter(address(fake), Iden3VerifierAdapter.Surface.ZKPVerifierV1);
35
+ assertEq(adapter.target(), address(fake));
36
+ assertEq(uint8(adapter.surface()), uint8(Iden3VerifierAdapter.Surface.ZKPVerifierV1));
37
+
38
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
39
+ fake.setProof(alice, REQUEST_ID, true);
40
+ assertTrue(adapter.isEligible(alice, REQUEST_ID));
41
+ assertFalse(adapter.isEligible(alice, REQUEST_ID + 1), "request ids are distinct");
42
+ assertFalse(adapter.isEligible(bob, REQUEST_ID));
43
+ _assertStatusIsValidOrNeverIssued(adapter, alice);
44
+ _assertStatusIsValidOrNeverIssued(adapter, bob);
45
+
46
+ fake.setProof(alice, REQUEST_ID, false);
47
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
48
+ }
49
+
50
+ function test_iden3V2MapsIsProofVerifiedAndUnknownRequestIsFalse() public {
51
+ FakeIden3V2 fake = new FakeIden3V2();
52
+ Iden3VerifierAdapter adapter =
53
+ new Iden3VerifierAdapter(address(fake), Iden3VerifierAdapter.Surface.ZKPVerifierV2);
54
+
55
+ // Request not set: the real contract reverts; the adapter reads that as not eligible.
56
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
57
+ assertEq(uint8(adapter.eligibilityStatus(alice, REQUEST_ID)), uint8(EligibilityStatus.NeverIssued));
58
+
59
+ fake.setRequest(REQUEST_ID);
60
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
61
+ fake.setProof(alice, REQUEST_ID, true);
62
+ assertTrue(adapter.isEligible(alice, REQUEST_ID));
63
+ assertEq(uint8(adapter.eligibilityStatus(alice, REQUEST_ID)), uint8(EligibilityStatus.Valid));
64
+ assertFalse(adapter.isEligible(bob, REQUEST_ID));
65
+ }
66
+
67
+ function test_iden3V3WidensRequestIdAndUnknownRequestIsFalse() public {
68
+ FakeIden3V3 fake = new FakeIden3V3();
69
+ Iden3VerifierAdapter adapter = new Iden3VerifierAdapter(address(fake), Iden3VerifierAdapter.Surface.VerifierV3);
70
+
71
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
72
+ fake.setRequest(uint256(REQUEST_ID));
73
+ fake.setProof(alice, uint256(REQUEST_ID), true);
74
+ assertTrue(adapter.isEligible(alice, REQUEST_ID));
75
+ assertFalse(adapter.isEligible(alice, REQUEST_ID + 1));
76
+ _assertStatusIsValidOrNeverIssued(adapter, alice);
77
+ }
78
+
79
+ function test_iden3WrongSurfaceIsDeniedNotPassed() public {
80
+ // Pointing a V2 adapter at a V1 contract: the selector is unknown, the call reverts, nobody
81
+ // gets through. Misconfiguration fails closed.
82
+ FakeIden3V1 fake = new FakeIden3V1();
83
+ fake.setProof(alice, REQUEST_ID, true);
84
+ Iden3VerifierAdapter adapter =
85
+ new Iden3VerifierAdapter(address(fake), Iden3VerifierAdapter.Surface.ZKPVerifierV2);
86
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
87
+ }
88
+
89
+ function test_iden3AdapterRejectsTargetWithoutCode() public {
90
+ address empty = makeAddr("empty");
91
+ vm.expectRevert(abi.encodeWithSelector(Iden3VerifierAdapter.TargetHasNoCode.selector, empty));
92
+ new Iden3VerifierAdapter(empty, Iden3VerifierAdapter.Surface.ZKPVerifierV2);
93
+ }
94
+
95
+ function test_vcAdapterMapsVerificationStatus() public {
96
+ FakeVCVerifierChild fake = new FakeVCVerifierChild("OptimaV1Credential");
97
+ VCVerifierAdapter adapter = new VCVerifierAdapter(address(fake));
98
+ assertEq(adapter.target(), address(fake));
99
+
100
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
101
+ assertEq(uint8(adapter.eligibilityStatus(alice, REQUEST_ID)), uint8(EligibilityStatus.NeverIssued));
102
+
103
+ vm.prank(alice);
104
+ fake.verifyCredential("did:key:z...", "{}", "{}");
105
+ assertTrue(adapter.isEligible(alice, REQUEST_ID));
106
+ assertTrue(adapter.isEligible(alice, 0), "request id is ignored on the VC path");
107
+ assertEq(uint8(adapter.eligibilityStatus(alice, REQUEST_ID)), uint8(EligibilityStatus.Valid));
108
+ assertFalse(adapter.isEligible(bob, REQUEST_ID));
109
+
110
+ fake.revoke(alice);
111
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
112
+ }
113
+
114
+ function test_vcAdapterRevertingTargetIsDenied() public {
115
+ RevertingTarget bad = new RevertingTarget();
116
+ VCVerifierAdapter adapter = new VCVerifierAdapter(address(bad));
117
+ assertFalse(adapter.isEligible(alice, REQUEST_ID));
118
+ }
119
+
120
+ function test_vcAdapterRejectsTargetWithoutCode() public {
121
+ address empty = makeAddr("empty");
122
+ vm.expectRevert(abi.encodeWithSelector(VCVerifierAdapter.TargetHasNoCode.selector, empty));
123
+ new VCVerifierAdapter(empty);
124
+ }
125
+
126
+ function test_swapMockForAdapterBehindGated() public {
127
+ // Develop against the mock, then repoint the same contract at a real-shaped verifier.
128
+ GatedCounter counter = new GatedCounter(mock, REQUEST_ID);
129
+ assertRevertsForAllInvalidStates(address(counter), abi.encodeCall(counter.increment, ()), alice, REQUEST_ID);
130
+
131
+ FakeIden3V2 fake = new FakeIden3V2();
132
+ fake.setRequest(REQUEST_ID);
133
+ Iden3VerifierAdapter adapter =
134
+ new Iden3VerifierAdapter(address(fake), Iden3VerifierAdapter.Surface.ZKPVerifierV2);
135
+ counter.setVerifier(adapter);
136
+
137
+ vm.prank(alice);
138
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, alice, REQUEST_ID));
139
+ counter.increment();
140
+
141
+ fake.setProof(alice, REQUEST_ID, true);
142
+ vm.prank(alice);
143
+ counter.increment();
144
+ assertEq(counter.count(), 2);
145
+ }
146
+ }
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {GatedTest} from "./GatedTest.sol";
5
+ import {GatedCounter} from "./examples/GatedCounter.sol";
6
+
7
+ /// @dev Interfaces of two Redbelly system contracts, from `packages/chain-definitions` (verified
8
+ /// 2026-09-12): the bootstrap registry's `getContractAddress(string)` and the permission
9
+ /// contract's `isAllowed(address)`.
10
+ interface IBootstrapRegistry {
11
+ function getContractAddress(string calldata name) external view returns (address);
12
+ }
13
+
14
+ interface IPermission {
15
+ function isAllowed(address account) external view returns (bool);
16
+ }
17
+
18
+ /// @title ForkTest
19
+ /// @notice Runs only under `forge test --fork-url https://governors.testnet.redbelly.network`.
20
+ /// Without a fork every test here is skipped. Reads only; nothing is signed or sent.
21
+ contract ForkTest is GatedTest {
22
+ uint256 internal constant REDBELLY_TESTNET = 153;
23
+
24
+ /// @dev Same address on 151 and 153; has code from block 0 (RESEARCH.md, 2026-09-12).
25
+ address internal constant BOOTSTRAP_REGISTRY = 0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5;
26
+
27
+ /// @dev Third-party wallet that `isAllowed` returned true for on 2026-09-12 (chain-definitions
28
+ /// `knownAllowed`). It may stop being allowed; the test says so if it does.
29
+ address internal constant KNOWN_ALLOWED = 0xA2c6a3fC1E12dF79B9e3D099FaA2Ffe860450F76;
30
+
31
+ uint64 internal constant REQUEST_ID = 108;
32
+ address internal alice = makeAddr("alice");
33
+
34
+ function setUp() public {
35
+ vm.skip(block.chainid != REDBELLY_TESTNET);
36
+ _deployMock();
37
+ }
38
+
39
+ function test_fork_registryResolvesPermissionAndIsAllowedAnswers() public view {
40
+ assertGt(BOOTSTRAP_REGISTRY.code.length, 0, "registry has code");
41
+ address permission = IBootstrapRegistry(BOOTSTRAP_REGISTRY).getContractAddress("permission");
42
+ assertTrue(permission != address(0), "registry names a permission contract");
43
+ assertGt(permission.code.length, 0, "permission contract has code");
44
+
45
+ assertFalse(IPermission(permission).isAllowed(address(0)), "zero address is never allowed");
46
+ assertTrue(
47
+ IPermission(permission).isAllowed(KNOWN_ALLOWED),
48
+ "known allowed wallet no longer passes isAllowed; update chain-definitions knownAllowed"
49
+ );
50
+ }
51
+
52
+ function test_fork_fiveStatesAgainstRealChainState() public {
53
+ // Prague bytecode compiled here runs against the forked chain's state.
54
+ GatedCounter counter = new GatedCounter(mock, REQUEST_ID);
55
+ assertRevertsForAllInvalidStates(address(counter), abi.encodeCall(counter.increment, ()), alice, REQUEST_ID);
56
+ assertEq(counter.count(), 1);
57
+ }
58
+ }
@@ -0,0 +1,88 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {GatedTest} from "./GatedTest.sol";
5
+ import {GatedCounter} from "./examples/GatedCounter.sol";
6
+ import {Gated} from "../src/Gated.sol";
7
+ import {EligibilityStatus} from "../src/IRedbellyVerifier.sol";
8
+ import {ReceptorMock} from "../src/ReceptorMock.sol";
9
+
10
+ contract FuzzTest is GatedTest {
11
+ function setUp() public {
12
+ _deployMock();
13
+ }
14
+
15
+ function testFuzz_unsetWalletIsNeverIssuedAndDenied(address wallet, uint64 requestId) public {
16
+ assertEq(uint8(mock.eligibilityStatus(wallet, requestId)), uint8(EligibilityStatus.NeverIssued));
17
+ assertFalse(mock.isEligible(wallet, requestId));
18
+
19
+ GatedCounter counter = new GatedCounter(mock, requestId);
20
+ vm.prank(wallet);
21
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, wallet, requestId));
22
+ counter.increment();
23
+ }
24
+
25
+ function testFuzz_validIsScopedToTheExactPair(
26
+ address wallet,
27
+ uint64 requestId,
28
+ address otherWallet,
29
+ uint64 otherRequestId
30
+ ) public {
31
+ vm.assume(wallet != otherWallet || requestId != otherRequestId);
32
+ mock.setStatus(wallet, requestId, EligibilityStatus.Valid);
33
+ assertTrue(mock.isEligible(wallet, requestId));
34
+ assertFalse(mock.isEligible(otherWallet, otherRequestId));
35
+
36
+ GatedCounter counter = new GatedCounter(mock, requestId);
37
+ vm.prank(wallet);
38
+ counter.increment();
39
+ assertEq(counter.count(), 1);
40
+ }
41
+
42
+ function testFuzz_onlyValidPasses(address wallet, uint64 requestId, uint8 rawStatus) public {
43
+ EligibilityStatus status = EligibilityStatus(bound(rawStatus, 0, uint8(EligibilityStatus.WrongJurisdiction)));
44
+ mock.setStatus(wallet, requestId, status);
45
+ assertEq(uint8(mock.eligibilityStatus(wallet, requestId)), uint8(status));
46
+ assertEq(mock.isEligible(wallet, requestId), status == EligibilityStatus.Valid);
47
+
48
+ GatedCounter counter = new GatedCounter(mock, requestId);
49
+ vm.prank(wallet);
50
+ if (status != EligibilityStatus.Valid) {
51
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, wallet, requestId));
52
+ }
53
+ counter.increment();
54
+ }
55
+
56
+ function testFuzz_wildcardCoversEveryRequestIdUnlessOverridden(
57
+ address wallet,
58
+ uint64 requestId,
59
+ uint64 overriddenRequestId,
60
+ uint8 rawOverride
61
+ ) public {
62
+ vm.assume(requestId != overriddenRequestId);
63
+ EligibilityStatus overrideStatus =
64
+ EligibilityStatus(bound(rawOverride, 0, uint8(EligibilityStatus.WrongJurisdiction)));
65
+ mock.setStatusAll(wallet, EligibilityStatus.Valid);
66
+ mock.setStatus(wallet, overriddenRequestId, overrideStatus);
67
+ assertTrue(mock.isEligible(wallet, requestId));
68
+ assertEq(mock.isEligible(wallet, overriddenRequestId), overrideStatus == EligibilityStatus.Valid);
69
+ }
70
+
71
+ function testFuzz_expiryFollowsTheClock(address wallet, uint64 requestId, uint64 expiresAt, uint64 now_) public {
72
+ mock.setValidUntil(wallet, requestId, expiresAt);
73
+ vm.warp(now_);
74
+ bool expectedEligible = expiresAt == 0 || now_ < expiresAt;
75
+ assertEq(mock.isEligible(wallet, requestId), expectedEligible);
76
+ EligibilityStatus expected = expectedEligible ? EligibilityStatus.Valid : EligibilityStatus.Expired;
77
+ assertEq(uint8(mock.eligibilityStatus(wallet, requestId)), uint8(expected));
78
+ }
79
+
80
+ function testFuzz_frozenMockNeverChanges(address wallet, uint64 requestId, uint8 rawStatus) public {
81
+ EligibilityStatus status = EligibilityStatus(bound(rawStatus, 0, uint8(EligibilityStatus.WrongJurisdiction)));
82
+ mock.setStatus(wallet, requestId, status);
83
+ mock.freeze();
84
+ vm.expectRevert(ReceptorMock.MockIsFrozen.selector);
85
+ mock.setStatus(wallet, requestId, EligibilityStatus.Valid);
86
+ assertEq(uint8(mock.eligibilityStatus(wallet, requestId)), uint8(status));
87
+ }
88
+ }
@@ -0,0 +1,127 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.30;
3
+
4
+ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5
+ import {GatedTest} from "./GatedTest.sol";
6
+ import {GatedCounter} from "./examples/GatedCounter.sol";
7
+ import {Gated} from "../src/Gated.sol";
8
+ import {EligibilityStatus, IRedbellyVerifier} from "../src/IRedbellyVerifier.sol";
9
+ import {ReceptorMock} from "../src/ReceptorMock.sol";
10
+
11
+ contract GatedCounterTest is GatedTest {
12
+ uint64 internal constant REQUEST_ID = 108;
13
+
14
+ GatedCounter internal counter;
15
+ address internal alice = makeAddr("alice");
16
+ address internal bob = makeAddr("bob");
17
+ address internal stranger = makeAddr("stranger");
18
+
19
+ function setUp() public {
20
+ _deployMock();
21
+ counter = new GatedCounter(mock, REQUEST_ID);
22
+ }
23
+
24
+ function test_incrementAcrossAllFiveStates() public {
25
+ assertRevertsForAllInvalidStates(address(counter), abi.encodeCall(counter.increment, ()), alice, REQUEST_ID);
26
+ assertEq(counter.count(), 1, "only the Valid call should have counted");
27
+ }
28
+
29
+ function test_nudgeNeedsBothParties() public {
30
+ assertGatedPair(address(counter), abi.encodeCall(counter.nudge, (bob)), alice, bob, REQUEST_ID);
31
+ assertEq(counter.nudges(alice, bob), 2, "two successful nudges expected");
32
+ }
33
+
34
+ function test_tryIncrementLogsDenialWithoutReverting() public {
35
+ vm.expectEmit(address(counter));
36
+ emit Gated.EligibilityDenied(alice, REQUEST_ID, address(mock));
37
+ vm.prank(alice);
38
+ bool moved = counter.tryIncrement();
39
+ assertFalse(moved);
40
+ assertEq(counter.count(), 0);
41
+
42
+ mock.setStatus(alice, REQUEST_ID, EligibilityStatus.Valid);
43
+ vm.prank(alice);
44
+ assertTrue(counter.tryIncrement());
45
+ assertEq(counter.count(), 1);
46
+ }
47
+
48
+ function test_requestIdMustMatch() public {
49
+ mock.setStatus(alice, REQUEST_ID + 1, EligibilityStatus.Valid);
50
+ vm.prank(alice);
51
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, alice, REQUEST_ID));
52
+ counter.increment();
53
+ }
54
+
55
+ function test_setStatusAllCoversTheCounter() public {
56
+ mock.setStatusAll(alice, EligibilityStatus.Valid);
57
+ vm.prank(alice);
58
+ counter.increment();
59
+ assertEq(counter.count(), 1);
60
+ }
61
+
62
+ function test_isEligibleView() public {
63
+ assertFalse(counter.isEligible(alice));
64
+ mock.setStatus(alice, REQUEST_ID, EligibilityStatus.Valid);
65
+ assertTrue(counter.isEligible(alice));
66
+ assertEq(address(counter.verifier()), address(mock));
67
+ assertEq(counter.requestId(), REQUEST_ID);
68
+ }
69
+
70
+ function test_constructorEmitsAndRejectsZeroVerifier() public {
71
+ vm.expectEmit();
72
+ emit Gated.VerifierChanged(address(0), address(mock));
73
+ vm.expectEmit();
74
+ emit Gated.RequestIdChanged(0, 7);
75
+ new GatedCounter(mock, 7);
76
+
77
+ vm.expectRevert(Gated.ZeroVerifier.selector);
78
+ new GatedCounter(IRedbellyVerifier(address(0)), 7);
79
+ }
80
+
81
+ function test_onlyOwnerChangesVerifierAndRequestId() public {
82
+ ReceptorMock other = new ReceptorMock();
83
+
84
+ vm.prank(stranger);
85
+ vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, stranger));
86
+ counter.setVerifier(other);
87
+
88
+ vm.prank(stranger);
89
+ vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, stranger));
90
+ counter.setRequestId(9);
91
+
92
+ vm.expectEmit(address(counter));
93
+ emit Gated.VerifierChanged(address(mock), address(other));
94
+ counter.setVerifier(other);
95
+ assertEq(address(counter.verifier()), address(other));
96
+
97
+ vm.expectEmit(address(counter));
98
+ emit Gated.RequestIdChanged(REQUEST_ID, 9);
99
+ counter.setRequestId(9);
100
+ assertEq(counter.requestId(), 9);
101
+
102
+ vm.expectRevert(Gated.ZeroVerifier.selector);
103
+ counter.setVerifier(IRedbellyVerifier(address(0)));
104
+
105
+ // The gate now reads the new verifier and the new request id.
106
+ other.setStatus(alice, 9, EligibilityStatus.Valid);
107
+ vm.prank(alice);
108
+ counter.increment();
109
+ mock.setStatus(alice, REQUEST_ID, EligibilityStatus.Valid);
110
+ vm.prank(bob);
111
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, bob, 9));
112
+ counter.increment();
113
+ }
114
+
115
+ function test_expiryDeniesAfterWarp() public {
116
+ uint64 expiresAt = uint64(block.timestamp + 1 days);
117
+ mock.setValidUntil(alice, REQUEST_ID, expiresAt);
118
+ vm.prank(alice);
119
+ counter.increment();
120
+
121
+ vm.warp(expiresAt);
122
+ vm.prank(alice);
123
+ vm.expectRevert(abi.encodeWithSelector(Gated.NotEligible.selector, alice, REQUEST_ID));
124
+ counter.increment();
125
+ assertEq(uint8(mock.eligibilityStatus(alice, REQUEST_ID)), uint8(EligibilityStatus.Expired));
126
+ }
127
+ }