Patch unnormalized address in query to chainqueue

This commit is contained in:
nolash 2021-10-20 14:31:02 +02:00
parent 574ddcba1a
commit 786e1a6029
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 22 additions and 13 deletions

View File

@ -8,6 +8,7 @@ from chainlib.error import JSONRPCException
from chainqueue.enum import StatusBits from chainqueue.enum import StatusBits
from chainqueue.sql.query import count_tx from chainqueue.sql.query import count_tx
from hexathon import strip_0x from hexathon import strip_0x
from chainqueue.encode import TxNormalizer
#logg = logging.getLogger(__name__) #logg = logging.getLogger(__name__)
logg = logging.getLogger() logg = logging.getLogger()
@ -23,6 +24,7 @@ class Dispatcher:
self.chain_spec = chain_spec self.chain_spec = chain_spec
self.adapter = adapter self.adapter = adapter
self.limit = limit self.limit = limit
self.tx_normalizer = TxNormalizer()
def __init_count(self, address, session): def __init_count(self, address, session):
@ -36,10 +38,12 @@ class Dispatcher:
def get_count(self, address, session): def get_count(self, address, session):
address = self.tx_normalizer.wallet_address(address)
return self.__init_count(address, session) return self.__init_count(address, session)
def inc_count(self, address, session): def inc_count(self, address, session):
address = self.tx_normalizer.wallet_address(address)
self.__init_count(address, session) self.__init_count(address, session)
self.address_counts[address] -= 1 self.address_counts[address] -= 1

View File

@ -1,4 +1,4 @@
chaind<=0.0.3,>=0.0.3a5 chaind<=0.0.3,>=0.0.3a6
hexathon~=0.0.1a8 hexathon~=0.0.1a8
chainlib-eth<=0.1.0,>=0.0.9a10 chainlib-eth<=0.1.0,>=0.0.10a10
eth-address-index<=0.3.0,>=0.2.3a5 eth-token-index<=0.3.0,>=0.2.4a1

View File

@ -2,9 +2,11 @@
set -e set -e
set -x set -x
set -a
export PYTHONPATH=${PYTHONPATH:.} export PYTHONPATH=${PYTHONPATH:.}
for f in `ls tests/*.py`; do for f in `ls tests/*.py`; do
python $f python $f
done done
set +a
set +x set +x
set +e set +e

View File

@ -22,10 +22,10 @@ class TestBase(EthTesterCase):
def setUp(self): def setUp(self):
super(TestBase, self).setUp() super(TestBase, self).setUp()
self.db_chainsyncer = ChainSyncerDb() self.db_chainsyncer = ChainSyncerDb(debug=bool(os.environ.get('DATABASE_DEBUG')))
self.session_chainsyncer = self.db_chainsyncer.bind_session() self.session_chainsyncer = self.db_chainsyncer.bind_session()
self.db_chainqueue = ChainQueueDb() self.db_chainqueue = ChainQueueDb(debug=bool(os.environ.get('DATABASE_DEBUG')))
self.session_chainqueue = self.db_chainqueue.bind_session() self.session_chainqueue = self.db_chainqueue.bind_session()
self.interface = EthChainInterface() self.interface = EthChainInterface()
@ -40,7 +40,8 @@ class TestBase(EthTesterCase):
class TestSQLBase(TestBase): class TestSQLBase(TestBase):
example_tx = bytes.fromhex('f8650d8405f5e10082520894ee38d3a40e177608d41978778206831f60dd0fa88204008077a040adee2ad0a0e566bced4b76a8899549e86719eb8866b87674b6fdc88479c201a030b3ca061bb330f4d78bc9cb8144c8e570339496f56b7809387de2ffeaa585d5') example_tx_hex = 'f8650d8405f5e10082520894ee38d3a40e177608d41978778206831f60dd0fa88204008077a040adee2ad0a0e566bced4b76a8899549e86719eb8866b87674b6fdc88479c201a030b3ca061bb330f4d78bc9cb8144c8e570339496f56b7809387de2ffeaa585d5'
example_tx = bytes.fromhex(example_tx_hex)
example_tx_sender = add_0x(to_checksum_address('eb3907ecad74a0013c259d5874ae7f22dcbcc95c')) example_tx_sender = add_0x(to_checksum_address('eb3907ecad74a0013c259d5874ae7f22dcbcc95c'))
dsn = dsn_from_config(db_config) dsn = dsn_from_config(db_config)

View File

@ -19,7 +19,7 @@ class TestAdapter(TestSQLBase):
def test_eth_adapter_add(self): def test_eth_adapter_add(self):
self.adapter.add(self.example_tx, self.chain_spec, session=self.session_chainqueue) self.adapter.add(self.example_tx_hex, self.chain_spec, session=self.session_chainqueue)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -37,14 +37,15 @@ class TestDispatcher(TestSQLBase):
tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed)) tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed))
dispatcher = Dispatcher(self.chain_spec, self.adapter, 1) dispatcher = Dispatcher(self.chain_spec, self.adapter, 1)
self.adapter.add(tx_raw_rlp_signed_bytes, self.chain_spec, session=self.session_chainqueue) self.adapter.add(tx_raw_rlp_signed, self.chain_spec, session=self.session_chainqueue)
assert dispatcher.get_count(self.example_tx_sender, self.session_chainqueue) == 1 #self.assertEqual(dispatcher.get_count(self.example_tx_sender, self.session_chainqueue), 1)
self.assertEqual(dispatcher.get_count(self.accounts[0], self.session_chainqueue), 1)
dispatcher.process(self.rpc, self.session_chainqueue) dispatcher.process(self.rpc, self.session_chainqueue)
tx_obj = unpack(tx_raw_rlp_signed_bytes, self.chain_spec) tx_obj = unpack(tx_raw_rlp_signed_bytes, self.chain_spec)
o = get_tx(self.chain_spec, tx_obj['hash'], session=self.session_chainqueue) o = get_tx(self.chain_spec, tx_obj['hash'], session=self.session_chainqueue)
assert o['status'] & StatusBits.IN_NETWORK > 0 self.assertGreater(o['status'] & StatusBits.IN_NETWORK, 0)
self.assertEqual(dispatcher.get_count(self.accounts[0], self.session_chainqueue), 0)
assert dispatcher.get_count(self.accounts[0], self.session_chainqueue) == 0
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -76,7 +76,8 @@ class TestFilter(TestBase):
adapter = EthAdapter(backend) adapter = EthAdapter(backend)
tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed)) tx_raw_rlp_signed_bytes = bytes.fromhex(strip_0x(tx_raw_rlp_signed))
adapter.add(tx_raw_rlp_signed_bytes, self.chain_spec, session=self.session_chainqueue) #adapter.add(tx_raw_rlp_signed_bytes, self.chain_spec, session=self.session_chainqueue)
adapter.add(tx_raw_rlp_signed, self.chain_spec, session=self.session_chainqueue)
set_ready(self.chain_spec, tx_hash, session=self.session_chainqueue) set_ready(self.chain_spec, tx_hash, session=self.session_chainqueue)
set_reserved(self.chain_spec, tx_hash, session=self.session_chainqueue) set_reserved(self.chain_spec, tx_hash, session=self.session_chainqueue)