0

I'm trying to deploy a simple Lottery contract with the Foundry framework. While testing I had some little problem, in fact I defined the following modifier:

modifier selectedWinner() {
        vm.prank(ALICE);
        lottery.joinTheLottery{value: 1 ethereum}();
        vm.prank(BOB);
        lottery.joinTheLottery{value: 1 ethereum}();
        lottery.selectWinner();      
        _;
    }

I already tested the selectWinner and joinTheLottery function and they work.

My test should assert that the number of players at the moment is 2 (Alice and Bob):

function testNumberPlayers() public selectedWinner {
        uint256 n = lottery.getCurrentNumberOfPlayer();
        assertEq(n, 2);

but it trows an error. If I can guess, I'd say I can't can set up two vm.prank(). Am I right? Is there any solution to this?

Thanks in advance.

1 Answer 1

1

While you want to set a signer for more that one transactions, you can use vm.startPrank(bob) and vm.stopPrank.

Like this

modifier selectedWinner() {
    vm.prank(ALICE);
    lottery.joinTheLottery{value: 1 ethereum}();
    vm.startPrank(BOB);
    lottery.joinTheLottery{value: 1 ethereum}();
    lottery.selectWinner();  
    vm.stopPrank();    
    _;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.