1

Struggling with testing my withdraw function in a Solidity smart-contract via Brownie:

My withdrawing function is the following but in Remix it definitely works and I have tested _owner.send() and _owner.transfer() as well and both work so it has to be the test but I can not see where my error lays.

function withdrawMoney() external onlyOwner returns (bool) {
    (success, response) = _owner.call{value: address(this).balance}("");
    return success;
}

Below the brownie test that does not work. The prints and other stuff should be explained in the comments.

def test_can_withdraw():

   # ARRANGE
   buy_coffee = deploy_buycoffee()  # works fine as contract is deployed

   # ACT
   print("Before: ", buy_coffee.balance())  # Before:  0

   tx = send_money()  # works fine as tested by sending {"from": get_account(account_index=1)}

   tx.wait(1)
   print("During: ", buy_coffee.balance())  # During:  1000000000000000

   tx = buy_coffee.withdrawMoney({"from": get_account(account_index=0)})  # BROKEN!

   tx.wait(1)
   print("After: ", buy_coffee.balance())  # should be 0 but is 1000000000000000

   # ASSERT
   assert buy_coffee.balance() == 0
4
  • Have you tried setting the gas by hand? One never knows...
    – Kiuhnm
    Dec 17, 2022 at 5:50
  • I have not but does that mean you would deem my test to be set up correctly on first glance?
    – emilrueh
    Dec 20, 2022 at 16:29
  • I don't use brownie, so I can't really say, but since nobody answered, it seems others can't either. You should give more information or even upload something to play with. Trying to come up with a minimal (not) working example might even reveal the solution right away.
    – Kiuhnm
    Dec 21, 2022 at 22:56
  • I have discontinued this project, thank you for your suggestion though! Might get back to it at some point..
    – emilrueh
    Jan 16 at 18:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.