Skip to content

Don't understand why a test is passing #3188

Answered by ismaildawoodjee
SHerbes asked this question in Q&A
Discussion options

You must be logged in to vote

Great question. I'm doing the exact same lesson actually 😄

The msg.sender in the console logs is actually the fundMe.i_owner() that we tested in the second test:

    function test_Owner_IsMsgSender() public view {
        assertEq(fundMe.i_owner(), msg.sender);
    }

If you want to know who's actually calling the fund() and withdraw() functions, you need to log them inside the functions themselves. The msg.sender is just the caller of the test function, which we already established is the owner.

Include a log in the onlyOwner() modifier:

    modifier onlyOwner() {
        console.log("Caller address of onlyOwner / withdraw():", msg.sender, "\n");
        if (msg.sender != i_owner) revert N…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@KMean
Comment options

@ismaildawoodjee
Comment options

@EngrPips
Comment options

@SHerbes
Comment options

@EngrPips
Comment options

Answer selected by SHerbes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants