Open supercede opened 2 years ago
Hi, I got the same issue and thanks to your post, I could manage a quick fix, which is however not completely satisfactory. I invite you to read the issue I posted today (it doesn't contain the quick fix, as I hadn't found it yet): https://github.com/smartcontractkit/full-blockchain-solidity-course-py/issues/1442
As you noted, when you fix the gas_limit parameter you then get the following error.
ValueError: Execution reverted during call: 'VM Exception while processing transaction: revert'. This transaction will likely revert. If you wish to broadcast, include allow_revert:True as a transaction parameter.
If you try to add the parameter allow_revert: true you'll have the following error:
fund_me.withdraw({"from": bad_actor,"gas_limit":12000000,"allow_revert":True})
ValueError: sender doesn't have enough funds to send tx. The upfront cost is: 240000000000000000 and the sender's account only has: 0
Which is not surprising, because for some reason when you use the method accounts.add() to create the bad_actor, it generates an empty account with a balance of 0. I looked it up but don't know how to change that.
Therefore, if you fix the gas_price to 0, the code should work. In other words the following line should solve your issue:
fund_me.withdraw({"from": bad_actor,"gas_price":0,"gas_limit":12000000,"allow_revert":True})
Alternatively you can also replace bad_actor, by any other account in the accounts list (except account[0] the actual owner), for example, this line will also work:
fund_me.withdraw({"from": accounts[3],"gas_limit":12000000,"allow_revert":True})
_Note that the gaslimit has been fixed at 1200000 because above that, the test fails in the development network with the following message (this is linked to the default configuration of the development network) :
ValueError: Exceeds block gas limit
With regards to the sender's account only has: 0
error, it might be a property of the method accounts.add() that the account created has a balance of 0 or a property of the network on which it is created, I am not sure. It might be possible to redefine this in the network config, but I didn't find any way to do it.
My gut feeling is that the primary issue is linked to the default network config.
https://eth-brownie.readthedocs.io/en/stable/config.html#config
I believe that our ganache-local network has the default properties of a live network since it is not natively a development network. And as you can see in the link development and live network have differing properties such including the following:
gas_limit
gas_buffer
gas_price
reverting_tx_gas_limit
My guess is that one or several of them are responsible for the problem. I tried to change the brownie-config.yaml to play with these parameters, but I am not sure if I am operating correctly.
It is possible that it is linked to the version of Ganache we work with. I work with Ganache 7.0.5, while I think the video was made with Ganache 6.x.x
If you haven't try already, I suggest that you try to explore a bit with a debugger, it makes it easier to understand your issues. You might be luckier than me in finding a more satisfactory solution.
If you work with vscode you can create .vscode folder in your working folder (brownie_fund_me) and create the launch.json with the code below in it. It will allow you to debug your python code, and run some inline command to check your variables and all during code execution. Pretty useful for troubleshooting. You need to adapt "pythonPath" and "program" to your ownenvironment. Also, you may need to copy brownie.exe to be in the same folder as your brownie package folder. Let me know if you have any problem with that.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Brownie Test",
"type": "python",
"request": "launch",
"pythonPath": "D:/Anaconda3/envs/blockchain/python.exe",
"program":"D:/Anaconda3/envs/blockchain/lib/site-packages/brownie.exe",
"console": "integratedTerminal",
"args": ["test","-s","--network","ganache-local"],
},
{
"name": "Brownie Debug",
"type": "python",
"request": "launch",
"pythonPath": "D:/Anaconda3/envs/blockchain/python.exe",
"program":"D:/Anaconda3/envs/blockchain/lib/site-packages/brownie.exe",
"console": "integratedTerminal",
"args": ["run","scripts/deploy.py","--network","ganache-local"],
}
]
}
How to create a bad_actor account that is prefunded? Is the problem linked to the Ganache version? Is the error linked to the properties of the network, and if it is the case how to change them?
You need to use the addresses from Chainlink VRF v1 NOT v2 in your .yaml, remember to re-deploy your contract with these newly updated addresses. Please see the link below for the addresses: https://docs.chain.link/docs/vrf/v1/supported-networks/ https://stackoverflow.com/questions/71194882/execution-reverted-during-call-this-transaction-will-likely-revert-if-you-wish
The same issue. Relly weird behavior, has two different types of errors raised by require in developement and local ganache chain.
Try deploying to Goerli
You need to use the addresses from Chainlink VRF v1 NOT v2 in your .yaml, remember to re-deploy your contract with these newly updated addresses. Please see the link below for the addresses: https://docs.chain.link/docs/vrf/v1/supported-networks/ https://stackoverflow.com/questions/71194882/execution-reverted-during-call-this-transaction-will-likely-revert-if-you-wish
I have checked everything, my addresses are from v1. Still have the error. I am using Goerli
Actually, my error is slightly different: Gas estimation failed: 'execution reverted: 2'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
Hi, I got the same issue and thanks to your post, I could manage a quick fix, which is however not completely satisfactory. I invite you to read the issue I posted today (it doesn't contain the quick fix, as I hadn't found it yet): #1442
Quick fix
As you noted, when you fix the gas_limit parameter you then get the following error.
ValueError: Execution reverted during call: 'VM Exception while processing transaction: revert'. This transaction will likely revert. If you wish to broadcast, include allow_revert:True as a transaction parameter.
If you try to add the parameter allow_revert: true you'll have the following error:
fund_me.withdraw({"from": bad_actor,"gas_limit":12000000,"allow_revert":True})
ValueError: sender doesn't have enough funds to send tx. The upfront cost is: 240000000000000000 and the sender's account only has: 0
Which is not surprising, because for some reason when you use the method accounts.add() to create the bad_actor, it generates an empty account with a balance of 0. I looked it up but don't know how to change that. Therefore, if you fix the gas_price to 0, the code should work. In other words the following line should solve your issue:
fund_me.withdraw({"from": bad_actor,"gas_price":0,"gas_limit":12000000,"allow_revert":True})
Alternatively you can also replace bad_actor, by any other account in the accounts list (except account[0] the actual owner), for example, this line will also work:
fund_me.withdraw({"from": accounts[3],"gas_limit":12000000,"allow_revert":True})
_Note that the gaslimit has been fixed at 1200000 because above that, the test fails in the development network with the following message (this is linked to the default configuration of the development network) :
ValueError: Exceeds block gas limit
Exploring the problem
With regards to
the sender's account only has: 0
error, it might be a property of the method accounts.add() that the account created has a balance of 0 or a property of the network on which it is created, I am not sure. It might be possible to redefine this in the network config, but I didn't find any way to do it.My gut feeling is that the primary issue is linked to the default network config. https://eth-brownie.readthedocs.io/en/stable/config.html#config I believe that our ganache-local network has the default properties of a live network since it is not natively a development network. And as you can see in the link development and live network have differing properties such including the following:
gas_limit gas_buffer gas_price reverting_tx_gas_limit
My guess is that one or several of them are responsible for the problem. I tried to change the brownie-config.yaml to play with these parameters, but I am not sure if I am operating correctly.
It is possible that it is linked to the version of Ganache we work with. I work with Ganache 7.0.5, while I think the video was made with Ganache 6.x.x
Other useful advice
If you haven't try already, I suggest that you try to explore a bit with a debugger, it makes it easier to understand your issues. You might be luckier than me in finding a more satisfactory solution.
If you work with vscode you can create .vscode folder in your working folder (brownie_fund_me) and create the launch.json with the code below in it. It will allow you to debug your python code, and run some inline command to check your variables and all during code execution. Pretty useful for troubleshooting. You need to adapt "pythonPath" and "program" to your ownenvironment. Also, you may need to copy brownie.exe to be in the same folder as your brownie package folder. Let me know if you have any problem with that.
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Brownie Test", "type": "python", "request": "launch", "pythonPath": "D:/Anaconda3/envs/blockchain/python.exe", "program":"D:/Anaconda3/envs/blockchain/lib/site-packages/brownie.exe", "console": "integratedTerminal", "args": ["test","-s","--network","ganache-local"], }, { "name": "Brownie Debug", "type": "python", "request": "launch", "pythonPath": "D:/Anaconda3/envs/blockchain/python.exe", "program":"D:/Anaconda3/envs/blockchain/lib/site-packages/brownie.exe", "console": "integratedTerminal", "args": ["run","scripts/deploy.py","--network","ganache-local"], } ] }
Main questions
How to create a bad_actor account that is prefunded? Is the problem linked to the Ganache version? Is the error linked to the properties of the network, and if it is the case how to change them?
Thanks, @kthibault77 One of these two works for me.
fund_me.withdraw({"from": bad_actor,"gas_price":0,"gas_limit":12000000,"allow_revert":True})
OR
fund_me.withdraw({"from": accounts[3],"gas_limit":12000000,"allow_revert":True})
BTW, the ENV version for me as following:
OS Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy
Python3 Python 3.10.6
Pip pip 22.0.2
Brownie Brownie v1.19.2
Ganache-cli Ganache CLI v6.12.2
def test_only_owner_can_withdraw():
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip("only for local testing")
fund_me = deploy_fund_me()
bad_actor = accounts.add()
with pytest.raises(exceptions.VirtualMachineError):
fund_me.withdraw(
{
"from": bad_actor,
"gas_price": 0,
"gas_limit": 12000000,
"allow_revert": True,
}
)
OR
def test_only_owner_can_withdraw():
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip("only for local testing")
fund_me = deploy_fund_me()
bad_actor = accounts[1]
with pytest.raises(exceptions.VirtualMachineError):
fund_me.withdraw(
{"from": bad_actor, "gas_limit": 12000000, "allow_revert": True}
)
test_only_owner_can_withdraw
test fails even though the deploy fund_and_withdraw function runs perfectly. I get the error above when I run the test.The test that fails for ganache-local:
The error message turns into:
ValueError: Execution reverted during call: 'VM Exception while processing transaction: revert'. This transaction will likely revert. If you wish to broadcast, include
allow_revert:Trueas a transaction parameter.
Other useful files:
DECIMALS = 8 # Price feed aggregator usually returns 8 decimals STARTING_PRICE = 200000000000 # 2000 + 8 decimals LOCAL_ENVIRONMENTS = ["development", "ganache-local"] FORKED_LOCAL_ENVIRONMENTS = ["mainnet-fork", "mainnet-fork-dev"]
def get_account(): if ( network.show_active() in LOCAL_ENVIRONMENTS or network.show_active() in FORKED_LOCAL_ENVIRONMENTS ): return accounts[0] else: return accounts.add(config["wallets"]["from_key"])
def deploy_mocks(): if len(MockV3Aggregator) <= 0: print("deploying mock aggregator") mock_aggregator = MockV3Aggregator.deploy( DECIMALS, STARTING_PRICE, {"from": get_account()} ) print(f"deployed mock aggregator to address {mock_aggregator.address}")
from brownie import FundMe, config, network, MockV3Aggregator from scripts.helpers import get_account, deploy_mocks, LOCAL_ENVIRONMENTS
def deploy_fundme(): account = get_account() if network.show_active() not in LOCAL_ENVIRONMENTS:
def main(): deploy_fundme()
from brownie import FundMe, accounts
def fund(): fund_me = FundMe[-1] account = accounts[0] entrance_fee = fund_me.getEntranceFee() print("The current entrance fee is {entrance_fee}") fund_me.fund({"from": account, "value": entrance_fee})
def withdraw(): fund_me = FundMe[-1] account = accounts[0]
def main(): fund() withdraw()