Force hashing of tx inside puts
This commit is contained in:
@@ -11,6 +11,7 @@ from chainqueue import QueueEntry
|
||||
|
||||
# test imports
|
||||
from tests.base_shep import TestShepBase
|
||||
from tests.common import MockCacheTokenTx
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -19,22 +20,21 @@ logg = logging.getLogger()
|
||||
class TestEntry(TestShepBase):
|
||||
|
||||
def test_entry_get(self):
|
||||
tx_hash_one = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
entry = QueueEntry(self.store, tx_hash_one)
|
||||
entry.create(signed_tx)
|
||||
entry = QueueEntry(self.store, cache_adapter=MockCacheTokenTx)
|
||||
tx_hash_one = entry.create(signed_tx)
|
||||
|
||||
tx_hash_two = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
entry = QueueEntry(self.store, tx_hash_two)
|
||||
entry.create(signed_tx)
|
||||
entry = QueueEntry(self.store, cache_adapter=MockCacheTokenTx)
|
||||
tx_hash_two = entry.create(signed_tx)
|
||||
|
||||
txs = self.store.by_state()
|
||||
self.assertEqual(len(txs), 2)
|
||||
|
||||
entry = QueueEntry(self.store, tx_hash_one)
|
||||
|
||||
logg.debug('tx hash one {}'.format(tx_hash_one))
|
||||
entry = QueueEntry(self.store, tx_hash=tx_hash_one, cache_adapter=MockCacheTokenTx)
|
||||
entry.load()
|
||||
entry.sent()
|
||||
|
||||
|
||||
@@ -42,20 +42,18 @@ class TestIntegrateBase(TestShepBase):
|
||||
|
||||
|
||||
def test_integration_valid(self):
|
||||
self.store.put(os.urandom(4).hex(), os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
|
||||
|
||||
def test_state_default(self):
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
v = self.store.pending()
|
||||
self.assertEqual(len(v), 1)
|
||||
self.assertEqual(v[0], hx)
|
||||
|
||||
|
||||
def test_state_enqueue(self):
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.get(hx)
|
||||
self.store.enqueue(hx)
|
||||
v = self.store.upcoming()
|
||||
@@ -65,8 +63,7 @@ class TestIntegrateBase(TestShepBase):
|
||||
|
||||
|
||||
def test_state_defer(self):
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
v = self.store.deferred()
|
||||
@@ -75,12 +72,11 @@ class TestIntegrateBase(TestShepBase):
|
||||
|
||||
|
||||
def test_state_multiple(self):
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
hx = os.urandom(8).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
v = self.store.deferred()
|
||||
@@ -88,33 +84,30 @@ class TestIntegrateBase(TestShepBase):
|
||||
|
||||
|
||||
def test_state_multiple_sort(self):
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.enqueue(hx)
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
hx = os.urandom(4).hex()
|
||||
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
|
||||
self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
v = self.store.deferred()
|
||||
self.assertEqual(len(v), 2)
|
||||
|
||||
|
||||
def test_state_date_threshold(self):
|
||||
hx = os.urandom(4).hex()
|
||||
s = self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
then = self.store.modified(s)
|
||||
time.sleep(0.1)
|
||||
|
||||
hx = os.urandom(4).hex()
|
||||
s = self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
(s, hx) = self.store.put(os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
|
||||
self.store.reserve(hx)
|
||||
self.store.fail(hx)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from chainqueue import QueueEntry
|
||||
|
||||
# test imports
|
||||
from tests.base_shep import TestShepBase
|
||||
from tests.common import MockCacheTokenTx
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -27,13 +28,12 @@ class TestShep(TestShepBase):
|
||||
|
||||
|
||||
def test_shep_tx(self):
|
||||
tx_hash = add_0x(os.urandom(20).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
tx = QueueEntry(self.store, tx_hash)
|
||||
tx.create(signed_tx)
|
||||
tx = QueueEntry(self.store, cache_adapter=MockCacheTokenTx)
|
||||
tx_hash = tx.create(signed_tx)
|
||||
|
||||
tx_retrieved = QueueEntry(self.store, tx_hash)
|
||||
tx_retrieved = QueueEntry(self.store, tx_hash=tx_hash)
|
||||
tx_retrieved.load()
|
||||
self.assertEqual(tx_retrieved.signed_tx, strip_0x(signed_tx))
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestShep(TestShepBase):
|
||||
|
||||
|
||||
def test_shep_cache(self):
|
||||
self.store.put('foo', 'bar')
|
||||
self.store.put('bar', cache_adapter=MockCacheTokenTx)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user