full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

Lesson 6: testing error when testing for bad actor withdrawal

Open kthibault77 opened this issue 2 years ago • 0 comments

I noted that another user had the same problem. I leave the description below because it is useful, but I invite you to check the following thread for more discussion and info: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/issues/1423

Hello,

I am going through Lesson 6 and run into the following error during testing of withdrawal by the bad_actor account when working on the ganache-local network.

As a preamble I signal that:

  • The exact same testing passes on the development network. (i.e. the transaction is reverted as expected)
  • the fund_and_withdraw.py scripts runs normally on the local-ganache network and development network.
  • Ganache version: ganache v7.0.5 (@ganache/cli: 0.1.6, @ganache/core: 0.1.6)
  • Brownie version: Brownie v1.18.1
  • I am runnning on a conda environment and working with VS Code.

When testing withdrawal by a bad_actor i.e. fund_me.withdraw({"from":bad_actor}) on the ganache-local network the test fails and returns the following error:

D:\Anaconda3\envs\blockchain\lib\site-packages\brownie\network\contract.py:1710: in call return self.transact(*args) D:\Anaconda3\envs\blockchain\lib\site-packages\brownie\network\contract.py:1583: in transact return tx["from"].transfer( D:\Anaconda3\envs\blockchain\lib\site-packages\brownie\network\account.py:644: in transfer receipt, exc = self._make_transaction( D:\Anaconda3\envs\blockchain\lib\site-packages\brownie\network\account.py:727: in _make_transaction raise VirtualMachineError(e) from None


self = VirtualMachineError(ValueError("Gas estimation failed: 'VM Exception while processing transaction: revert'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually."))

I did some further exploring using the VSCode debugger, and noted the following:

  1. I don't think this is necessarily linked to this error, but it sorta bugs me that bad_actor (generated through accounts.add() method) has a balance of 0. Even in the eventuality that the transaction passes, how can they even pay the gas fees? However bad_actor.balance() is 0 even when I run the test succefully on the development network.

  2. I set a breakpoint right before the faulty transaction in the test file to do some testing, and it appears that fund_me.withdraw({"from": accounts[0]}) works just fine. As expected since accounts[0] is the owner. On the other hand fund_me.withdraw({"from": accounts[2]}) for example gives the exact same error as fund_me.withdraw({"from":bad_actor}). I am therefore left thinking that this is just normal behavior: those transactions are not supposed to pass anyway and the "error" is just pointing that they are reverted. Is that the case? If yes, why is it a different error on my ganache-local network than on my development network? Is there a way to include this error in the test so that it passes successfully when it encounters it?

I have seen problems with similar error messages before raised in here, but I believe that I have narrowed it down to something I haven't seen before. Most of what I have seen before were errors linked to the MockV3Aggregator answer, and those I also ran into but I already solved (I have a line that prints the entrance_fee, and the fund_me.getPrice(), to check that they are consistent, which they are). And I am left with this "error", which only occurs when testing for non owner withdrawal on ganache-local.

Thanking you for your help. And thanks for that amazing tutorial, it is really interesting. Let me know if you need more info.

All the best

PS: here is the code for the test. I usually write along with the video, so that there shouldn't be any major difference. The error occurs on the last line. image

kthibault77 avatar Apr 25 '22 04:04 kthibault77