@@ -25,9 +25,12 @@ contract QueryTypeStakingPoolTest is Test {
2525
2626 factory.setFeeRecipient (feeRecipient);
2727
28- bytes32 queryType = bytes32 (uint256 (1 ));
29- bytes32 initialEntry = bytes32 (uint256 (1 ));
30- address poolAddress = factory.createStakingPool (queryType, address (this ), initialEntry);
28+ address poolAddress = factory.createStakingPool (
29+ bytes32 (uint256 (1 )), // queryType
30+ address (this ), // poolOwner
31+ bytes32 (uint256 (1 )), // initialEntry
32+ 100 // decayRate
33+ );
3134 pool = QueryTypeStakingPool (poolAddress);
3235
3336 stakingToken.mint (staker, INITIAL_BALANCE);
@@ -61,10 +64,23 @@ contract Constructor is QueryTypeStakingPoolTest {
6164 vm.assume (_stakingToken != address (0 ));
6265
6366 QueryTypeStakingPool _newPool =
64- new QueryTypeStakingPool (_owner, _stakingToken, address (factory), _initialEntry);
67+ new QueryTypeStakingPool (_owner, _stakingToken, address (factory), _initialEntry, 0 );
6568 assertEq (address (_newPool.STAKING_TOKEN ()), _stakingToken);
6669 assertEq (_newPool.conversionTableHistory (0 ), _initialEntry);
6770 }
71+
72+ function testFuzz_RevertIf_DecayRateIsInvalid (uint8 _decayRate ) public {
73+ _decayRate = uint8 (bound (_decayRate, 101 , type (uint8 ).max));
74+
75+ vm.expectRevert (QueryTypeStakingPool.QueryTypeStakingPool__InvalidDecayRate.selector );
76+ new QueryTypeStakingPool (
77+ address (this ), // owner
78+ address (stakingToken), // stakingToken
79+ address (factory), // factory
80+ bytes32 (uint256 (100 )), // initialEntry
81+ _decayRate
82+ );
83+ }
6884}
6985
7086contract UpdateConversionTable is QueryTypeStakingPoolTest {
@@ -1030,3 +1046,91 @@ contract Claim is QueryTypeStakingPoolTest {
10301046 );
10311047 }
10321048}
1049+
1050+ contract DecayRate is QueryTypeStakingPoolTest {
1051+ function testFuzz_DecayRateAppliedCorrectly (
1052+ uint8 _decayRate ,
1053+ uint256 _stakeAmount ,
1054+ uint32 _timeElapsed
1055+ ) public {
1056+ // Bound parameters to reasonable ranges
1057+ _decayRate = uint8 (bound (_decayRate, 1 , 100 )); // Valid decay rates only
1058+ _stakeAmount = bound (_stakeAmount, 100 ether, 10_000 ether);
1059+ _timeElapsed = uint32 (bound (_timeElapsed, 1 days, 60 days));
1060+
1061+ // Create pool with fuzzed decay rate
1062+ address poolAddress = factory.createStakingPool (
1063+ bytes32 (uint256 (5 )), // queryType
1064+ address (this ), // poolOwner
1065+ bytes32 (uint256 (100 )), // initialEntry
1066+ _decayRate // fuzzed decay rate
1067+ );
1068+ QueryTypeStakingPool fuzzedPool = QueryTypeStakingPool (poolAddress);
1069+
1070+ // Set capacity based on stake amount
1071+ uint256 capacity = bound (10_000 ether, _stakeAmount, _stakeAmount * 10 );
1072+ fuzzedPool.setStakingTokenCapacity (capacity);
1073+
1074+ // Setup staker
1075+ stakingToken.mint (staker, INITIAL_BALANCE);
1076+ vm.prank (staker);
1077+ stakingToken.approve (address (fuzzedPool), type (uint256 ).max);
1078+
1079+ // Stake tokens
1080+ vm.prank (staker);
1081+ fuzzedPool.stake (_stakeAmount);
1082+
1083+ uint256 initialAmount = _stakeAmount;
1084+
1085+ // Advance time
1086+ vm.warp (block .timestamp + _timeElapsed);
1087+
1088+ // Claim decay
1089+ fuzzedPool.claim (staker);
1090+
1091+ // Verify decay behavior
1092+ (uint256 finalAmount ,,,,,) = fuzzedPool.stakes (staker);
1093+
1094+ // All valid decay rates should result in some decay
1095+ assertLe (finalAmount, initialAmount, "Amount should not increase with decay " );
1096+ assertGe (finalAmount, 0 , "Amount should not go negative " );
1097+
1098+ // Higher decay rates should result in more decay
1099+ if (_decayRate > 50 ) {
1100+ assertLt (finalAmount, initialAmount, "High decay rate should cause significant decay " );
1101+ }
1102+ }
1103+
1104+ function testFuzz_DecayRateBoundaries (uint8 _decayRate ) public {
1105+ // Test boundary conditions for decay rate
1106+ _decayRate = uint8 (bound (_decayRate, 1 , 100 ));
1107+
1108+ // Create pool with boundary decay rate
1109+ address poolAddress = factory.createStakingPool (
1110+ bytes32 (uint256 (6 )), // queryType
1111+ address (this ), // poolOwner
1112+ bytes32 (uint256 (100 )), // initialEntry
1113+ _decayRate // boundary decay rate
1114+ );
1115+ QueryTypeStakingPool boundaryPool = QueryTypeStakingPool (poolAddress);
1116+
1117+ // Verify decay rate was set correctly
1118+ assertEq (boundaryPool.DECAY_RATE (), _decayRate, "Decay rate should be set correctly " );
1119+
1120+ // Test that pool functions work with boundary decay rates
1121+ stakingToken.mint (staker, INITIAL_BALANCE);
1122+ vm.prank (staker);
1123+ stakingToken.approve (address (boundaryPool), type (uint256 ).max);
1124+
1125+ // Set capacity
1126+ boundaryPool.setStakingTokenCapacity (10_000 ether);
1127+
1128+ // Stake tokens
1129+ vm.prank (staker);
1130+ boundaryPool.stake (1000 ether);
1131+
1132+ // Verify stake was successful
1133+ (uint256 amount ,,,,,) = boundaryPool.stakes (staker);
1134+ assertEq (amount, 1000 ether, "Stake should work with boundary decay rate " );
1135+ }
1136+ }
0 commit comments