Skip to content

Commit

Permalink
test: hardhat compatibility (#268)
Browse files Browse the repository at this point in the history
* test: hardhat compatibility

* test: fix for hardhat timestamp drift
  • Loading branch information
banteg authored Apr 19, 2021
1 parent f97088d commit 67cf46f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand All @@ -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",
Expand Down Expand Up @@ -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:
Expand All @@ -170,7 +174,7 @@ def sign_vault_permit(
"domain": {
"name": name,
"version": version,
"chainId": chain_id,
"chainId": chain_id(),
"verifyingContract": str(vault),
},
"primaryType": "Permit",
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/strategy/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 67cf46f

Please sign in to comment.