@@ -993,4 +993,94 @@ contract SmartnodesTokenTest is BaseSmartnodesTest {
993993 vm.prank (address (core));
994994 token.escrowPayment (user1, largeAmount);
995995 }
996+
997+ /**
998+ * @notice Simulate 100 reward distribution periods and claim all 100 rewards
999+ */
1000+ function testSimulate100RewardPeriodsAndClaim () public {
1001+ console.log (
1002+ "=== Simulating 100 reward periods and claiming in batches of 100 === "
1003+ );
1004+
1005+ uint256 NUM_PERIODS = 100 ;
1006+ uint256 BATCH_SIZE = 100 ;
1007+ _setupContractFunding ();
1008+
1009+ // fund contract for ETH side of rewards
1010+ vm.deal (address (core), ADDITIONAL_ETH_PAYMENT * NUM_PERIODS);
1011+ vm.prank (address (core));
1012+ (bool sent , ) = address (token).call {
1013+ value: ADDITIONAL_ETH_PAYMENT * NUM_PERIODS
1014+ }("" );
1015+ require (sent, "funding failed " );
1016+
1017+ // pick one worker to repeatedly claim rewards
1018+ Participant[] memory initialWorkers;
1019+ uint256 dummyTotalCapacity;
1020+ (initialWorkers, dummyTotalCapacity) = _setupTestParticipants (5 , false );
1021+
1022+ address worker = initialWorkers[0 ].addr;
1023+ uint256 workerIndex = 0 ;
1024+
1025+ uint256 [] memory distributionIds = new uint256 [](NUM_PERIODS);
1026+ uint256 [] memory capacities = new uint256 [](NUM_PERIODS);
1027+ bytes32 [][] memory proofs = new bytes32 [][](NUM_PERIODS);
1028+
1029+ // ----- CREATE 10,000 MERKLE DISTRIBUTIONS -----
1030+ for (uint256 i = 0 ; i < NUM_PERIODS; i++ ) {
1031+ Participant[] memory participants;
1032+ uint256 totalCapacity;
1033+
1034+ (participants, totalCapacity) = _setupTestParticipants (5 , false );
1035+
1036+ require (workerIndex < participants.length , "invalid worker index " );
1037+ capacities[i] = participants[workerIndex].capacity;
1038+
1039+ bytes32 [] memory leaves = _generateLeaves (
1040+ participants,
1041+ token.s_currentDistributionId () + 1
1042+ );
1043+ proofs[i] = _generateMerkleProof (leaves, workerIndex);
1044+
1045+ vm.warp (block .timestamp + UPDATE_TIME);
1046+
1047+ (uint256 distributionId , ) = _createAndValidateDistribution (
1048+ participants,
1049+ totalCapacity
1050+ );
1051+
1052+ distributionIds[i] = distributionId;
1053+ }
1054+
1055+ uint256 preBal = token.balanceOf (worker);
1056+ uint256 preEth = worker.balance;
1057+
1058+ // ----- CLAIM IN BATCHES OF 100 -----
1059+ vm.startPrank (worker);
1060+
1061+ for (uint256 i = 0 ; i < NUM_PERIODS; i += BATCH_SIZE) {
1062+ uint256 end = i + BATCH_SIZE;
1063+ if (end > NUM_PERIODS) end = NUM_PERIODS;
1064+
1065+ for (uint256 j = i; j < end; j++ ) {
1066+ token.claimMerkleRewards (
1067+ distributionIds[j],
1068+ capacities[j],
1069+ proofs[j]
1070+ );
1071+ }
1072+ }
1073+
1074+ vm.stopPrank ();
1075+
1076+ uint256 postBal = token.balanceOf (worker);
1077+ uint256 postEth = worker.balance;
1078+
1079+ assertTrue (postBal > preBal, "worker SNO rewards should increase " );
1080+ assertTrue (postEth > preEth, "worker ETH rewards should increase " );
1081+
1082+ console.log (
1083+ "Successfully created and claimed 10,000 reward periods in batches of 100! "
1084+ );
1085+ }
9961086}
0 commit comments