@@ -19,6 +19,8 @@ contract FeeGateTest is Test {
1919 address public issuer = vm.addr (ISSUER_KEY);
2020 address public recipient = address (0xBEEF );
2121
22+ receive () external payable {}
23+
2224 string constant SCHEMA =
2325 'string cubidId,uint8 trustLevel,bool human,bytes32 circle,uint64 issuedAt,uint64 expiry,uint256 nonce ' ;
2426
@@ -113,13 +115,13 @@ contract FeeGateTest is Test {
113115 vm.stopPrank ();
114116
115117 vm.startPrank (issuer);
116- bytes32 uid = feeGate.attestDirect {value: feeGate.LIFETIME_FEE ()}(_payload ('cubidC ' , 6 ));
118+ bytes32 uid = feeGate.attestDirect {value: feeGate.lifetimeFee ()}(_payload ('cubidC ' , 6 ));
117119 vm.stopPrank ();
118120
119121 assertEq (feeGate.attestCount (issuer), 3 );
120122 assertTrue (feeGate.hasPaidFee (issuer));
121123 assertEq (feeGate.getLastUID (issuer, 'cubidC ' ), uid);
122- assertEq (address (feeGate).balance, feeGate.LIFETIME_FEE ());
124+ assertEq (address (feeGate).balance, feeGate.lifetimeFee ());
123125
124126 // fourth attestation requires no additional fee
125127 AttestationPayload memory payloadFourth = _payload ('cubidD ' , 7 );
@@ -136,7 +138,7 @@ contract FeeGateTest is Test {
136138
137139 assertEq (feeGate.attestCount (issuer), 4 );
138140 assertTrue (feeGate.hasPaidFee (issuer));
139- assertEq (address (feeGate).balance, feeGate.LIFETIME_FEE ());
141+ assertEq (address (feeGate).balance, feeGate.lifetimeFee ());
140142 }
141143
142144 function testInsufficientFeeDelegatedReverts () public {
@@ -169,6 +171,68 @@ contract FeeGateTest is Test {
169171 assertEq (feeGate.getLastUID (issuer, 'cubidX ' ), latestUID);
170172 }
171173
174+ function testSetLifetimeFeeByDeployer () public {
175+ uint256 oldFee = feeGate.lifetimeFee ();
176+ assertEq (oldFee, 100 ether);
177+
178+ uint256 newFee = 50 ether ;
179+ feeGate.setLifetimeFee (newFee);
180+
181+ assertEq (feeGate.lifetimeFee (), newFee);
182+
183+ // Verify new fee is enforced
184+ vm.startPrank (issuer);
185+ feeGate.attestDirect (_payload ('cubid1 ' , 5 ));
186+ feeGate.attestDirect (_payload ('cubid2 ' , 5 ));
187+
188+ // Third attestation should now require the new fee amount
189+ vm.expectRevert (FeeGate.InsufficientFee.selector );
190+ feeGate.attestDirect {value: oldFee}(_payload ('cubid3 ' , 6 ));
191+
192+ // Should succeed with new fee
193+ feeGate.attestDirect {value: newFee}(_payload ('cubid3 ' , 6 ));
194+ vm.stopPrank ();
195+
196+ assertTrue (feeGate.hasPaidFee (issuer));
197+ assertEq (address (feeGate).balance, newFee);
198+ }
199+
200+ function testSetLifetimeFeeRevertsForNonDeployer () public {
201+ vm.prank (issuer);
202+ vm.expectRevert (FeeGate.OnlyDeployer.selector );
203+ feeGate.setLifetimeFee (50 ether);
204+ }
205+
206+ function testSetLifetimeFeeRevertsForZero () public {
207+ vm.expectRevert (FeeGate.InvalidFee.selector );
208+ feeGate.setLifetimeFee (0 );
209+ }
210+
211+ function testWithdrawByDeployer () public {
212+ // Setup: get issuer to pay fee
213+ vm.startPrank (issuer);
214+ feeGate.attestDirect (_payload ('cubid1 ' , 5 ));
215+ feeGate.attestDirect (_payload ('cubid2 ' , 5 ));
216+ feeGate.attestDirect {value: feeGate.lifetimeFee ()}(_payload ('cubid3 ' , 6 ));
217+ vm.stopPrank ();
218+
219+ uint256 contractBalance = address (feeGate).balance;
220+ assertEq (contractBalance, 100 ether);
221+
222+ uint256 deployerBalanceBefore = address (this ).balance;
223+ feeGate.withdraw ();
224+ uint256 deployerBalanceAfter = address (this ).balance;
225+
226+ assertEq (address (feeGate).balance, 0 );
227+ assertEq (deployerBalanceAfter - deployerBalanceBefore, contractBalance);
228+ }
229+
230+ function testWithdrawRevertsForNonDeployer () public {
231+ vm.prank (issuer);
232+ vm.expectRevert (FeeGate.OnlyDeployer.selector );
233+ feeGate.withdraw ();
234+ }
235+
172236 function _payload (
173237 string memory cubidId ,
174238 uint8 trustLevel
0 commit comments