chainqueue/tests/test_shep.py

61 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-03-11 12:02:47 +01:00
# standard imports
import os
import logging
import unittest
# external imports
2022-03-11 21:16:42 +01:00
from hexathon import (
add_0x,
strip_0x,
)
2022-03-11 12:02:47 +01:00
from shep.error import StateTransitionInvalid
# local imports
2022-03-11 20:38:12 +01:00
from chainqueue import QueueEntry
# test imports
from tests.base_shep import TestShepBase
2022-03-15 09:06:39 +01:00
from tests.common import MockCacheTokenTx
2022-03-11 12:02:47 +01:00
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestShep(TestShepBase):
def test_shep_setup(self):
pass
def test_shep_tx(self):
signed_tx = add_0x(os.urandom(128).hex())
nonce = 42
2022-03-15 09:06:39 +01:00
tx = QueueEntry(self.store, cache_adapter=MockCacheTokenTx)
tx_hash = tx.create(signed_tx)
2022-03-15 09:06:39 +01:00
tx_retrieved = QueueEntry(self.store, tx_hash=tx_hash)
tx_retrieved.load()
2022-03-11 21:16:42 +01:00
self.assertEqual(tx_retrieved.signed_tx, strip_0x(signed_tx))
2022-03-11 12:02:47 +01:00
def test_shep_valid(self):
self.state.put('foo', 'bar')
self.state.set('foo', self.state.IN_NETWORK)
self.state.set('foo', self.state.FINAL)
2022-03-11 12:02:47 +01:00
def test_shep_invalid(self):
self.state.put('foo', 'bar')
self.state.set('foo', self.state.FINAL)
with self.assertRaises(StateTransitionInvalid):
2022-03-11 12:05:56 +01:00
self.state.move('foo', self.state.INSUFFICIENT_FUNDS)
2022-03-12 14:48:40 +01:00
def test_shep_cache(self):
2022-03-15 09:06:39 +01:00
self.store.put('bar', cache_adapter=MockCacheTokenTx)
2022-03-12 14:48:40 +01:00
2022-03-11 12:02:47 +01:00
2022-04-10 16:00:01 +02:00
2022-03-11 12:02:47 +01:00
if __name__ == '__main__':
unittest.main()