From aca1dc73954cd9f671dfcab7b76f0d84894fb2c4 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Fri, 3 May 2024 14:36:40 +0200 Subject: [PATCH 1/2] Fix lack of fund errors --- tests/conftest.py | 4 ++-- .../examples/market_maker/test_on_chain_market_maker.py | 9 +++++++-- .../safe_remote_purchase/test_safe_remote_purchase.py | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2b645fc50d..420e1224ff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ from hexbytes import HexBytes import vyper.evm.opcodes as evm_opcodes -from tests.evm_backends.base_env import BaseEnv, EvmError +from tests.evm_backends.base_env import BaseEnv, ExecutionReverted from tests.evm_backends.pyevm_env import PyEvmEnv from tests.evm_backends.revm_env import RevmEnv from tests.utils import working_directory @@ -314,7 +314,7 @@ def assert_side_effects_invoked(side_effects_contract, side_effects_trigger, n=1 @pytest.fixture(scope="module") def tx_failed(env): @contextmanager - def fn(exception=EvmError, exc_text=None): + def fn(exception=ExecutionReverted, exc_text=None): with pytest.raises(exception) as excinfo: yield diff --git a/tests/functional/examples/market_maker/test_on_chain_market_maker.py b/tests/functional/examples/market_maker/test_on_chain_market_maker.py index d9f77c8d68..d867266beb 100644 --- a/tests/functional/examples/market_maker/test_on_chain_market_maker.py +++ b/tests/functional/examples/market_maker/test_on_chain_market_maker.py @@ -14,9 +14,11 @@ def erc20(get_contract): with open("examples/tokens/ERC20.vy") as f: contract_code = f.read() - return get_contract( + contract = get_contract( contract_code, *[TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS, TOKEN_INITIAL_SUPPLY] ) + print("Deployed ERC20 to " + contract.address) + return contract @pytest.fixture(scope="module") @@ -27,6 +29,7 @@ def market_maker(get_contract, erc20): def test_initial_state(market_maker): + print("Starting test_initial_state") assert market_maker.totalEthQty() == 0 assert market_maker.totalTokenQty() == 0 assert market_maker.invariant() == 0 @@ -34,9 +37,10 @@ def test_initial_state(market_maker): def test_initiate(env, market_maker, erc20, tx_failed): + print("Starting test_initiate") a0 = env.accounts[0] ether, ethers = to_wei(1, "ether"), to_wei(2, "ether") - env.set_balance(a0, ethers) + env.set_balance(a0, ethers * 2) erc20.approve(market_maker.address, ethers) market_maker.initiate(erc20.address, ether, value=ethers) assert market_maker.totalEthQty() == ethers @@ -52,6 +56,7 @@ def test_initiate(env, market_maker, erc20, tx_failed): def test_eth_to_tokens(env, market_maker, erc20): + print("Starting test_eth_to_tokens") a0, a1 = env.accounts[:2] env.set_balance(a0, to_wei(2, "ether")) erc20.approve(market_maker.address, to_wei(2, "ether")) diff --git a/tests/functional/examples/safe_remote_purchase/test_safe_remote_purchase.py b/tests/functional/examples/safe_remote_purchase/test_safe_remote_purchase.py index c278d6090e..c4cfdc29eb 100644 --- a/tests/functional/examples/safe_remote_purchase/test_safe_remote_purchase.py +++ b/tests/functional/examples/safe_remote_purchase/test_safe_remote_purchase.py @@ -33,10 +33,10 @@ def get_balance(): def test_initial_state(env, tx_failed, get_contract, get_balance, contract_code): + env.set_balance(env.deployer, to_wei(2, "ether")) # Initial deposit has to be divisible by two with tx_failed(): get_contract(contract_code, value=13) - env.set_balance(env.deployer, to_wei(2, "ether")) # Seller puts item up for sale a0_pre_bal, a1_pre_bal = get_balance() c = get_contract(contract_code, value=to_wei(2, "ether")) @@ -73,8 +73,8 @@ def test_abort(env, tx_failed, get_balance, get_contract, contract_code): def test_purchase(env, get_contract, tx_failed, get_balance, contract_code): a0, a1, a2, a3 = env.accounts[:4] - env.set_balance(a0, 10**18) - env.set_balance(a1, 10**18) + for a in env.accounts[:4]: + env.set_balance(a, 10**18) init_bal_a0, init_bal_a1 = get_balance() c = get_contract(contract_code, value=2) From 70cea123f6a7f19b57e5ef325d3305391660871d Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Fri, 3 May 2024 14:40:21 +0200 Subject: [PATCH 2/2] Remove prints --- .../examples/market_maker/test_on_chain_market_maker.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/functional/examples/market_maker/test_on_chain_market_maker.py b/tests/functional/examples/market_maker/test_on_chain_market_maker.py index d867266beb..9dddc37ceb 100644 --- a/tests/functional/examples/market_maker/test_on_chain_market_maker.py +++ b/tests/functional/examples/market_maker/test_on_chain_market_maker.py @@ -14,11 +14,9 @@ def erc20(get_contract): with open("examples/tokens/ERC20.vy") as f: contract_code = f.read() - contract = get_contract( + return get_contract( contract_code, *[TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS, TOKEN_INITIAL_SUPPLY] ) - print("Deployed ERC20 to " + contract.address) - return contract @pytest.fixture(scope="module") @@ -29,7 +27,6 @@ def market_maker(get_contract, erc20): def test_initial_state(market_maker): - print("Starting test_initial_state") assert market_maker.totalEthQty() == 0 assert market_maker.totalTokenQty() == 0 assert market_maker.invariant() == 0 @@ -37,7 +34,6 @@ def test_initial_state(market_maker): def test_initiate(env, market_maker, erc20, tx_failed): - print("Starting test_initiate") a0 = env.accounts[0] ether, ethers = to_wei(1, "ether"), to_wei(2, "ether") env.set_balance(a0, ethers * 2) @@ -56,7 +52,6 @@ def test_initiate(env, market_maker, erc20, tx_failed): def test_eth_to_tokens(env, market_maker, erc20): - print("Starting test_eth_to_tokens") a0, a1 = env.accounts[:2] env.set_balance(a0, to_wei(2, "ether")) erc20.approve(market_maker.address, to_wei(2, "ether"))