Add change test for chainqueue entry
This commit is contained in:
parent
0fa12adfa1
commit
01b674d09e
@ -115,7 +115,8 @@ class QueueEntry:
|
|||||||
def fail(self, block, tx):
|
def fail(self, block, tx):
|
||||||
if self.__match_state(self.store.NETWORK_ERROR):
|
if self.__match_state(self.store.NETWORK_ERROR):
|
||||||
return
|
return
|
||||||
self.store.set(self.k, self.store.NETWORK_ERROR)
|
v = self.store.state(self.k)
|
||||||
|
self.store.change(self.k, v | self.store.NETWORK_ERROR, self.store.QUEUED)
|
||||||
if self.store.cache:
|
if self.store.cache:
|
||||||
self.store.cache.set_block(self.tx_hash, block, tx)
|
self.store.cache.set_block(self.tx_hash, block, tx)
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainqueue.cache import CacheTx
|
from chainqueue.cache import CacheTx
|
||||||
from chainqueue.entry import QueueEntry
|
from chainqueue.entry import QueueEntry
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def to_key(t, n, k):
|
def to_key(t, n, k):
|
||||||
return '{}_{}_{}'.format(t, n, k)
|
return '{}_{}_{}'.format(t, n, k)
|
||||||
@ -125,6 +128,7 @@ class Store:
|
|||||||
def final(self, k, block, tx, error=False):
|
def final(self, k, block, tx, error=False):
|
||||||
entry = QueueEntry(self, k)
|
entry = QueueEntry(self, k)
|
||||||
entry.load()
|
entry.load()
|
||||||
|
logg.debug('entry {} {}'.format(k, entry.k))
|
||||||
if error:
|
if error:
|
||||||
entry.fail(block, tx)
|
entry.fail(block, tx)
|
||||||
else:
|
else:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import shutil
|
import shutil
|
||||||
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from shep.store.file import SimpleFileStoreFactory
|
from shep.store.file import SimpleFileStoreFactory
|
||||||
@ -19,6 +20,7 @@ from tests.common import (
|
|||||||
MockContentStore,
|
MockContentStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TestShepBase(unittest.TestCase):
|
class TestShepBase(unittest.TestCase):
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ class TestShepBase(unittest.TestCase):
|
|||||||
counter = MockCounter()
|
counter = MockCounter()
|
||||||
chain_spec = ChainSpec('foo', 'bar', 42, 'baz')
|
chain_spec = ChainSpec('foo', 'bar', 42, 'baz')
|
||||||
self.store = Store(chain_spec, self.state, content_store, counter)
|
self.store = Store(chain_spec, self.state, content_store, counter)
|
||||||
|
logg.debug('using path {}'.format(self.path))
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -5,6 +5,8 @@ import unittest
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from hexathon import add_0x
|
from hexathon import add_0x
|
||||||
|
from chainlib.tx import Tx
|
||||||
|
from chainlib.block import Block
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainqueue import QueueEntry
|
from chainqueue import QueueEntry
|
||||||
@ -59,5 +61,25 @@ class TestEntry(TestShepBase):
|
|||||||
self.assertEqual(len(txs), 1)
|
self.assertEqual(len(txs), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_entry_change(self):
|
||||||
|
signed_tx = add_0x(os.urandom(128).hex())
|
||||||
|
nonce = 42
|
||||||
|
entry = QueueEntry(self.store, cache_adapter=MockCacheTokenTx)
|
||||||
|
tx_hash = entry.create(signed_tx)
|
||||||
|
|
||||||
|
block = Block()
|
||||||
|
block.number = 13
|
||||||
|
tx = Tx(None)
|
||||||
|
tx.index = 666
|
||||||
|
|
||||||
|
entry.readysend()
|
||||||
|
entry.reserve()
|
||||||
|
entry.sendfail()
|
||||||
|
|
||||||
|
entry = QueueEntry(self.store, tx_hash, cache_adapter=MockCacheTokenTx)
|
||||||
|
entry.load()
|
||||||
|
self.assertEqual(str(entry), tx_hash + ': SENDFAIL')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -55,5 +55,6 @@ class TestShep(TestShepBase):
|
|||||||
self.store.put('bar', cache_adapter=MockCacheTokenTx)
|
self.store.put('bar', cache_adapter=MockCacheTokenTx)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user