Initial commit; receive all eth code from chainlib package

This commit is contained in:
nolash
2021-06-28 07:48:36 +02:00
commit f8afc172c6
59 changed files with 4535 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from .fixtures_ethtester import *
from .fixtures_chain import *
from .fixtures_signer import *

View 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,
}

View 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

View 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],
}