implement get tx by state
This commit is contained in:
35
tests/base_shep.py
Normal file
35
tests/base_shep.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# standard imports
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
# external imports
|
||||
from shep.store.file import SimpleFileStoreFactory
|
||||
|
||||
# local imports
|
||||
from chainqueue import (
|
||||
Store,
|
||||
Status,
|
||||
)
|
||||
|
||||
|
||||
class MockIndexStore:
|
||||
|
||||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
|
||||
def put(self, k, v):
|
||||
self.store[k] = v
|
||||
|
||||
|
||||
def get(self, k):
|
||||
return self.store.get(k)
|
||||
|
||||
|
||||
class TestShepBase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.path = tempfile.mkdtemp()
|
||||
factory = SimpleFileStoreFactory(self.path).add
|
||||
self.state = Status(factory)
|
||||
self.store = Store(self.state, MockIndexStore())
|
||||
65
tests/test_entry.py
Normal file
65
tests/test_entry.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
# external imports
|
||||
from hexathon import add_0x
|
||||
|
||||
# local imports
|
||||
from chainqueue import QueueEntry
|
||||
|
||||
# test imports
|
||||
from tests.base_shep import TestShepBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class MockTranslator:
|
||||
pass
|
||||
|
||||
|
||||
class TestShep(TestShepBase):
|
||||
|
||||
def test_entry_get(self):
|
||||
tx_hash_one = add_0x(os.urandom(20).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
entry = QueueEntry(self.store, tx_hash_one)
|
||||
entry.create(nonce, signed_tx)
|
||||
|
||||
tx_hash_two = add_0x(os.urandom(20).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
entry = QueueEntry(self.store, tx_hash_two)
|
||||
entry.create(nonce, signed_tx)
|
||||
|
||||
txs = self.store.list()
|
||||
self.assertEqual(len(txs), 2)
|
||||
|
||||
entry = QueueEntry(self.store, tx_hash_one)
|
||||
entry.load()
|
||||
entry.sent()
|
||||
|
||||
txs = self.store.list()
|
||||
self.assertEqual(len(txs), 1)
|
||||
|
||||
txs = self.store.list(state=self.store.IN_NETWORK)
|
||||
self.assertEqual(len(txs), 1)
|
||||
|
||||
entry.succeed(0)
|
||||
txs = self.store.list()
|
||||
self.assertEqual(len(txs), 1)
|
||||
|
||||
entry = QueueEntry(self.store, tx_hash_two)
|
||||
entry.load()
|
||||
entry.sent()
|
||||
|
||||
txs = self.store.list(state=self.store.IN_NETWORK)
|
||||
self.assertEqual(len(txs), 2)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,43 +2,21 @@
|
||||
import os
|
||||
import logging
|
||||
import unittest
|
||||
import tempfile
|
||||
|
||||
# external imports
|
||||
from hexathon import add_0x
|
||||
from shep.store.file import SimpleFileStoreFactory
|
||||
from shep.error import StateTransitionInvalid
|
||||
|
||||
# local imports
|
||||
from chainqueue import Status
|
||||
from chainqueue.tx import Tx
|
||||
from chainqueue import QueueEntry
|
||||
|
||||
# test imports
|
||||
from tests.base_shep import TestShepBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class MockIndexStore:
|
||||
|
||||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
|
||||
def put(self, k, v):
|
||||
self.store[k] = v
|
||||
|
||||
|
||||
def get(self, k):
|
||||
return self.store.get(k)
|
||||
|
||||
|
||||
class TestShepBase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.path = tempfile.mkdtemp()
|
||||
factory = SimpleFileStoreFactory(self.path).add
|
||||
self.state = Status(factory)
|
||||
|
||||
|
||||
class TestShep(TestShepBase):
|
||||
|
||||
def test_shep_setup(self):
|
||||
@@ -49,11 +27,10 @@ class TestShep(TestShepBase):
|
||||
tx_hash = add_0x(os.urandom(20).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
nonce = 42
|
||||
mock_store = MockIndexStore()
|
||||
tx = Tx(self.state, mock_store, tx_hash)
|
||||
tx = QueueEntry(self.store, tx_hash)
|
||||
tx.create(nonce, signed_tx)
|
||||
|
||||
tx_retrieved = Tx(self.state, mock_store, tx_hash)
|
||||
tx_retrieved = QueueEntry(self.store, tx_hash)
|
||||
tx_retrieved.load()
|
||||
self.assertEqual(tx_retrieved.signed_tx, signed_tx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user