0

I'm trying to test an onlyOwner function on goerli testnet which's expected to be passed with pytest.raises(exceptions.VirtualMachineError) but it keeps getting below error. I added priority_fee and max_fee to the transaction and set_the_gas_limit_manually: True and gas_limit: 300000000 to my brownie-config.yaml file but it keeps throwing the below error and I can't find out where I set sth wrong or what I missed. Any help would be appreciated, Thanks.

Terminal: cmd, python version: 3.10.6, pytest version: 7.1.3

This is the solidity function:

function setTokensData(
        address _token,
        uint8 _rate,
        address _priceFeed
    ) public onlyOwner {
        tokensToRate[_token] = _rate;
        tokensToPriceFeed[_token] = _priceFeed;
        tokenIsApproved[_token] = true;
    }

This is my python test script:

from brownie import network, exceptions, accounts, chain, config, Staking, KoalaToken
from scripts.helpful_scripts import (
    LOCAL_BLOCKCHAIN_ENVIRONMENTS,
    get_contract,
    get_account,
)
from scripts.deploy import (
    deploy_KoalaToken_and_Staking,
)
import pytest
from web3 import Web3


def test_only_owner_can_set_tokens_data():
    # Arrange
    if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
        pytest.skip()
    account = accounts.add(config["wallets"]["from_key_non_owner"])
    link_token = get_contract("link_token")
    link_usd_price_feed = get_contract("link_usd_price_feed")
    rate = 2
    staking = Staking[-1]
    koala_token = KoalaToken[-1]
    # Act & Assert
    with pytest.raises(exceptions.VirtualMachineError):
        staking.setTokensData(
            link_token,
            rate,
            link_usd_price_feed,
            {
                "from": account,
                "allow_revert": True,
                "priority_fee": 3000000000,
                "max_fee": 15716213,
            },
        )

This is the thrown error:

    ...\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1861: in __call__
        return self.transact(*args)
    ...\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py:1734: in transact
        return tx["from"].transfer(
    ...\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py:644: in transfer
        receipt, exc = self._make_transaction(
    ...\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py:727: in _make_transaction
        raise VirtualMachineError(e) from None
            
self = VirtualMachineError(ValueError("Gas estimation failed: 'execution reverted: Ownable: caller is not the owner'. This transaction will likely revert. If 
        you wish to broadcast, you must set the gas limit manually."))
        exc = "Gas estimation failed: 'execution reverted: Ownable: caller is not the owner'. This transaction will likely revert. If you wish to broadcast, you must 
        set the gas limit manually."
        
            def __init__(self, exc: ValueError) -> None:
                    self.txid: str = ""
                    self.source: str = ""
                    self.revert_type: str = ""
                    self.pc: Optional[int] = None
                    self.revert_msg: Optional[str] = None
                    self.dev_revert_msg: Optional[str] = None
            
                    try:
                        exc = exc.args[0]
                    except Exception:
                        pass
            
                    if not (isinstance(exc, dict) and "message" in exc):
            >           raise ValueError(str(exc)) from None
            E           ValueError: Gas estimation failed: 'execution reverted: Ownable: caller is not the owner'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

1 Answer 1

0

Use some of the gas modifying and setting techniques here:

https://eth-brownie.readthedocs.io/en/stable/core-gas.html

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.