0

I'm working through FreeCodeCamp.org's YT Solidity tutorial and I'm up to the part where I'm trying to run pytest on an ETH Mainnet Fork. When I run the tests using brownie test --network mainnet-fork-dev I receive this error:

Error while running tests on mainnet-fork-dev:


(venv) fvs@LAPTOP:~/solidity-scripts/brownie-fund-me$ brownie test --network mainnet-fork-dev
Brownie v1.17.2 - Python development framework for Ethereum

=============================================== test session starts ================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/fvs/solidity-scripts/brownie-fund-me
plugins: eth-brownie-1.17.2, forked-1.3.0, hypothesis-6.27.3, xdist-1.34.0, web3-5.25.0
collected 3 items

Launching 'ganache-cli --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/<API KEY> --mnemonic brownie --port 8545 --hardfork istanbul'...

tests/test_can_fund_and_withdraw.py FFs                                                                      [100%]

===================================================== FAILURES =====================================================
__________________________________________________ test_can_fund ___________________________________________________
    def test_can_fund():
        # Arrange
        account = get_account()
        # Act
        fundme = deploy_fund_me()
        starting_entrance_fee = fundme.getEntranceFee()
>       tx = fundme.fund({"from": account, "value": starting_entrance_fee})
E       brownie.exceptions.VirtualMachineError: revert: You need to spend more ETH!
E       Trace step -1, program counter 1126:
E         File "contracts/FundMe.sol", lines 26-29, in FundMe.fund:
E
E           function fund() public payable {
E               uint256 minimumUSD = 50 * 10**18;
E               require(
E                   getConversionRate(msg.value) >= minimumUSD,
E                   "You need to spend more ETH!"
E               );
E               addressToAmountFunded[msg.sender] += msg.value;
E               funders.push(msg.sender);
E           }

tests/test_can_fund_and_withdraw.py:14: VirtualMachineError
----------------------------------------------- Captured stdout call -----------------------------------------------
Contract deployed to 0xE7eD6747FaC5360f88a2EFC03E00d25789F69291
Transaction sent: 0xdc610b1577c1670b615ecea705d6f347c4c83285a68363a96a6406fcc9fa06f9
________________________________________________ test_can_withdraw _________________________________________________

    def test_can_withdraw():
        # Arrange
        account = get_account()
        # Act
        fundme = deploy_fund_me()
        starting_entrance_fee = fundme.getEntranceFee()
>       tx = fundme.fund({"from": account, "value": starting_entrance_fee})
E       brownie.exceptions.VirtualMachineError: revert: You need to spend more ETH!
E       Trace step -1, program counter 1126:
E         File "contracts/FundMe.sol", lines 26-29, in FundMe.fund:
E
E           function fund() public payable {
E               uint256 minimumUSD = 50 * 10**18;
E               require(
E                   getConversionRate(msg.value) >= minimumUSD,
E                   "You need to spend more ETH!"
E               );
E               addressToAmountFunded[msg.sender] += msg.value;
E               funders.push(msg.sender);
E           }

tests/test_can_fund_and_withdraw.py:26: VirtualMachineError
----------------------------------------------- Captured stdout call -----------------------------------------------
Contract deployed to 0xe0aA552A10d7EC8760Fc6c246D391E698a82dDf9
Transaction sent: 0xf86c00779fc29f34a443ebdb5f11f6ef81148278c800a6f4cc8dd63e50c448de
============================================= short test summary info ==============================================
FAILED tests/test_can_fund_and_withdraw.py::test_can_fund - brownie.exceptions.VirtualMachineError: revert: You n...
FAILED tests/test_can_fund_and_withdraw.py::test_can_withdraw - brownie.exceptions.VirtualMachineError: revert: Y...
=========================================== 2 failed, 1 skipped in 5.11s ===========================================
Terminating local RPC client...

Passing while running tests on development:

(venv) fvs@LAPTOP:~/solidity-scripts/brownie-fund-me$ brownie test --network development
Brownie v1.17.2 - Python development framework for Ethereum

=============================================== test session starts ================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/fvs/solidity-scripts/brownie-fund-me
plugins: eth-brownie-1.17.2, forked-1.3.0, hypothesis-6.27.3, xdist-1.34.0, web3-5.25.0
collected 3 items

Launching 'ganache-cli --accounts 10 --hardfork istanbul --gasLimit 12000000 --mnemonic brownie --port 8545'...

tests/test_can_fund_and_withdraw.py ...                                                                      [100%]

================================================ 3 passed in 2.70s =================================================
Terminating local RPC client...
(venv) fvs@LAPTOP:~/solidity-scripts/brownie-fund-me$

Brownie's network configuration:

  ├─Ganache-CLI
  │ ├─id: development
  │ ├─cmd: ganache-cli
  │ └─host: http://127.0.0.1
  │   ├─accounts: 10
  │   ├─evm_version: istanbul
  │   ├─gas_limit: 12000000
  │   ├─mnemonic: brownie
  │   └─port: 8545
  └─mainnet-fork-dev
    ├─id: mainnet-fork-dev
    ├─cmd: ganache-cli
    └─host: http://127.0.0.1
      ├─accounts: 10
      ├─fork: https://eth-mainnet.alchemyapi.io/v2/<API KEY>
      ├─mnemonic: brownie
      └─port: 8545

But when I run the tests on my local computer, they tests pass. I'm not sure why the mainnet-fork-dev is saying I'm not sending enough ETH. This issue seems to be that the test account that's being used in the unit test, is sending too small of an amount of ETH to the contract, and thus the contract's require statement is causing the test to fail.

Here's a link to my code repo where you can see the full tests file, and FundMe.sol contract: https://github.com/freddie71010/solidity-scripts/blob/main/brownie-fund-me/tests/test_can_fund_and_withdraw.py

2
  • Did you ever figure this out? Experiencing the same issue here...
    – sillyPin
    Jan 28 at 20:12
  • Yep! Just posted my answer @sillyPin on this post below. Lmk if it doesn't work and I can try and help you. Jan 28 at 22:06

1 Answer 1

0

I replaced the numbers related to the decimal point conversion (i.e., 10**8, 10**10, etc) with 1_000_000_000_000_000_000, 10_000_000_000, etc. It seems I must have had an issue with those exponents since now when I run the command, they all pass!

command: brownie test -v --network mainnet-fork-dev

You can see my latest file on my GH: https://github.com/freddie71010/solidity-scripts/blob/main/brownie-fund-me/contracts/FundMe.sol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.