Section 4 Puppy Raffle, Lesson 13 . Dos Test Failing #215
-
This test is throwing a duplicate raffle error
My test is
function enterRaffle(address[] memory newPlayers) public payable {
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @AllenOps08, address(0) entered the raffle twice, and that is why the test reverted with The first player that entered the raffle is address(0) as seen in this output below ├─ [6228032] PuppyRaffle::enterRaffle{value: 100000000000000000000}([0x0000000000000000000000000000000000000000 And then address(0) attempts to enter again as shown in the output below, we both know that the ├─ [346653] PuppyRaffle::enterRaffle{value: 100000000000000000000}([0x0000000000000000000000000000000000000000 The issue here is that you are trying to use the same set of addresses to enter the lottery the second time for the next 100 participants. doing this wouldn't work as the To help get insight on how to resolve this issue, The below is my test 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);
} |
Beta Was this translation helpful? Give feedback.
Hello @AllenOps08, address(0) entered the raffle twice, and that is why the test reverted with
← [Revert] revert: PuppyRaffle: Duplicate player
The first player that entered the raffle is address(0) as seen in this output below
And then address(0) attempts to enter again as shown in the output below, we both know that the
Lottery
contract does not allow an address to enter the lottery twice so the contract revertsThe issue here is that you are trying to use the same se…