Add chain spec to method calls in tests

This commit is contained in:
nolash 2021-04-06 10:33:23 +02:00
parent b177bc8aa6
commit f41573d205
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
9 changed files with 124 additions and 91 deletions

View File

@ -21,6 +21,7 @@ def upgrade():
'otx', 'otx',
sa.Column('id', sa.Integer, primary_key=True), sa.Column('id', sa.Integer, primary_key=True),
sa.Column('date_created', sa.DateTime, nullable=False), sa.Column('date_created', sa.DateTime, nullable=False),
sa.Column('date_updated', sa.DateTime, nullable=False),
sa.Column('nonce', sa.Integer, nullable=False), sa.Column('nonce', sa.Integer, nullable=False),
sa.Column('tx_hash', sa.Text, nullable=False), sa.Column('tx_hash', sa.Text, nullable=False),
sa.Column('signed_tx', sa.Text, nullable=False), sa.Column('signed_tx', sa.Text, nullable=False),

View File

@ -42,6 +42,7 @@ class Otx(SessionBase):
nonce = Column(Integer) nonce = Column(Integer)
date_created = Column(DateTime, default=datetime.datetime.utcnow) date_created = Column(DateTime, default=datetime.datetime.utcnow)
date_updated = Column(DateTime, default=datetime.datetime.utcnow)
tx_hash = Column(String(66)) tx_hash = Column(String(66))
signed_tx = Column(Text) signed_tx = Column(Text)
status = Column(Integer) status = Column(Integer)
@ -50,6 +51,7 @@ class Otx(SessionBase):
def __set_status(self, status, session): def __set_status(self, status, session):
self.status |= status self.status |= status
self.date_updated = datetime.datetime.utcnow()
session.add(self) session.add(self)
session.flush() session.flush()
@ -57,6 +59,7 @@ class Otx(SessionBase):
def __reset_status(self, status, session): def __reset_status(self, status, session):
status_edit = ~status & self.status status_edit = ~status & self.status
self.status &= status_edit self.status &= status_edit
self.date_updated = datetime.datetime.utcnow()
session.add(self) session.add(self)
session.flush() session.flush()
@ -90,6 +93,7 @@ class Otx(SessionBase):
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('Attempted set block {} when block was already {}'.format(block, self.block)) raise TxStateChangeError('Attempted set block {} when block was already {}'.format(block, self.block))
self.block = block self.block = block
self.date_updated = datetime.datetime.utcnow()
session.add(self) session.add(self)
session.flush() session.flush()
@ -109,11 +113,13 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('GAS_ISSUES cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('GAS_ISSUES cannot be set on an entry with FINAL state set ({})'.format(status))
if self.status & StatusBits.IN_NETWORK: if self.status & StatusBits.IN_NETWORK:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('GAS_ISSUES cannot be set on an entry with IN_NETWORK state set ({})'.format(status_str(self.status))) raise TxStateChangeError('GAS_ISSUES cannot be set on an entry with IN_NETWORK state set ({})'.format(status))
self.__set_status(StatusBits.GAS_ISSUES, session) self.__set_status(StatusBits.GAS_ISSUES, session)
self.__reset_status(StatusBits.QUEUED | StatusBits.DEFERRED, session) self.__reset_status(StatusBits.QUEUED | StatusBits.DEFERRED, session)
@ -135,14 +141,17 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('FUBAR cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('FUBAR cannot be set on an entry with FINAL state set ({})'.format(status))
if is_error_status(self.status): if is_error_status(self.status):
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('FUBAR cannot be set on an entry with an error state already set ({})'.format(status_str(self.status))) raise TxStateChangeError('FUBAR cannot be set on an entry with an error state already set ({})'.format(status))
if not self.status & StatusBits.RESERVED: if not self.status & StatusBits.RESERVED:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('FUBAR on tx that has not been RESEREVED ({})'.format(status_str(self.status))) raise TxStateChangeError('FUBAR on tx that has not been RESEREVED ({})'.format(status))
self.__set_status(StatusBits.UNKNOWN_ERROR | StatusBits.FINAL, session) self.__set_status(StatusBits.UNKNOWN_ERROR | StatusBits.FINAL, session)
@ -164,17 +173,21 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REJECTED cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('REJECTED cannot be set on an entry with FINAL state set ({})'.format(status))
if self.status & StatusBits.IN_NETWORK: if self.status & StatusBits.IN_NETWORK:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REJECTED cannot be set on an entry already IN_NETWORK ({})'.format(status_str(self.status))) raise TxStateChangeError('REJECTED cannot be set on an entry already IN_NETWORK ({})'.format(status))
if is_error_status(self.status): if is_error_status(self.status):
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REJECTED cannot be set on an entry with an error state already set ({})'.format(status_str(self.status))) raise TxStateChangeError('REJECTED cannot be set on an entry with an error state already set ({})'.format(status))
if not self.status & StatusBits.RESERVED: if not self.status & StatusBits.RESERVED:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REJECTED on tx that has not been RESEREVED ({})'.format(status_str(self.status))) raise TxStateChangeError('REJECTED on tx that has not been RESEREVED ({})'.format(status))
@ -195,14 +208,15 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry with FINAL state set ({})'.format(status))
if self.status & StatusBits.IN_NETWORK: if self.status & StatusBits.IN_NETWORK:
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry already IN_NETWORK ({})'.format(status_str(self.status))) raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry already IN_NETWORK ({})'.format(status))
if self.status & StatusBits.OBSOLETE: if self.status & StatusBits.OBSOLETE:
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry already OBSOLETE ({})'.format(status_str(self.status))) raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry already OBSOLETE ({})'.format(status))
self.__set_status(StatusBits.OBSOLETE, session) self.__set_status(StatusBits.OBSOLETE, session)
#if manual: #if manual:
@ -221,8 +235,9 @@ class Otx(SessionBase):
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('OVERRIDDEN/OBSOLETED cannot be set on an entry with FINAL state set ({})'.format(status))
self.__set_status(StatusBits.MANUAL, session) self.__set_status(StatusBits.MANUAL, session)
@ -244,11 +259,13 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = status_str(self.status)
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('RETRY cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('RETRY cannot be set on an entry with FINAL state set ({})'.format(status))
if not is_error_status(self.status) and not StatusBits.IN_NETWORK & self.status > 0: if not is_error_status(self.status) and not StatusBits.IN_NETWORK & self.status > 0:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('RETRY cannot be set on an entry that has no error ({})'.format(status_str(self.status))) raise TxStateChangeError('RETRY cannot be set on an entry that has no error ({})'.format(status))
self.__set_status(StatusBits.QUEUED, session) self.__set_status(StatusBits.QUEUED, session)
self.__reset_status(StatusBits.GAS_ISSUES, session) self.__reset_status(StatusBits.GAS_ISSUES, session)
@ -272,11 +289,13 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('READYSEND cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('READYSEND cannot be set on an entry with FINAL state set ({})'.format(status))
if is_error_status(self.status): if is_error_status(self.status):
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('READYSEND cannot be set on an errored state ({})'.format(status_str(self.status))) raise TxStateChangeError('READYSEND cannot be set on an errored state ({})'.format(status))
self.__set_status(StatusBits.QUEUED, session) self.__set_status(StatusBits.QUEUED, session)
self.__reset_status(StatusBits.GAS_ISSUES, session) self.__reset_status(StatusBits.GAS_ISSUES, session)
@ -300,12 +319,14 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SENT cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SENT cannot be set on an entry with FINAL state set ({})'.format(status))
if not self.status & StatusBits.RESERVED: if not self.status & StatusBits.RESERVED:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SENT on tx that has not been RESEREVED ({})'.format(status_str(self.status))) raise TxStateChangeError('SENT on tx that has not been RESEREVED ({})'.format(status))
self.__set_status(StatusBits.IN_NETWORK, session) self.__set_status(StatusBits.IN_NETWORK, session)
self.__reset_status(StatusBits.RESERVED | StatusBits.DEFERRED | StatusBits.QUEUED | StatusBits.LOCAL_ERROR | StatusBits.NODE_ERROR, session) self.__reset_status(StatusBits.RESERVED | StatusBits.DEFERRED | StatusBits.QUEUED | StatusBits.LOCAL_ERROR | StatusBits.NODE_ERROR, session)
@ -329,14 +350,17 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SENDFAIL cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SENDFAIL cannot be set on an entry with FINAL state set ({})'.format(status))
if self.status & StatusBits.IN_NETWORK: if self.status & StatusBits.IN_NETWORK:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SENDFAIL cannot be set on an entry with IN_NETWORK state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SENDFAIL cannot be set on an entry with IN_NETWORK state set ({})'.format(status))
if not self.status & StatusBits.RESERVED: if not self.status & StatusBits.RESERVED:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SENDFAIL on tx that has not been RESEREVED ({})'.format(status_str(self.status))) raise TxStateChangeError('SENDFAIL on tx that has not been RESEREVED ({})'.format(status))
self.__set_status(StatusBits.LOCAL_ERROR | StatusBits.DEFERRED, session) self.__set_status(StatusBits.LOCAL_ERROR | StatusBits.DEFERRED, session)
self.__reset_status(StatusBits.RESERVED | StatusBits.QUEUED | StatusBits.GAS_ISSUES, session) self.__reset_status(StatusBits.RESERVED | StatusBits.QUEUED | StatusBits.GAS_ISSUES, session)
@ -360,14 +384,17 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.QUEUED == 0: if self.status & StatusBits.QUEUED == 0:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('RESERVED cannot be set on an entry without QUEUED state set ({})'.format(status_str(self.status))) raise TxStateChangeError('RESERVED cannot be set on an entry without QUEUED state set ({})'.format(status))
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('RESERVED cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('RESERVED cannot be set on an entry with FINAL state set ({})'.format(status))
if self.status & StatusBits.IN_NETWORK: if self.status & StatusBits.IN_NETWORK:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('RESERVED cannot be set on an entry with IN_NETWORK state set ({})'.format(status_str(self.status))) raise TxStateChangeError('RESERVED cannot be set on an entry with IN_NETWORK state set ({})'.format(status))
self.__reset_status(StatusBits.QUEUED, session) self.__reset_status(StatusBits.QUEUED, session)
self.__set_status(StatusBits.RESERVED, session) self.__set_status(StatusBits.RESERVED, session)
@ -394,11 +421,13 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REVERTED cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('REVERTED cannot be set on an entry with FINAL state set ({})'.format(status))
if not self.status & StatusBits.IN_NETWORK: if not self.status & StatusBits.IN_NETWORK:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('REVERTED cannot be set on an entry without IN_NETWORK state set ({})'.format(status_str(self.status))) raise TxStateChangeError('REVERTED cannot be set on an entry without IN_NETWORK state set ({})'.format(status))
if block != None: if block != None:
self.block = block self.block = block
@ -425,13 +454,15 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('CANCEL cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('CANCEL cannot be set on an entry with FINAL state set ({})'.format(status))
if confirmed: if confirmed:
status = self.status
if self.status > 0 and self.status & (StatusBits.OBSOLETE & StatusBits.IN_NETWORK) == 0: if self.status > 0 and self.status & (StatusBits.OBSOLETE & StatusBits.IN_NETWORK) == 0:
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('CANCEL can only be set on an entry marked OBSOLETE ({})'.format(status_str(self.status))) raise TxStateChangeError('CANCEL can only be set on an entry marked OBSOLETE ({})'.format(status))
self.__set_status(StatusEnum.FINAL, session) self.__set_status(StatusEnum.FINAL, session)
self.__set_status(StatusEnum.OBSOLETED, session) self.__set_status(StatusEnum.OBSOLETED, session)
@ -456,14 +487,17 @@ class Otx(SessionBase):
session = SessionBase.bind_session(session) session = SessionBase.bind_session(session)
if self.status & StatusBits.FINAL: if self.status & StatusBits.FINAL:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SUCCESS cannot be set on an entry with FINAL state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SUCCESS cannot be set on an entry with FINAL state set ({})'.format(status))
if not self.status & StatusBits.IN_NETWORK: if not self.status & StatusBits.IN_NETWORK:
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SUCCESS cannot be set on an entry without IN_NETWORK state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SUCCESS cannot be set on an entry without IN_NETWORK state set ({})'.format(status))
if is_error_status(self.status): if is_error_status(self.status):
status = self.status
SessionBase.release_session(session) SessionBase.release_session(session)
raise TxStateChangeError('SUCCESS cannot be set on an entry with error state set ({})'.format(status_str(self.status))) raise TxStateChangeError('SUCCESS cannot be set on an entry with error state set ({})'.format(status))
if block != None: if block != None:
self.block = block self.block = block

View File

@ -50,8 +50,6 @@ def get_tx_cache(chain_spec, tx_hash, session=None):
q = q.filter(TxCache.otx_id==otx.id) q = q.filter(TxCache.otx_id==otx.id)
txc = q.first() txc = q.first()
SessionBase.release_session(session)
# TODO: DRY, get_tx_cache / get_tx # TODO: DRY, get_tx_cache / get_tx
tx = { tx = {
'tx_hash': add_0x(otx.tx_hash), 'tx_hash': add_0x(otx.tx_hash),
@ -72,6 +70,8 @@ def get_tx_cache(chain_spec, tx_hash, session=None):
'date_checked': txc.date_checked, 'date_checked': txc.date_checked,
} }
SessionBase.release_session(session)
return tx return tx
@ -195,7 +195,7 @@ def get_status_tx_cache(chain_spec, status, not_status=None, before=None, exact=
q = session.query(Otx) q = session.query(Otx)
q = q.join(TxCache) q = q.join(TxCache)
if before != None: if before != None:
q = q.filter(TxCache.date_updated<before) q = q.filter(Otx.date_updated<before)
if exact: if exact:
q = q.filter(Otx.status==status) q = q.filter(Otx.status==status)
else: else:

View File

@ -54,14 +54,13 @@ def set_sent(chain_spec, tx_hash, fail=False, session=None):
SessionBase.release_session(session) SessionBase.release_session(session)
raise(e) raise(e)
session.commit() session.commit()
SessionBase.release_session(session) SessionBase.release_session(session)
return tx_hash return tx_hash
def set_final(chain_spec, tx_hash, block=None, fail=False, session=None): def set_final(chain_spec, tx_hash, block=None, tx_index=None, fail=False, session=None):
"""Used to set the status of an incoming transaction result. """Used to set the status of an incoming transaction result.
:param tx_hash: Transaction hash of record to modify :param tx_hash: Transaction hash of record to modify
@ -86,7 +85,6 @@ def set_final(chain_spec, tx_hash, block=None, fail=False, session=None):
o.minefail(block, session=session) o.minefail(block, session=session)
else: else:
o.success(block, session=session) o.success(block, session=session)
session.commit()
except TxStateChangeError as e: except TxStateChangeError as e:
logg.exception('set final fail: {}'.format(e)) logg.exception('set final fail: {}'.format(e))
SessionBase.release_session(session) SessionBase.release_session(session)
@ -96,10 +94,10 @@ def set_final(chain_spec, tx_hash, block=None, fail=False, session=None):
SessionBase.release_session(session) SessionBase.release_session(session)
raise(e) raise(e)
q = session.query(TxCache) if block != None:
q = q.join(Otx) TxCache.set_final(o.tx_hash, block, tx_index, session=session)
q = q.filter(Otx.tx_hash==strip_0x(tx_hash))
o = q.first() session.commit()
SessionBase.release_session(session) SessionBase.release_session(session)

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainqueue name = chainqueue
version = 0.0.1a5 version = 0.0.1a6
description = Generic blockchain transaction queue control description = Generic blockchain transaction queue control
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -24,93 +24,93 @@ logg = logging.getLogger()
class TestOtx(TestOtxBase): class TestOtx(TestOtxBase):
def test_ideal_state_sequence(self): def test_ideal_state_sequence(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status, StatusBits.QUEUED) self.assertEqual(otx.status, StatusBits.QUEUED)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status, StatusBits.RESERVED) self.assertEqual(otx.status, StatusBits.RESERVED)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status, StatusBits.IN_NETWORK) self.assertEqual(otx.status, StatusBits.IN_NETWORK)
set_final(self.tx_hash, block=1024) set_final(self.chain_spec, self.tx_hash, block=1024)
self.session.refresh(otx) self.session.refresh(otx)
self.assertFalse(is_alive(otx.status)) self.assertFalse(is_alive(otx.status))
self.assertFalse(is_error_status(otx.status)) self.assertFalse(is_error_status(otx.status))
def test_send_fail_and_retry(self): def test_send_fail_and_retry(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status, StatusBits.QUEUED) self.assertEqual(otx.status, StatusBits.QUEUED)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status, StatusBits.RESERVED) self.assertEqual(otx.status, StatusBits.RESERVED)
set_sent(self.tx_hash, fail=True) set_sent(self.chain_spec, self.tx_hash, fail=True)
self.session.refresh(otx) self.session.refresh(otx)
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.QUEUED, StatusBits.QUEUED) self.assertEqual(otx.status & StatusBits.QUEUED, StatusBits.QUEUED)
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED) self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED)
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status, StatusBits.IN_NETWORK) self.assertEqual(otx.status, StatusBits.IN_NETWORK)
self.assertFalse(is_error_status(otx.status)) self.assertFalse(is_error_status(otx.status))
set_final(self.tx_hash, block=1024) set_final(self.chain_spec, self.tx_hash, block=1024)
self.session.refresh(otx) self.session.refresh(otx)
self.assertFalse(is_alive(otx.status)) self.assertFalse(is_alive(otx.status))
self.assertFalse(is_error_status(otx.status)) self.assertFalse(is_error_status(otx.status))
def test_fubar(self): def test_fubar(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status, StatusBits.QUEUED) self.assertEqual(otx.status, StatusBits.QUEUED)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED) self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED)
set_fubar(self.tx_hash) set_fubar(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
self.assertEqual(otx.status & StatusBits.UNKNOWN_ERROR, StatusBits.UNKNOWN_ERROR) self.assertEqual(otx.status & StatusBits.UNKNOWN_ERROR, StatusBits.UNKNOWN_ERROR)
def test_reject(self): def test_reject(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status, StatusBits.QUEUED) self.assertEqual(otx.status, StatusBits.QUEUED)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED) self.assertEqual(otx.status & StatusBits.RESERVED, StatusBits.RESERVED)
set_rejected(self.tx_hash) set_rejected(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
self.assertEqual(otx.status & StatusBits.NODE_ERROR, StatusBits.NODE_ERROR) self.assertEqual(otx.status & StatusBits.NODE_ERROR, StatusBits.NODE_ERROR)
def test_final_fail(self): def test_final_fail(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
set_final(self.tx_hash, block=1042, fail=True) set_final(self.chain_spec, self.tx_hash, block=1042, fail=True)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertFalse(is_alive(otx.status)) self.assertFalse(is_alive(otx.status))
self.assertTrue(is_error_status(otx.status)) self.assertTrue(is_error_status(otx.status))
@ -118,47 +118,47 @@ class TestOtx(TestOtxBase):
def test_final_protected(self): def test_final_protected(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
set_final(self.tx_hash, block=1042) set_final(self.chain_spec, self.tx_hash, block=1042)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status & StatusBits.FINAL, StatusBits.FINAL) self.assertEqual(otx.status & StatusBits.FINAL, StatusBits.FINAL)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_fubar(self.tx_hash) set_fubar(self.chain_spec, self.tx_hash)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_rejected(self.tx_hash) set_rejected(self.chain_spec, self.tx_hash)
set_cancel(self.tx_hash) set_cancel(self.chain_spec, self.tx_hash)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.OBSOLETE, 0) self.assertEqual(otx.status & StatusBits.OBSOLETE, 0)
set_cancel(self.tx_hash, manual=True) set_cancel(self.chain_spec, self.tx_hash, manual=True)
self.session.refresh(otx) self.session.refresh(otx)
self.assertEqual(otx.status & StatusBits.OBSOLETE, 0) self.assertEqual(otx.status & StatusBits.OBSOLETE, 0)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_waitforgas(self.tx_hash) set_waitforgas(self.chain_spec, self.tx_hash)
with self.assertRaises(TxStateChangeError): with self.assertRaises(TxStateChangeError):
set_manual(self.tx_hash) set_manual(self.chain_spec, self.tx_hash)
def test_manual_persist(self): def test_manual_persist(self):
set_manual(self.tx_hash) set_manual(self.chain_spec, self.tx_hash)
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
set_final(self.tx_hash, block=1042) set_final(self.chain_spec, self.tx_hash, block=1042)
otx = Otx.load(self.tx_hash, session=self.session) otx = Otx.load(self.tx_hash, session=self.session)
self.assertEqual(otx.status & StatusBits.MANUAL, StatusBits.MANUAL) self.assertEqual(otx.status & StatusBits.MANUAL, StatusBits.MANUAL)

View File

@ -19,10 +19,10 @@ class TestOtxState(TestOtxBase):
def test_state_log(self): def test_state_log(self):
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
set_final(self.tx_hash, block=1042) set_final(self.chain_spec, self.tx_hash, block=1042)
state_log = get_state_log(self.chain_spec, self.tx_hash) state_log = get_state_log(self.chain_spec, self.tx_hash)
self.assertEqual(state_log[0][1], StatusEnum.READYSEND) self.assertEqual(state_log[0][1], StatusEnum.READYSEND)

View File

@ -93,7 +93,7 @@ class TestTxQuery(TestTxBase):
def test_paused_tx_cache(self): def test_paused_tx_cache(self):
set_waitforgas(self.tx_hash) set_waitforgas(self.chain_spec, self.tx_hash)
tx_hash = add_0x(os.urandom(32).hex()) tx_hash = add_0x(os.urandom(32).hex())
signed_tx = add_0x(os.urandom(128).hex()) signed_tx = add_0x(os.urandom(128).hex())
@ -150,7 +150,7 @@ class TestTxQuery(TestTxBase):
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session) txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
self.assertEqual(len(txs.keys()), 1) self.assertEqual(len(txs.keys()), 1)
set_waitforgas(tx_hash) set_waitforgas(self.chain_spec, tx_hash)
self.session.commit() self.session.commit()
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session) txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)

View File

@ -16,10 +16,10 @@ class TestTxCache(TestTxBase):
with self.assertRaises(NotLocalTxError): with self.assertRaises(NotLocalTxError):
TxCache.set_final(self.tx_hash, 1024, 13, session=self.session) TxCache.set_final(self.tx_hash, 1024, 13, session=self.session)
set_ready(self.tx_hash) set_ready(self.chain_spec, self.tx_hash)
set_reserved(self.tx_hash) set_reserved(self.chain_spec, self.tx_hash)
set_sent(self.tx_hash) set_sent(self.chain_spec, self.tx_hash)
set_final(self.tx_hash, block=1024) set_final(self.chain_spec, self.tx_hash, block=1024)
with self.assertRaises(NotLocalTxError): with self.assertRaises(NotLocalTxError):
TxCache.set_final(self.tx_hash, 1023, 13, session=self.session) TxCache.set_final(self.tx_hash, 1023, 13, session=self.session)