From ab95c5b76de44057bd1257927801c5f3ab503125 Mon Sep 17 00:00:00 2001 From: banteg Date: Mon, 19 Apr 2021 22:57:01 +0300 Subject: [PATCH] test: hardhat compatibility (#268) * test: hardhat compatibility * test: fix for hardhat timestamp drift --- tests/conftest.py | 14 +++++++++----- tests/functional/strategy/test_misc.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ef588cdf..2ed537e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ from eth_account import Account from eth_account.messages import encode_structured_data -from brownie import compile_source, Token, Vault +from brownie import compile_source, Token, Vault, web3, chain PACKAGE_VERSION = yaml.safe_load( (Path(__file__).parents[1] / "ethpm-config.yaml").read_text() @@ -82,6 +82,12 @@ def patch_vault_version(version): return patch_vault_version +def chain_id(): + # BUG: ganache-cli provides mismatching chain.id and chainid() + # https://github.com/trufflesuite/ganache/issues/1643 + return 1 if web3.clientVersion.startswith("EthereumJS") else chain.id + + @pytest.fixture def sign_token_permit(): def sign_token_permit( @@ -92,7 +98,6 @@ def sign_token_permit( deadline: int = 0, # 0 means no time limit override_nonce: int = None, ): - chain_id = 1 # ganache bug https://github.com/trufflesuite/ganache/issues/1643 if override_nonce: nonce = override_nonce else: @@ -116,7 +121,7 @@ def sign_token_permit( "domain": { "name": token.name(), "version": "1", - "chainId": chain_id, + "chainId": chain_id(), "verifyingContract": str(token), }, "primaryType": "Permit", @@ -146,7 +151,6 @@ def sign_vault_permit( ): name = "Yearn Vault" version = vault.apiVersion() - chain_id = 1 # ganache bug https://github.com/trufflesuite/ganache/issues/1643 if override_nonce: nonce = override_nonce else: @@ -170,7 +174,7 @@ def sign_vault_permit( "domain": { "name": name, "version": version, - "chainId": chain_id, + "chainId": chain_id(), "verifyingContract": str(vault), }, "primaryType": "Permit", diff --git a/tests/functional/strategy/test_misc.py b/tests/functional/strategy/test_misc.py index dc7a0d8c..d5ec3c92 100644 --- a/tests/functional/strategy/test_misc.py +++ b/tests/functional/strategy/test_misc.py @@ -44,13 +44,13 @@ def test_harvest_tend_trigger(chain, gov, vault, token, TestStrategy): # Check that trigger works if gas costs is less than profitFactor profit = 10 ** token.decimals() token.transfer(strategy, profit, {"from": gov}) - chain.mine(timedelta=strategy.minReportDelay()) + chain.mine(timedelta=strategy.minReportDelay() + 5) assert not strategy.harvestTrigger(profit // strategy.profitFactor()) assert strategy.harvestTrigger(profit // strategy.profitFactor() - 1) strategy.harvest({"from": gov}) # Check that trigger works if strategy is in debt using debt threshold - chain.mine(timedelta=strategy.minReportDelay()) + chain.mine(timedelta=strategy.minReportDelay() + 5) assert vault.debtOutstanding(strategy) == 0 vault.revokeStrategy(strategy, {"from": gov}) assert vault.debtOutstanding(strategy) > strategy.debtThreshold()