2

I'm currently developing a simple prediction market test dapp to further my learning & I'm writing tests right now to check the first contract out. I wanted to make sure that I was referencing & updating certain values the correct way, so I imported Hardhat console.log so that I could log out some of the outputs. I currently have a struct and two enums, & I am able to log out the values of some of my mappings containing the struct & an enum, but console.log will not work on the others.

This is the warning I get: "Member 'log' not found or not visible after argument-dependent lookup in type(library console)."

I know that I must be trying to reference or access them wrong, and might just be using them plain wrong altogether. To that extent, can someone please explain to me how to access/set an enum value, and let me know if I'm doing it all wrong below? Are those values not able to be logged to the console for some reason? I guess I'm just confused as to what I'm really accessing here, as it's very hard for me to visualize right now. I get the aforementioned error on each of the first console.log statements in the if/else, but not the second ones (the ones that reference the struct).

Relevant code is below:

Result public result;

enum overUnder {
    Over,
    Under
}

enum Status {
    Win,
    Lose,
    Draw
}

struct Result {
    overUnder winner;
    overUnder loser;
}

mapping(overUnder => uint256) public bets;
mapping(address => mapping(overUnder => uint256)) public betsPerBettor;
mapping(address => mapping(overUnder => Status)) public bettorWinLoss;

function winOrLose() public {
    uint256 initialPrice = 100;
    uint256 finalPrice = 120;

    if (initialPrice > finalPrice) {
        result.winner = overUnder.Under;
        bettorWinLoss[msg.sender][overUnder.Under] = Status.Win;
        console.log("User win under status: ", bettorWinLoss[msg.sender][overUnder.Under]);
        console.log("Winners under: ", result.winner);
         } else {
            result.winner = overUnder.Over;
            bettorWinLoss[msg.sender][overUnder.Over] = Status.Win;
            console.log("User win over status: ", bettorWinLoss[msg.sender]);
            console.log("Winners over: ", result.winner);
        }

Thank you!

1
  • Update, my linter was just slow. None of the console logs are working on either side with the same error.
    – jkiles
    Sep 1, 2021 at 21:38

1 Answer 1

3

Enums are represented as uint values under the hood, but you the console.log function will fail to compile unless you explicitly convert them to uint before logging.

try console.log(uint(result.winner)) and I think that will work for you.

You'll get a number which is determined by the order defined in the enum (the first enum member = 0)

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.