Replies: 1 comment
-
Hello @owanemi, The approach you took seems fine, but a gradual increment in the array to show how players that joined later pay more to enter due to the length of the array to the point where some players that come at a more later time couldn't enter again would be more detailed. You can look at the way I wrote my test below. function testPlayersWontBeAbleToParticipateOnceActivePlayersArrayGetFilledToACertainAmount() public {
vm.txGasPrice(1);
// setting up the first 100 players that would enter the game
uint256 playernum = 100;
address[] memory players = new address[](playernum);
for(uint256 i = 0; i < 100; ++i) {
players[i] = address(i);
}
uint256 gastStart = gasleft();
puppyRaffle.enterRaffle{value: entranceFee * players.length}(players);
uint256 gasEnd = gasleft();
uint256 gasSpentForFirstHundredParticant = gastStart - gasEnd;
console.log('The amount of gas used by the first 100 players that entered the raffle is: ', gasSpentForFirstHundredParticant);
// setting up the next 100 players that would enter the game
uint256 playernumTwo = 100;
address[] memory players2 = new address[](playernumTwo);
for(uint256 i = 0; i < 100; ++i) {
players2[i] = address(i + playernumTwo);
// players2[i] = address(i);
}
uint256 gasStart1 = gasleft();
puppyRaffle.enterRaffle{value: entranceFee * players2.length}(players2);
uint256 gasEnd1 = gasleft();
uint256 gasSpentForSecondHundredParticipant = gasStart1 - gasEnd1;
console.log('The amount of gas used by the second 100 players that entered the raffle is: ', gasSpentForSecondHundredParticipant);
// setting up the next 100 players that would enter the game
uint256 playersnumThree = 100;
address[] memory players3 = new address[](playersnumThree);
for(uint256 i = 0; i < 100; ++i) {
players3[i] = address(i + (playersnumThree * 2));
}
uint256 gasStart2 = gasleft();
puppyRaffle.enterRaffle{value: entranceFee * players3.length}(players3);
uint256 gasEnd2 = gasleft();
uint256 gasSpentForThirdHundredParticant = gasStart2 - gasEnd2;
console.log('The amount of gas used by the second 100 players that entered the raffle is: ', gasSpentForThirdHundredParticant);
assert(gasSpentForSecondHundredParticipant < gasSpentForThirdHundredParticant);
} Although I didn't actually increase the length of the player's array enough to cause the revert but I demonstrated the gradual increase in the entry fee and, which will eventually get to a point where it is unreasonable if more people enter |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
when patrick asked us to go ahead and write the poc for the DoS attack in pupple raffle. This is what i did
I wanted to ask if this was too simple and didn't provide enough clarity
Beta Was this translation helpful? Give feedback.
All reactions