0

Ran the code as shown and my constructor is public but I keep getting "Cannot import Lottery from brownie" as the error. The Lottery.sol code is below;

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract lottery {
    address payable[] public players;
    uint256 public usdEntryFee;
    AggregatorV3Interface internal ethUsdPriceFeed;

    constructor(address _priceFeedAddress) public {
        usdEntryFee = 50 * (10**18);
        ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
    }

    function enter() public payable {
        //$50 minimum
        players.push(msg.sender);
    }

    function getEntranceFee() public view returns (uint256) {
        //
        (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
        uint256 adjustedPrice = uint256(price) * 10**10;
        uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
        return costToEnter;
    }

    function startLottery() public {}

    function endLottery() public {}
}

The deploy.py code is below:

#0.0317789204065159
#310000000000000000
from brownie import Lottery, accounts, config, network
from web3 import Web3


def test_get_entrance_fee():
    account = accounts[0]
    lottery = lottery.deploy(
        config["networks"][network.showactive()]["eth_usd_price_feed"],
        {"from": account},
    )
    assert lottery.getEntranceFee() > Web3.toWei(0.028, "ether")
    assert lottery.getEntranceFee() < Web3.toWei(0.038, "ether")

1 Answer 1

0

You have written contract name lottry in small case.

Changes are to be done :

from brownie import Lottery, accounts, config, network

to

from brownie import lottery , accounts, config, network

5
  • I tried that already, same issue. Aug 6, 2022 at 16:42
  • If you are trying to test. Check correct spelling in confest.py file also. It would be better if you could share all code through github Aug 6, 2022 at 16:49
  • I actually tried what you mentioned initially again but this time I recompiled so right now I am battling another error, an attribute error. Says AttributeError: 'ContractContainer' object has no attribute 'getEntranceFee' From the deploy.py code I initially posted. Aug 6, 2022 at 17:16
  • Thank you so much for your help, it was actually still the same issue of casing used. Thank you Aug 6, 2022 at 17:23
  • Welcome. Try to give first letter as capital for Smart Contract name Aug 7, 2022 at 12:47

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.