Split index interface and registry implementation

This commit is contained in:
nolash
2021-04-30 12:46:53 +02:00
parent 6aa5da01bd
commit 9363ed3bfb
7 changed files with 168 additions and 118 deletions

View File

@@ -7,6 +7,7 @@ import logging
# external imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.connection import RPCConnection
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.address import to_checksum_address
from chainlib.eth.tx import (
receipt,
@@ -19,7 +20,8 @@ from chainlib.eth.contract import (
)
# local imports
from eth_accounts_index import AccountRegistry
from eth_accounts_index.registry import AccountRegistry
from eth_accounts_index import AccountsIndex
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -44,8 +46,8 @@ class Test(EthTesterCase):
def setUp(self):
super(Test, self).setUp()
nonce_oracle = TestNonceOracle(self.accounts[0])
self.o = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = self.o.constructor(self.accounts[0])
c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.constructor(self.accounts[0])
self.conn = RPCConnection.connect(self.chain_spec, 'default')
r = self.conn.do(o)
logg.debug('deployed with hash {}'.format(r))
@@ -54,7 +56,7 @@ class Test(EthTesterCase):
r = self.conn.do(o)
self.address = to_checksum_address(r['contract_address'])
(tx_hash, o) = self.o.add_writer(self.address, self.accounts[0], self.accounts[0])
(tx_hash, o) = c.add_writer(self.address, self.accounts[0], self.accounts[0])
r = self.conn.do(o)
o = receipt(r)
@@ -63,17 +65,21 @@ class Test(EthTesterCase):
def test_1_count(self):
o = self.o.count(self.address, sender_address=self.accounts[0])
#o = self.o.count(self.address, sender_address=self.accounts[0])
c = AccountsIndex(self.chain_spec)
o = c.entry_count(self.address, sender_address=self.accounts[0])
r = self.conn.do(o)
r = abi_decode_single(ABIContractType.UINT256, r)
self.assertEqual(r, 1)
self.assertEqual(r, 0)
def test_2_add(self):
b = os.urandom(20)
a = to_checksum_address(b.hex())
(tx_hash, o) = self.o.add(self.address, self.accounts[0], a)
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.add(self.address, self.accounts[0], a)
r = self.conn.do(o)
self.assertEqual(tx_hash, r)
@@ -81,7 +87,7 @@ class Test(EthTesterCase):
rcpt = self.conn.do(o)
self.helper.mine_block()
o = self.o.have(self.address, a, sender_address=self.accounts[0])
o = c.have(self.address, a, sender_address=self.accounts[0])
r = self.conn.do(o)
@@ -89,7 +95,9 @@ class Test(EthTesterCase):
b = os.urandom(20)
a = to_checksum_address(b.hex())
(tx_hash, o) = self.o.add(self.address, self.accounts[0], a, tx_format=TxFormat.RLP_SIGNED)
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.add(self.address, self.accounts[0], a, tx_format=TxFormat.RLP_SIGNED)
#r = self.conn.do(o)
#self.assertEqual(tx_hash, r)
logg.debug('o {}'.format(o))