0

I am using brownie to interact with my Ethereum smart contracts. The scripts and tests are located in parallel scripts/ and test/ folders. How can I access the functions from scripts/ in test/ files?

enter image description here

Unfortunately relative imports do not work.

from ..scripts.helper import get_account
from ..scripts.deploy_fund_me import deploy_fund_me


def test_stake_and_withdraw():
    account = get_account()
    fund_me = deploy_fund_me()
    entry_fee = fund_me.getEntryFee()
    tx = fund_me.stake({"from": account, "value": entry_fee})
    tx.wait(1)
    assert (
        fund_me.fundsByStaker(account.address) == entry_fee
    ), f"{account.address}'s staking failed!"

The tests are run using the brownie test command from the brownie_demo/ project's location. Using from scripts.helper import get_account does not work as well.

1 Answer 1

1

Add a __init__.py file in your scripts folder.

For reference on python modules

Your Answer

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

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