If the are too much winners in a contest, the loop of fund distribution may run out of gas. If it is the case, the contract will not be able to distribute the tokens.
function testTooMuchWinners() public {
vm.selectFork(mainnetFork);
assertEq(vm.activeFork(), mainnetFork);
bytes32 contestId = 0x0000000000000000000000000000000000000000000000000000000000000001;
vm.startPrank(owner);
proxyFactory.setContest(organizer, contestId, block.timestamp + 10 days, goodImplementation);
deal(usdc, sponsor, 1000 * 10 ** 6);
assertEq(ERC20(usdc).balanceOf(sponsor), 1000 * 10 ** 6);
address proxyAddress = proxyFactory.getProxyAddress(_calculateSalt(organizer, contestId, goodImplementation), goodImplementation);
vm.prank(sponsor);
ERC20(usdc).transfer(proxyAddress, 1000 * 10 ** 6);
skip(11 days);
uint256 winnerAmount = 1000;
address[] memory winners = new address[](winnerAmount);
uint256[] memory percentages = new uint256[](winnerAmount);
uint256 accumulatedPercentage;
for(uint256 i = 1;i <= winnerAmount - 1; i++){
address winner = address(uint160(i));
winners[i-1] = winner;
percentages[i-1] = 10;
accumulatedPercentage+=10;
}
winners[winnerAmount - 1] = makeAddr("lastwinner");
percentages[winnerAmount - 1] = 9500 - accumulatedPercentage;
bytes memory distributeData = abi.encodeWithSignature("distribute(address,address[],uint256[],bytes)", usdc, winners, percentages, "");
vm.startPrank(organizer);
proxyFactory.deployProxyAndDistribute(contestId, implementation, distributeData);
}
Set a maxium number of winners, or if the array is too long, divide the distribution in packs of a certain amount of winners and distribute the funds in more than a single call.