Skip to content

Commit

Permalink
test: hardhat compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
banteg committed Apr 7, 2021
1 parent c8f0e5a commit ed027fa
Showing 1 changed file with 9 additions and 5 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

0 comments on commit ed027fa

Please sign in to comment.