彩票主网分叉测试问题



我一直在免费代码营学习Solidity 16小时课程。我一整天都在测试中遇到问题。我本来可以通过,但现在我被卡住了。我在主网fork上测试时的错误与Patrick Collins类似,但一旦纠正,我就出现了一个巨大的错误。下面是我的代码以及巨大的错误。

platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: C:Userspatridemossmartcontract-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 ________________________________________________________________ 
.....localpipxvenvseth-brownielibsite-packages_pytestpython.py:578: in _importtestmodule
mod = import_path(self.fspath, mode=importmode)
.....localpipxvenvseth-brownielibsite-packages_pytestpathlib.py:524: in import_path
importlib.import_module(module_name)
....AppDataLocalProgramsPythonPython39libimportlib__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
???
.....localpipxvenvseth-brownielibsite-packages_pytestassertionrewrite.py:161: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.....localpipxvenvseth-brownielibsite-packages_pytestassertionrewrite.py:354: in _rewrite_test
tree = ast.parse(source, filename=fn_)
....AppDataLocalProgramsPythonPython39libast.py:50: in parse
return compile(source, filename, mode, flags,
E     File "C:Userspatridemossmartcontract-lotteryteststest_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 {}
}

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

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

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

最新更新