0

我一直在 Free Code Camp 16 小时课程中学习 Solidity。我整天都在运行测试时遇到问题。我能够通过,但现在我被卡住了。我在 mainnet-fork 上测试时的错误与 Patrick Collins 类似,但一旦更正,我就遇到了一个巨大的错误。以下是我的代码以及大量错误。

platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: C:\Users\patri\demos\smartcontract-lottery
plugins: eth-brownie-1.17.2, hypothesis-6.27.3, forked-1.3.0, xdist-1.34.0, web3-5.25.0
collected 0 items / 1 error

=============================================================================== ERRORS ================================================================================
_______________________________________________________________ ERROR collecting tests/test_lottery.py ________________________________________________________________ 
..\..\.local\pipx\venvs\eth-brownie\lib\site-packages\_pytest\python.py:578: in _importtestmodule
    mod = import_path(self.fspath, mode=importmode)
..\..\.local\pipx\venvs\eth-brownie\lib\site-packages\_pytest\pathlib.py:524: in import_path
    importlib.import_module(module_name)
..\..\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
..\..\.local\pipx\venvs\eth-brownie\lib\site-packages\_pytest\assertion\rewrite.py:161: in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
..\..\.local\pipx\venvs\eth-brownie\lib\site-packages\_pytest\assertion\rewrite.py:354: in _rewrite_test
    tree = ast.parse(source, filename=fn_)
..\..\AppData\Local\Programs\Python\Python39\lib\ast.py:50: in parse
    return compile(source, filename, mode, flags,
E     File "C:\Users\patri\demos\smartcontract-lottery\tests\test_lottery.py", line 7
E       account = accounts[0]
E       ^
E   IndentationError: expected an indented block
======================================================================= short test summary info ======================================================================= 
FAILED tests/test_lottery.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
========================================================================== 1 error in 1.03s ===========================================================================
# 0.015
# 15000000000000000000
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.show_active()]["eth_usd_price_feed"],
    {"from": account},
)
assert lottery.getEntranceFee() > Web3.toWei(0.014, "ether")
assert lottery.getEntranceFee() < Web3.toWei(0.017, "ether")
// 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; // 18 decimals
        // $50, $2000 / ETH
        // 50/2,000
        // 50 * 100000 / 2000
        uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
        return costToEnter;
    }

    function startLottery() public {}

    function endLottery() public {}
}
4

1 回答 1

0

您必须正确缩进您的 python 代码才能使其工作。

def test_get_entrance_fee():
    account = accounts[0]
    lottery = Lottery.deploy(
        config["networks"][network.show_active()]["eth_usd_price_feed"],
        {"from": account},
    )

Python对缩进制表符和空格的解释

于 2022-02-18T06:05:49.160 回答