PatrickAlphaC / brownie_fund_me

26 stars 64 forks source link

[Duplicate] test_only_owner_can_withdraw() throws AttributeError instead of VirtualMachineError #15

Closed RishabhSood closed 2 years ago

RishabhSood commented 2 years ago
from scripts.helpers import get_account, LOCAL_BLOCKCHAIN_ENVIRONMENTS
from scripts.deploy import deploy_fund_me
from brownie import network, accounts, exceptions
import pytest

def test_can_fund_and_withdraw():
    account = get_account()
    fund_me = deploy_fund_me()
    entrance_fee = fund_me.getEntranceFee() + 100
    tx = fund_me.fund({"from": account, "value": entrance_fee})
    tx.wait(1)
    assert fund_me.addressToAmountFunded(account.address) == entrance_fee
    tx2 = fund_me.withdraw({"from": account})
    tx2.wait(1)
    assert fund_me.addressToAmountFunded(account.address) == 0

def test_only_owner_can_withdraw():
    if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
        pytest.skip("only for local testing")
    # account = get_account()
    fund_me = deploy_fund_me()
    bad_actor = accounts.add()
    fund_me.withdraw({"from": bad_actor})
    # with pytest.raises(exceptions.VirtualMachineError):
    #     fund_me.withdraw({"from": bad_actor})
brownie test -k test_only_owner_can_withdraw
INFO: Could not find files for the given pattern(s).
Brownie v1.17.2 - Python development framework for Ethereum

=============================== test session starts ================================
platform win32 -- Python 3.8.8, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: D:\College + Study\Courses\Solidity, Blockchain and Smart Contracts\brownie\fund_me
plugins: eth-brownie-1.17.2, hypothesis-6.27.3, forked-1.3.0, xdist-1.34.0, web3-5.25.0
collected 2 items / 1 deselected / 1 selected

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

tests\test_fund_me.py F                                                       [100%]

===================================== FAILURES ===================================== 
___________________________ test_only_owner_can_withdraw ___________________________ 

    def test_only_owner_can_withdraw():
        if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
            pytest.skip("only for local testing")
        # account = get_account()
        fund_me = deploy_fund_me()
        bad_actor = accounts.add()
>       fund_me.withdraw({"from": bad_actor})

tests\test_fund_me.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
C:\Users\soodr\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1629: in __call__
    return self.transact(*args)
C:\Users\soodr\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1502: in transact
    return tx["from"].transfer(
C:\Users\soodr\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py:682: in transfer
    receipt._raise_if_reverted(exc)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

self = <Transaction '0x7dbae07c4cd6854eba8d10cb92440ce5d50c3b53be61e25927dc512ad17613ea'>
exc = None

    def _raise_if_reverted(self, exc: Any) -> None:
        if self.status or CONFIG.mode == "console":
            return
        if not web3.supports_traces:
            # if traces are not available, do not attempt to determine the revert reason
            raise exc or ValueError("Execution reverted")

        if self._dev_revert_msg is None:
            # no revert message and unable to check dev string - have to get trace   
            self._expand_trace()
        if self.contract_address:
            source = ""
        elif CONFIG.argv["revert"]:
            source = self._traceback_string()
        else:
            source = self._error_string(1)
            contract = state._find_contract(self.receiver)
            if contract:
                marker = "//" if contract._build["language"] == "Solidity" else "#"  
                line = self._traceback_string().split("\n")[-1]
                if marker + " dev: " in line:
                    self._dev_revert_msg = line[line.index(marker) + len(marker) : -5].strip()

>       raise exc._with_attr(
            source=source, revert_msg=self._revert_msg, dev_revert_msg=self._dev_revert_msg
        )
E       AttributeError: 'NoneType' object has no attribute '_with_attr'

C:\Users\soodr\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\transaction.py:446: AttributeError
------------------------------- Captured stdout call -------------------------------
The acitve network is development
Deploying mocks...
Mocks deployed
Contract deployed to 0x602C71e4DAC47a042Ee7f46E0aee17F94A3bA0B6
mnemonic: 'fortune shrug mass west priority reopen document private enemy spike loop depth'
============================= short test summary info ============================== 
FAILED tests/test_fund_me.py::test_only_owner_can_withdraw - AttributeError: 'None...
========================= 1 failed, 1 deselected in 7.16s ========================== 
Terminating local RPC client...
RishabhSood commented 2 years ago

Updating node version and reinstalling ganache-cli seems to resolve this issue.