Пример #1
0
def _make_testerchain(mock_backend: bool = False) -> TesterBlockchain:
    """
    https://github.com/ethereum/eth-tester     # available-backends
    """
    # Monkey patch to prevent gas adjustment
    import eth
    eth._utils.headers.GAS_LIMIT_MINIMUM = TEST_GAS_LIMIT
    eth._utils.headers.GENESIS_GAS_LIMIT = TEST_GAS_LIMIT
    eth.vm.forks.frontier.headers.GENESIS_GAS_LIMIT = TEST_GAS_LIMIT

    # Monkey patch to prevent gas estimates
    def _get_buffered_gas_estimate(web3, transaction, gas_buffer=100000):
        return TEST_GAS_LIMIT

    import web3
    web3.eth.get_buffered_gas_estimate = _get_buffered_gas_estimate

    # Create the blockchain
    if mock_backend:
        testerchain = MockBlockchain()
    else:
        testerchain = TesterBlockchain(eth_airdrop=True,
                                       free_transactions=True)

    return testerchain
Пример #2
0
from enum import Enum

from constant_sorrow.constants import (CONTRACT_ATTRIBUTE, CONTRACT_CALL,
                                       TRANSACTION)
from hexbytes import HexBytes
from typing import Callable, Generator, Iterable, List, Type, Union
from unittest.mock import Mock

from nucypher.blockchain.eth import agents
from nucypher.blockchain.eth.agents import Agent, ContractAgency, EthereumContractAgent
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from tests.constants import MOCK_ETH_PROVIDER_URI
from tests.mock.interfaces import MockBlockchain

MOCK_TESTERCHAIN = MockBlockchain()
CACHED_MOCK_TESTERCHAIN = BlockchainInterfaceFactory.CachedInterface(
    interface=MOCK_TESTERCHAIN, emitter=None)
BlockchainInterfaceFactory._interfaces[
    MOCK_ETH_PROVIDER_URI] = CACHED_MOCK_TESTERCHAIN

CURRENT_BLOCK = MOCK_TESTERCHAIN.w3.eth.getBlock('latest')


class MockContractAgent:

    FAKE_TX_HASH = HexBytes(b'FAKE29890FAKE8349804')

    FAKE_RECEIPT = {
        'transactionHash': FAKE_TX_HASH,
        'gasUsed': 1,