Initial commit; receive all eth code from chainlib package
This commit is contained in:
3
chainlib/eth/pytest/__init__.py
Normal file
3
chainlib/eth/pytest/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .fixtures_ethtester import *
|
||||
from .fixtures_chain import *
|
||||
from .fixtures_signer import *
|
||||
17
chainlib/eth/pytest/fixtures_chain.py
Normal file
17
chainlib/eth/pytest/fixtures_chain.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# external imports
|
||||
import pytest
|
||||
|
||||
# local imports
|
||||
from chainlib.chain import ChainSpec
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def default_chain_spec():
|
||||
return ChainSpec('evm', 'foo', 42)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def default_chain_config():
|
||||
return {
|
||||
'foo': 42,
|
||||
}
|
||||
105
chainlib/eth/pytest/fixtures_ethtester.py
Normal file
105
chainlib/eth/pytest/fixtures_ethtester.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
import eth_tester
|
||||
import pytest
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
|
||||
# local imports
|
||||
from chainlib.eth.unittest.base import *
|
||||
from chainlib.connection import (
|
||||
RPCConnection,
|
||||
ConnType,
|
||||
)
|
||||
from chainlib.eth.unittest.ethtester import create_tester_signer
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
|
||||
logg = logging.getLogger() #__name__)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def eth_keystore():
|
||||
return DictKeystore()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def init_eth_tester(
|
||||
eth_keystore,
|
||||
):
|
||||
return create_tester_signer(eth_keystore)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def call_sender(
|
||||
eth_accounts,
|
||||
):
|
||||
return eth_accounts[0]
|
||||
#
|
||||
#
|
||||
#@pytest.fixture(scope='function')
|
||||
#def eth_signer(
|
||||
# init_eth_tester,
|
||||
# ):
|
||||
# return init_eth_tester
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def eth_rpc(
|
||||
default_chain_spec,
|
||||
init_eth_rpc,
|
||||
):
|
||||
return RPCConnection.connect(default_chain_spec, 'default')
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def eth_accounts(
|
||||
init_eth_tester,
|
||||
):
|
||||
addresses = list(init_eth_tester.get_accounts())
|
||||
for address in addresses:
|
||||
balance = init_eth_tester.get_balance(address)
|
||||
logg.debug('prefilled account {} balance {}'.format(address, balance))
|
||||
return addresses
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def eth_empty_accounts(
|
||||
eth_keystore,
|
||||
init_eth_tester,
|
||||
):
|
||||
a = []
|
||||
for i in range(10):
|
||||
#address = init_eth_tester.new_account()
|
||||
address = eth_keystore.new()
|
||||
checksum_address = add_0x(to_checksum_address(address))
|
||||
a.append(checksum_address)
|
||||
logg.info('added address {}'.format(checksum_address))
|
||||
return a
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def eth_signer(
|
||||
eth_keystore,
|
||||
):
|
||||
return EIP155Signer(eth_keystore)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def init_eth_rpc(
|
||||
default_chain_spec,
|
||||
init_eth_tester,
|
||||
eth_signer,
|
||||
):
|
||||
|
||||
rpc_conn = TestRPCConnection(None, init_eth_tester, eth_signer)
|
||||
def rpc_with_tester(url=None, chain_spec=default_chain_spec):
|
||||
return rpc_conn
|
||||
|
||||
RPCConnection.register_constructor(ConnType.CUSTOM, rpc_with_tester, tag='default')
|
||||
RPCConnection.register_constructor(ConnType.CUSTOM, rpc_with_tester, tag='signer')
|
||||
RPCConnection.register_location('custom', default_chain_spec, tag='default', exist_ok=True)
|
||||
RPCConnection.register_location('custom', default_chain_spec, tag='signer', exist_ok=True)
|
||||
return None
|
||||
18
chainlib/eth/pytest/fixtures_signer.py
Normal file
18
chainlib/eth/pytest/fixtures_signer.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# standard imports
|
||||
#import os
|
||||
|
||||
# external imports
|
||||
import pytest
|
||||
#from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def agent_roles(
|
||||
eth_accounts,
|
||||
):
|
||||
return {
|
||||
'ALICE': eth_accounts[20],
|
||||
'BOB': eth_accounts[21],
|
||||
'CAROL': eth_accounts[23],
|
||||
'DAVE': eth_accounts[24],
|
||||
}
|
||||
Reference in New Issue
Block a user