mirror of https://github.com/nucypher/nucypher.git
handles importing of test packages in production builds
parent
cc23931c37
commit
783664a173
|
@ -8,16 +8,9 @@ import requests
|
|||
from atxm import AutomaticTxMachine
|
||||
from atxm.tx import AsyncTx
|
||||
from constant_sorrow.constants import (
|
||||
INSUFFICIENT_FUNDS,
|
||||
NO_BLOCKCHAIN_CONNECTION,
|
||||
UNKNOWN_TX_STATUS,
|
||||
)
|
||||
from eth_tester import EthereumTester
|
||||
from eth_tester.exceptions import (
|
||||
TransactionFailed as TestTransactionFailed,
|
||||
)
|
||||
from eth_tester.exceptions import (
|
||||
ValidationError,
|
||||
INSUFFICIENT_FUNDS, # noqa
|
||||
NO_BLOCKCHAIN_CONNECTION, # noqa
|
||||
UNKNOWN_TX_STATUS, # noqa
|
||||
)
|
||||
from eth_utils import to_checksum_address
|
||||
from hexbytes.main import HexBytes
|
||||
|
@ -50,7 +43,7 @@ from nucypher.utilities.gas_strategies import (
|
|||
from nucypher.utilities.logging import Logger
|
||||
|
||||
Web3Providers = Union[
|
||||
IPCProvider, WebsocketProvider, HTTPProvider, EthereumTester
|
||||
IPCProvider, WebsocketProvider, HTTPProvider
|
||||
] # TODO: Move to types.py
|
||||
|
||||
|
||||
|
@ -540,7 +533,7 @@ class BlockchainInterface:
|
|||
payload, block_identifier="latest"
|
||||
)
|
||||
transaction_dict = contract_function.build_transaction(payload)
|
||||
except (TestTransactionFailed, ValidationError, ValueError) as error:
|
||||
except ValueError as error:
|
||||
# Note: Geth (1.9.15) raises ValueError in the same condition that pyevm raises ValidationError here.
|
||||
# Treat this condition as "Transaction Failed" during gas estimation.
|
||||
raise self._handle_failed_transaction(
|
||||
|
@ -610,7 +603,7 @@ class BlockchainInterface:
|
|||
signed_transaction.rawTransaction
|
||||
) # <--- BROADCAST
|
||||
emitter.message(f"TXHASH {txhash.hex()}", color="yellow")
|
||||
except (TestTransactionFailed, ValueError):
|
||||
except ValueError:
|
||||
raise # TODO: Unify with Transaction failed handling -- Entry point for _handle_failed_transaction
|
||||
|
||||
#
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
from typing import Union
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from eth_tester import EthereumTester, PyEVMBackend
|
||||
from eth_tester.backends.mock.main import MockBackend
|
||||
from web3 import HTTPProvider, IPCProvider, WebsocketProvider
|
||||
from web3.providers import BaseProvider
|
||||
from web3.providers.eth_tester.main import EthereumTesterProvider
|
||||
|
||||
from nucypher.exceptions import DevelopmentInstallationRequired
|
||||
|
||||
|
@ -49,7 +45,8 @@ def _get_auto_provider(endpoint) -> BaseProvider:
|
|||
return w3.provider
|
||||
|
||||
|
||||
def _get_pyevm_test_backend() -> PyEVMBackend:
|
||||
def _get_pyevm_test_backend():
|
||||
|
||||
try:
|
||||
# TODO: Consider packaged support of --dev mode with testerchain
|
||||
from tests.constants import NUMBER_OF_ETH_TEST_ACCOUNTS, PYEVM_GAS_LIMIT
|
||||
|
@ -57,13 +54,21 @@ def _get_pyevm_test_backend() -> PyEVMBackend:
|
|||
raise DevelopmentInstallationRequired(importable_name='tests.constants')
|
||||
|
||||
# Initialize
|
||||
from eth_tester import PyEVMBackend
|
||||
genesis_params = PyEVMBackend._generate_genesis_params(overrides={'gas_limit': PYEVM_GAS_LIMIT})
|
||||
pyevm_backend = PyEVMBackend(genesis_parameters=genesis_params)
|
||||
pyevm_backend.reset_to_genesis(genesis_params=genesis_params, num_accounts=NUMBER_OF_ETH_TEST_ACCOUNTS)
|
||||
return pyevm_backend
|
||||
|
||||
|
||||
def _get_ethereum_tester(test_backend: Union[PyEVMBackend, MockBackend]) -> EthereumTesterProvider:
|
||||
def _get_ethereum_tester(test_backend):
|
||||
try:
|
||||
from eth_tester import EthereumTester
|
||||
from web3.providers.eth_tester.main import EthereumTesterProvider
|
||||
except ImportError:
|
||||
raise DevelopmentInstallationRequired(
|
||||
importable_name="web3.providers.eth_tester"
|
||||
)
|
||||
eth_tester = EthereumTester(backend=test_backend, auto_mine_transactions=True)
|
||||
provider = EthereumTesterProvider(ethereum_tester=eth_tester)
|
||||
return provider
|
||||
|
@ -79,6 +84,10 @@ def _get_pyevm_test_provider(endpoint) -> BaseProvider:
|
|||
|
||||
def _get_mock_test_provider(endpoint) -> BaseProvider:
|
||||
# https://github.com/ethereum/eth-tester#mockbackend
|
||||
try:
|
||||
from eth_tester import MockBackend
|
||||
except ImportError:
|
||||
raise DevelopmentInstallationRequired(importable_name="eth_tester.MockBackend")
|
||||
mock_backend = MockBackend()
|
||||
provider = _get_ethereum_tester(test_backend=mock_backend)
|
||||
return provider
|
||||
|
|
|
@ -2,7 +2,6 @@ from copy import copy
|
|||
from unittest import mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from eth_tester.exceptions import ValidationError
|
||||
from nucypher_core import NodeMetadata
|
||||
|
||||
from nucypher.blockchain.eth.signers.software import Web3Signer
|
||||
|
@ -120,6 +119,12 @@ class Vladimir(Ursula):
|
|||
"""
|
||||
Upload Vladimir's ETH keys to the keychain via web3.
|
||||
"""
|
||||
try:
|
||||
from eth_tester.exceptions import ValidationError
|
||||
except ImportError:
|
||||
raise DevelopmentInstallationRequired(
|
||||
importable_name="eth_tester.exceptions.ValidationError"
|
||||
)
|
||||
try:
|
||||
password = 'iamverybadass'
|
||||
blockchain.w3.provider.ethereum_tester.add_account(cls.fraud_key, password=password)
|
||||
|
|
Loading…
Reference in New Issue