Skip to content

Commit

Permalink
fix(test): anvil behavior changed with --block-base-fee-per-gas (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz authored Mar 7, 2024
1 parent 0b6b55f commit 204b143
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
17 changes: 16 additions & 1 deletion tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,26 @@ def test_base_fee(connected_provider, temp_config, networks, accounts):
data = {"foundry": {"base_fee": new_base_fee, "host": "http://127.0.0.1:8555"}}
with temp_config(data):
with networks.ethereum.local.use_provider("foundry") as provider:
assert provider.base_fee == new_base_fee
# Verify the block has the right base fee
block_one = provider.get_block("latest")
assert block_one.base_fee == new_base_fee

# Make sure the command has the right base fee
cmd = provider.build_command()
idx = -1
for i, part in enumerate(cmd):
if part == "--block-base-fee-per-gas":
idx = i + 1
assert idx > -1 # option was found
assert cmd[idx] == str(new_base_fee) # option val is correct

# Show can transact with this base_fee
acct1.transfer(acct2, "1 eth")

# Verify the block still has the right base fee
block_two = provider.get_block("latest")
assert block_two.base_fee == new_base_fee


def test_auto_mine(connected_provider):
assert connected_provider.auto_mine is True
Expand Down
14 changes: 10 additions & 4 deletions tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def run_gas_test(result, expected_report: str = EXPECTED_GAS_REPORT):


@pytest.mark.fork
def test_gas_flag_in_tests(ape_pytester):
result = ape_pytester.runpytest("--gas")
def test_gas_flag_in_tests(ape_pytester, sender):
result = ape_pytester.runpytest("--gas", "--network", "ethereum:local:foundry")
run_gas_test(result)

# Verify can happen more than once.
Expand All @@ -101,7 +101,13 @@ def test_gas_flag_exclude_method_using_cli_option(ape_pytester):
expected = filter_expected_methods("fooAndBar", "myNumber")
# Also ensure can filter out whole class
expected = expected.replace(TOKEN_B_GAS_REPORT, "")
result = ape_pytester.runpytest("--gas", "--gas-exclude", "*:fooAndBar,*:myNumber,tokenB:*")
result = ape_pytester.runpytest(
"--gas",
"--gas-exclude",
"*:fooAndBar,*:myNumber,tokenB:*",
"--network",
"ethereum:local:foundry",
)
run_gas_test(result, expected_report=expected)


Expand All @@ -112,7 +118,7 @@ def test_coverage(ape_pytester):
verifying Foundry in coverage.
TODO: Write + Run tests in an env with both vyper and foundry.
"""
result = ape_pytester.runpytest("--coverage")
result = ape_pytester.runpytest("--coverage", "--network", "ethereum:local:foundry")
result.assert_outcomes(passed=NUM_TESTS)
assert any("Coverage Profile" in ln for ln in result.outlines)
assert any("WARNING: No coverage data found." in ln for ln in result.outlines)

0 comments on commit 204b143

Please sign in to comment.