I am running a test script with mainnet-fork using alchemy.
The test appears to be successfully completed, but during the tear down bit, brownie throws up: ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
The full readout:
PS D:\Remix Projects\Patrick Colins\Solidity with Python\Lesson7 - Lottery> brownie test --network mainnet-fork
INFO: Could not find files for the given pattern(s).
Brownie v1.18.1 - Python development framework for Ethereum
====================================================================================================== test session starts ======================================================================================================
platform win32 -- Python 3.9.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: D:\Remix Projects\Patrick Colins\Solidity with Python\Lesson7 - Lottery
plugins: eth-brownie-1.18.1, hypothesis-6.27.3, forked-1.4.0, xdist-1.34.0, web3-5.27.0
collected 1 item
Launching 'ganache-cli.cmd --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/QQSu6nAAnOvWlkS9KTHk9UGk-kxieDmj --mnemonic brownie --port 8545 --hardfork istanbul'...
tests\test_lottery.py . [100%]
====================================================================================================== 1 passed in 15.00s =======================================================================================================
Terminating local RPC client...
Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files\Python39\lib\http\client.py", line 1377, in getresponse
response.begin()
File "C:\Program Files\Python39\lib\http\client.py", line 320, in begin
version, status, reason = self._read_status()
File "C:\Program Files\Python39\lib\http\client.py", line 281, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files\Python39\lib\socket.py", line 704, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files\Python39\lib\http\client.py", line 1377, in getresponse
response.begin()
File "C:\Program Files\Python39\lib\http\client.py", line 320, in begin
version, status, reason = self._read_status()
File "C:\Program Files\Python39\lib\http\client.py", line 281, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files\Python39\lib\socket.py", line 704, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py", line 124, in _request
response = web3.provider.make_request(method, args) # type: ignore
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\web3\providers\rpc.py", line 88, in make_request
raw_response = make_post_request(
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\web3\_utils\request.py", line 48, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs) # type: ignore
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py", line 577, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py", line 501, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Program Files\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py", line 332, in _add_to_undo_buffer
self.sleep(0)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py", line 375, in sleep
self._time_offset = int(rpc.Rpc().sleep(seconds))
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\__init__.py", line 45, in wrapped
return fn(*args, **kwargs)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\__init__.py", line 166, in sleep
return self.backend.sleep(seconds)
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py", line 133, in sleep
return _request("evm_increaseTime", [seconds])
File "C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py", line 128, in _request
raise RPCRequestError("Web3 is not connected.")
brownie.exceptions.RPCRequestError: Web3 is not connected.
I tried addressing this by launching my ganache UI before running the test. However, when doing so my test fails, with a VirtualMachineError.
The full readout:
PS D:\Remix Projects\Patrick Colins\Solidity with Python\Lesson7 - Lottery> brownie test --network mainnet-fork
INFO: Could not find files for the given pattern(s).
Brownie v1.18.1 - Python development framework for Ethereum
====================================================================================================== test session starts ======================================================================================================
platform win32 -- Python 3.9.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: D:\Remix Projects\Patrick Colins\Solidity with Python\Lesson7 - Lottery
plugins: eth-brownie-1.18.1, hypothesis-6.27.3, forked-1.4.0, xdist-1.34.0, web3-5.27.0
collected 1 item
Attached to local RPC client listening at '127.0.0.1:8545'...
tests\test_lottery.py F [100%]
=========================================================================================================== FAILURES ============================================================================================================
_______________________________________________________________________________________________________ test_entranceFee ________________________________________________________________________________________________________
def test_entranceFee():
account = accounts[0]
lottery = Lottery.deploy(config["networks"][network.show_active()]["ethusd_pricefeed"],{"from": account})
> print(lottery.getEntranceFee())
tests\test_lottery.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1710: in __call__
return self.transact(*args)
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1583: in transact
return tx["from"].transfer(
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py:682: in transfer
receipt._raise_if_reverted(exc)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Transaction '0x724f5c0d843d7d7932130c7c7a4ae1a61a9bbad4aeef7726fa47dd579a319d4c'>
exc = VirtualMachineError(ValueError({'message': 'VM Exception while processing transaction: revert', 'code': -32000, 'data'...double.js:627:24)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)', 'name': 'RuntimeError'}}))
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 brownie.exceptions.VirtualMachineError: revert
E Trace step -1, program counter 310:
E File "contracts/Lottery.sol", line 28, in Lottery.getEntranceFee:
E //calc entrance fee in eth
E function getEntranceFee() public returns(uint) {
E //get eth/usd
E (,int price,,,) = ethusd_pricefeed.latestRoundData();
E uint eth_usd = (uint(price) * 10**10); // ETH/USD rate received in 8dp, multiply by 10**10 to make 18 dp
E // convert to eth = usd/ethPrice
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\transaction.py:446: VirtualMachineError
----------------------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------------------
Transaction sent: 0x724f5c0d843d7d7932130c7c7a4ae1a61a9bbad4aeef7726fa47dd579a319d4c
======================================================================================================= warnings summary ========================================================================================================
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py:44
C:\Users\PC\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py:44: BrownieEnvironmentWarning: Development network has a block height of 2
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/warnings.html
==================================================================================================== short test summary info ====================================================================================================
FAILED tests/test_lottery.py::test_entranceFee - brownie.exceptions.VirtualMachineError: revert
================================================================================================= 1 failed, 1 warning in 1.70s ==================================================================================================
Questions:
I should not be running ganache UI when deploying forks, as brownie would attach itself to the UI environment and not pull from the alchemy fork - Is this understand correct?
Regarding the connection reset issue - how can i rectify it?
Thank you.