Consolidate adapter interface
This commit is contained in:
112
tests/base.py
112
tests/base.py
@@ -1,112 +0,0 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
#import pysqlite
|
||||
|
||||
# external imports
|
||||
from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
from chainlib.chain import ChainSpec
|
||||
import alembic
|
||||
import alembic.config
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from chainqueue.db import dsn_from_config
|
||||
from chainqueue.db.models.base import SessionBase
|
||||
from chainqueue.sql.tx import create
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
|
||||
#logg = logging.getLogger().getChild(__name__)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestBase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
rootdir = os.path.dirname(os.path.dirname(__file__))
|
||||
dbdir = os.path.join(rootdir, 'chainqueue', 'db')
|
||||
#migrationsdir = os.path.join(dbdir, 'migrations', load_config.get('DATABASE_ENGINE'))
|
||||
#if not os.path.isdir(migrationsdir):
|
||||
migrationsdir = os.path.join(dbdir, 'migrations', 'default')
|
||||
logg.info('using migrations directory {}'.format(migrationsdir))
|
||||
|
||||
config = {
|
||||
'DATABASE_ENGINE': 'sqlite',
|
||||
'DATABASE_DRIVER': 'pysqlite',
|
||||
'DATABASE_NAME': 'chainqueue.sqlite',
|
||||
}
|
||||
logg.debug('config {}'.format(config))
|
||||
|
||||
dsn = dsn_from_config(config)
|
||||
SessionBase.poolable = False
|
||||
SessionBase.transactional = False
|
||||
SessionBase.procedural = False
|
||||
SessionBase.connect(dsn, debug=bool(os.environ.get('DATABASE_DEBUG'))) # TODO: evaluates to "true" even if string is 0
|
||||
|
||||
ac = alembic.config.Config(os.path.join(migrationsdir, 'alembic.ini'))
|
||||
ac.set_main_option('sqlalchemy.url', dsn)
|
||||
ac.set_main_option('script_location', migrationsdir)
|
||||
|
||||
alembic.command.downgrade(ac, 'base')
|
||||
alembic.command.upgrade(ac, 'head')
|
||||
|
||||
self.session = SessionBase.create_session()
|
||||
|
||||
self.chain_spec = ChainSpec('evm', 'foo', 42, 'bar')
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
self.session.commit()
|
||||
self.session.close()
|
||||
|
||||
|
||||
class TestOtxBase(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOtxBase, self).setUp()
|
||||
self.tx_hash = os.urandom(32).hex()
|
||||
self.tx = os.urandom(128).hex()
|
||||
self.nonce = 42
|
||||
self.alice = add_0x(os.urandom(20).hex())
|
||||
|
||||
tx_hash = create(self.chain_spec, self.nonce, self.alice, self.tx_hash, self.tx, session=self.session)
|
||||
self.assertEqual(tx_hash, self.tx_hash)
|
||||
self.session.commit()
|
||||
|
||||
logg.info('using tx hash {}'.format(self.tx_hash))
|
||||
|
||||
|
||||
class TestTxBase(TestOtxBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTxBase, self).setUp()
|
||||
self.bob = add_0x(os.urandom(20).hex())
|
||||
self.carol = add_0x(os.urandom(20).hex())
|
||||
self.foo_token = add_0x(os.urandom(20).hex())
|
||||
self.bar_token = add_0x(os.urandom(20).hex())
|
||||
self.from_value = 42
|
||||
self.to_value = 13
|
||||
|
||||
txc = TxCache(
|
||||
self.tx_hash,
|
||||
self.alice,
|
||||
self.bob,
|
||||
self.foo_token,
|
||||
self.bar_token,
|
||||
self.from_value,
|
||||
self.to_value,
|
||||
session=self.session,
|
||||
)
|
||||
self.session.add(txc)
|
||||
self.session.commit()
|
||||
|
||||
otx = Otx.load(self.tx_hash)
|
||||
self.assertEqual(txc.otx_id, otx.id)
|
||||
|
||||
85
tests/chainqueue_base.py
Normal file
85
tests/chainqueue_base.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
#import pysqlite
|
||||
|
||||
# external imports
|
||||
from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
from chainlib.chain import ChainSpec
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from chainqueue.sql.tx import create
|
||||
from chainqueue.unittest.db import ChainQueueDb
|
||||
from chainqueue.sql.backend import SQLBackend
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestBase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
debug = bool(os.environ.get('DATABASE_DEBUG', False))
|
||||
self.db = ChainQueueDb(debug=debug)
|
||||
self.session = self.db.bind_session()
|
||||
self.chain_spec = ChainSpec('evm', 'foo', 42, 'bar')
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
self.session.commit()
|
||||
self.db.release_session(self.session)
|
||||
|
||||
|
||||
class TestOtxBase(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOtxBase, self).setUp()
|
||||
self.tx_hash = os.urandom(32).hex()
|
||||
self.tx = os.urandom(128).hex()
|
||||
self.nonce = 42
|
||||
self.alice = add_0x(os.urandom(20).hex())
|
||||
|
||||
tx_hash = create(self.chain_spec, self.nonce, self.alice, self.tx_hash, self.tx, session=self.session)
|
||||
self.assertEqual(tx_hash, self.tx_hash)
|
||||
self.session.commit()
|
||||
|
||||
logg.info('using tx hash {}'.format(self.tx_hash))
|
||||
|
||||
|
||||
class TestTxBase(TestOtxBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTxBase, self).setUp()
|
||||
self.bob = add_0x(os.urandom(20).hex())
|
||||
self.carol = add_0x(os.urandom(20).hex())
|
||||
self.foo_token = add_0x(os.urandom(20).hex())
|
||||
self.bar_token = add_0x(os.urandom(20).hex())
|
||||
self.from_value = 42
|
||||
self.to_value = 13
|
||||
|
||||
backend = SQLBackend(self.db.dsn)
|
||||
tx = {
|
||||
'hash': self.tx_hash,
|
||||
'from': self.alice,
|
||||
'to': self.bob,
|
||||
'source_token': self.foo_token,
|
||||
'destination_token': self.bar_token,
|
||||
'from_value': self.from_value,
|
||||
'to_value': self.to_value,
|
||||
}
|
||||
backend.cache(tx, session=self.session)
|
||||
self.session.commit()
|
||||
|
||||
otx = Otx.load(self.tx_hash)
|
||||
txc = TxCache.load(self.tx_hash)
|
||||
|
||||
self.assertEqual(txc.otx_id, otx.id)
|
||||
|
||||
@@ -14,7 +14,7 @@ from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
|
||||
# test imports
|
||||
from tests.base import TestBase
|
||||
from tests.chainqueue_base import TestBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -5,9 +5,11 @@ import shutil
|
||||
import logging
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from leveldir.hex import HexDir
|
||||
|
||||
# local imports
|
||||
from chainqueue.fs.queue import FsQueue
|
||||
from chainqueue.fs.dir import HexDir
|
||||
from chainqueue.enum import StatusBits
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
@@ -5,9 +5,11 @@ import shutil
|
||||
import logging
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from leveldir.hex import HexDir
|
||||
|
||||
# local imports
|
||||
from chainqueue.fs.queue import FsQueue
|
||||
from chainqueue.fs.dir import HexDir
|
||||
from chainqueue.fs.entry import Entry
|
||||
from chainqueue.enum import StatusBits
|
||||
|
||||
@@ -30,9 +32,9 @@ class FsQueueEntryTest(unittest.TestCase):
|
||||
|
||||
|
||||
def test_entry(self):
|
||||
tx_hash = os.urandom(32)
|
||||
tx_content = os.urandom(128)
|
||||
Entry(tx_hash, tx_content)
|
||||
tx_hash = os.urandom(32).hex()
|
||||
tx_content = os.urandom(128).hex()
|
||||
Entry(0, tx_hash, tx_content)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
15
tests/test_helo.py
Normal file
15
tests/test_helo.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
|
||||
# local imports
|
||||
from tests.chainqueue_base import TestBase
|
||||
|
||||
|
||||
class TestHelo(TestBase):
|
||||
|
||||
def test_helo(self):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,84 +0,0 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import tempfile
|
||||
import shutil
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from chainqueue.fs.dir import HexDir
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class HexDirTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.dir = tempfile.mkdtemp()
|
||||
self.hexdir = HexDir(os.path.join(self.dir, 'q'), 4, 3, 2)
|
||||
logg.debug('setup hexdir root {}'.format(self.dir))
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.dir)
|
||||
logg.debug('cleaned hexdir root {}'.format(self.dir))
|
||||
|
||||
|
||||
def test_path(self):
|
||||
content = b'cdef'
|
||||
prefix = b'ab'
|
||||
label = b'\xde\xad\xbe\xef'
|
||||
self.hexdir.add(label, content, prefix=prefix)
|
||||
file_path = os.path.join(self.dir, 'q', 'DE', 'AD', 'BE', label.hex().upper())
|
||||
|
||||
f = open(file_path, 'rb')
|
||||
r = f.read()
|
||||
f.close()
|
||||
self.assertEqual(content, r)
|
||||
|
||||
f = open(self.hexdir.master_file, 'rb')
|
||||
r = f.read()
|
||||
f.close()
|
||||
self.assertEqual(prefix + label, r)
|
||||
|
||||
|
||||
def test_size(self):
|
||||
content = b'cdef'
|
||||
prefix = b'ab'
|
||||
label = b'\xde\xad\xbe\xef'
|
||||
with self.assertRaises(ValueError):
|
||||
self.hexdir.add(label, content, prefix=b'a')
|
||||
|
||||
|
||||
def test_index(self):
|
||||
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
|
||||
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
|
||||
c = self.hexdir.add(b'\x01\x02\x03\x04', b'baz', b'ef')
|
||||
self.assertEqual(c, 2)
|
||||
|
||||
|
||||
def test_edit(self):
|
||||
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
|
||||
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
|
||||
self.hexdir.add(b'\x01\x02\x03\x04', b'baz', b'ef')
|
||||
self.hexdir.set_prefix(1, b'ff')
|
||||
|
||||
f = open(self.hexdir.master_file, 'rb')
|
||||
f.seek(6)
|
||||
r = f.read(2)
|
||||
f.close()
|
||||
self.assertEqual(b'ff', r)
|
||||
|
||||
|
||||
def test_get(self):
|
||||
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
|
||||
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
|
||||
self.hexdir.add(b'\x01\x02\x03\x04', b'baz', b'ef')
|
||||
(prefix, key) = self.hexdir.get(1)
|
||||
self.assertEqual(b'\xbe\xef\xfe\xed', key)
|
||||
self.assertEqual(b'cd', prefix)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -15,7 +15,7 @@ from chainqueue.db.enum import (
|
||||
from chainqueue.sql.state import *
|
||||
|
||||
# test imports
|
||||
from tests.base import TestOtxBase
|
||||
from tests.chainqueue_base import TestOtxBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -6,7 +6,7 @@ from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.sql.state import *
|
||||
|
||||
# test imports
|
||||
from tests.base import TestOtxBase
|
||||
from tests.chainqueue_base import TestOtxBase
|
||||
|
||||
|
||||
class TestOtxState(TestOtxBase):
|
||||
|
||||
@@ -22,7 +22,7 @@ from chainqueue.sql.state import (
|
||||
from chainqueue.enum import StatusBits
|
||||
|
||||
# test imports
|
||||
from tests.base import TestTxBase
|
||||
from tests.chainqueue_base import TestTxBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -30,21 +30,207 @@ logg = logging.getLogger()
|
||||
|
||||
class TestTxQuery(TestTxBase):
|
||||
|
||||
def test_get_tx(self):
|
||||
tx = get_tx(self.chain_spec, self.tx_hash)
|
||||
expected_keys = [
|
||||
'otx_id',
|
||||
'status',
|
||||
'signed_tx',
|
||||
'nonce',
|
||||
]
|
||||
for k in tx.keys():
|
||||
expected_keys.remove(k)
|
||||
# def test_get_tx(self):
|
||||
# tx = get_tx(self.chain_spec, self.tx_hash)
|
||||
# expected_keys = [
|
||||
# 'otx_id',
|
||||
# 'status',
|
||||
# 'signed_tx',
|
||||
# 'nonce',
|
||||
# ]
|
||||
# for k in tx.keys():
|
||||
# expected_keys.remove(k)
|
||||
#
|
||||
# self.assertEqual(len(expected_keys), 0)
|
||||
#
|
||||
#
|
||||
# def test_nonce_tx(self):
|
||||
#
|
||||
# nonce_hashes = [self.tx_hash]
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# 42,
|
||||
# self.alice,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.alice,
|
||||
# self.bob,
|
||||
# self.foo_token,
|
||||
# self.bar_token,
|
||||
# self.from_value,
|
||||
# self.to_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
# self.session.add(txc)
|
||||
# self.session.commit()
|
||||
#
|
||||
# nonce_hashes.append(tx_hash)
|
||||
#
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# 41,
|
||||
# self.alice,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.alice,
|
||||
# self.bob,
|
||||
# self.foo_token,
|
||||
# self.bar_token,
|
||||
# self.from_value,
|
||||
# self.to_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
# self.session.add(txc)
|
||||
#
|
||||
# txs = get_nonce_tx_cache(self.chain_spec, 42, self.alice)
|
||||
# self.assertEqual(len(txs.keys()), 2)
|
||||
#
|
||||
# for h in nonce_hashes:
|
||||
# self.assertTrue(strip_0x(h) in txs)
|
||||
#
|
||||
#
|
||||
# def test_paused_tx_cache(self):
|
||||
# set_waitforgas(self.chain_spec, self.tx_hash)
|
||||
#
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# 43,
|
||||
# self.alice,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.alice,
|
||||
# self.bob,
|
||||
# self.foo_token,
|
||||
# self.bar_token,
|
||||
# self.from_value,
|
||||
# self.to_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
# self.session.add(txc)
|
||||
# self.session.commit()
|
||||
#
|
||||
# txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=self.alice, session=self.session)
|
||||
# self.assertEqual(len(txs.keys()), 1)
|
||||
#
|
||||
# txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
# self.assertEqual(len(txs.keys()), 1)
|
||||
#
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# 42,
|
||||
# self.bob,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.bob,
|
||||
# self.alice,
|
||||
# self.bar_token,
|
||||
# self.foo_token,
|
||||
# self.to_value,
|
||||
# self.from_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
# self.session.add(txc)
|
||||
# self.session.commit()
|
||||
#
|
||||
# txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
# self.assertEqual(len(txs.keys()), 1)
|
||||
#
|
||||
# set_waitforgas(self.chain_spec, tx_hash)
|
||||
# self.session.commit()
|
||||
#
|
||||
# txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
# self.assertEqual(len(txs.keys()), 2)
|
||||
#
|
||||
# txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=self.bob, session=self.session)
|
||||
# self.assertEqual(len(txs.keys()), 1)
|
||||
#
|
||||
#
|
||||
# def test_count(self):
|
||||
# for i in range(3):
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# i,
|
||||
# self.alice,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.alice,
|
||||
# self.bob,
|
||||
# self.foo_token,
|
||||
# self.bar_token,
|
||||
# self.from_value,
|
||||
# self.to_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
# self.session.add(txc)
|
||||
# set_ready(self.chain_spec, tx_hash, session=self.session)
|
||||
# set_reserved(self.chain_spec, tx_hash, session=self.session)
|
||||
# if i > 0:
|
||||
# set_sent(self.chain_spec, tx_hash, session=self.session)
|
||||
# if i == 2:
|
||||
# set_final(self.chain_spec, tx_hash, session=self.session)
|
||||
#
|
||||
# tx_hash = add_0x(os.urandom(32).hex())
|
||||
# signed_tx = add_0x(os.urandom(128).hex())
|
||||
# create(
|
||||
# self.chain_spec,
|
||||
# i,
|
||||
# self.bob,
|
||||
# tx_hash,
|
||||
# signed_tx,
|
||||
# session=self.session,
|
||||
# )
|
||||
# txc = TxCache(
|
||||
# tx_hash,
|
||||
# self.bob,
|
||||
# self.carol,
|
||||
# self.foo_token,
|
||||
# self.bar_token,
|
||||
# self.from_value,
|
||||
# self.to_value,
|
||||
# session=self.session,
|
||||
# )
|
||||
#
|
||||
# self.session.add(txc)
|
||||
# set_ready(self.chain_spec, tx_hash, session=self.session)
|
||||
# set_reserved(self.chain_spec, tx_hash, session=self.session)
|
||||
# set_sent(self.chain_spec, tx_hash, session=self.session)
|
||||
# self.session.commit()
|
||||
#
|
||||
# self.assertEqual(count_tx(self.chain_spec, status=StatusBits.IN_NETWORK | StatusBits.FINAL, status_target=StatusBits.IN_NETWORK), 2)
|
||||
# self.assertEqual(count_tx(self.chain_spec, address=self.alice, status=StatusBits.IN_NETWORK | StatusBits.FINAL, status_target=StatusBits.IN_NETWORK), 1)
|
||||
#
|
||||
|
||||
self.assertEqual(len(expected_keys), 0)
|
||||
|
||||
|
||||
def test_nonce_tx(self):
|
||||
def test_account_tx(self):
|
||||
|
||||
nonce_hashes = [self.tx_hash]
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
@@ -72,6 +258,8 @@ class TestTxQuery(TestTxBase):
|
||||
|
||||
nonce_hashes.append(tx_hash)
|
||||
|
||||
time_between = datetime.datetime.utcnow()
|
||||
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
create(
|
||||
@@ -94,140 +282,68 @@ class TestTxQuery(TestTxBase):
|
||||
)
|
||||
self.session.add(txc)
|
||||
|
||||
txs = get_nonce_tx_cache(self.chain_spec, 42, self.alice)
|
||||
self.assertEqual(len(txs.keys()), 2)
|
||||
|
||||
for h in nonce_hashes:
|
||||
self.assertTrue(strip_0x(h) in txs)
|
||||
nonce_hashes.append(tx_hash)
|
||||
|
||||
|
||||
def test_paused_tx_cache(self):
|
||||
set_waitforgas(self.chain_spec, self.tx_hash)
|
||||
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
create(
|
||||
self.chain_spec,
|
||||
43,
|
||||
self.alice,
|
||||
tx_hash,
|
||||
signed_tx,
|
||||
session=self.session,
|
||||
)
|
||||
txc = TxCache(
|
||||
tx_hash,
|
||||
self.alice,
|
||||
self.bob,
|
||||
self.foo_token,
|
||||
self.bar_token,
|
||||
self.from_value,
|
||||
self.to_value,
|
||||
session=self.session,
|
||||
)
|
||||
self.session.add(txc)
|
||||
self.session.commit()
|
||||
|
||||
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=self.alice, session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 3)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=tx_hash)
|
||||
self.assertEqual(len(txs.keys()), 1)
|
||||
|
||||
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=nonce_hashes[0])
|
||||
self.assertEqual(len(txs.keys()), 3)
|
||||
|
||||
bogus_hash = add_0x(os.urandom(32).hex())
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=bogus_hash)
|
||||
self.assertEqual(len(txs.keys()), 0)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=time_between)
|
||||
self.assertEqual(len(txs.keys()), 1)
|
||||
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
create(
|
||||
self.chain_spec,
|
||||
42,
|
||||
self.bob,
|
||||
tx_hash,
|
||||
signed_tx,
|
||||
session=self.session,
|
||||
)
|
||||
txc = TxCache(
|
||||
tx_hash,
|
||||
self.bob,
|
||||
self.alice,
|
||||
self.bar_token,
|
||||
self.foo_token,
|
||||
self.to_value,
|
||||
self.from_value,
|
||||
session=self.session,
|
||||
)
|
||||
self.session.add(txc)
|
||||
self.session.commit()
|
||||
time_before = time_between - datetime.timedelta(hours=1)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=time_before)
|
||||
self.assertEqual(len(txs.keys()), 3)
|
||||
|
||||
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 1)
|
||||
time_after = datetime.datetime.utcnow()
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=time_after)
|
||||
self.assertEqual(len(txs.keys()), 0)
|
||||
|
||||
set_waitforgas(self.chain_spec, tx_hash)
|
||||
self.session.commit()
|
||||
|
||||
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=2)
|
||||
self.assertEqual(len(txs.keys()), 2)
|
||||
|
||||
txs = get_paused_tx_cache(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=self.bob, session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=1)
|
||||
self.assertEqual(len(txs.keys()), 3)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=4)
|
||||
self.assertEqual(len(txs.keys()), 0)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=1, until=2)
|
||||
self.assertEqual(len(txs.keys()), 2)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=time_before, until=time_between)
|
||||
self.assertEqual(len(txs.keys()), 2)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, session=self.session, since=nonce_hashes[0], until=nonce_hashes[1])
|
||||
self.assertEqual(len(txs.keys()), 2)
|
||||
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, status=StatusBits.QUEUED, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 0)
|
||||
|
||||
set_ready(self.chain_spec, nonce_hashes[1], session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, status=StatusBits.QUEUED, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 1)
|
||||
|
||||
set_reserved(self.chain_spec, nonce_hashes[1], session=self.session)
|
||||
set_sent(self.chain_spec, nonce_hashes[1], session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, status=StatusBits.QUEUED, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 0)
|
||||
|
||||
def test_count(self):
|
||||
for i in range(3):
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
create(
|
||||
self.chain_spec,
|
||||
i,
|
||||
self.alice,
|
||||
tx_hash,
|
||||
signed_tx,
|
||||
session=self.session,
|
||||
)
|
||||
txc = TxCache(
|
||||
tx_hash,
|
||||
self.alice,
|
||||
self.bob,
|
||||
self.foo_token,
|
||||
self.bar_token,
|
||||
self.from_value,
|
||||
self.to_value,
|
||||
session=self.session,
|
||||
)
|
||||
self.session.add(txc)
|
||||
set_ready(self.chain_spec, tx_hash, session=self.session)
|
||||
set_reserved(self.chain_spec, tx_hash, session=self.session)
|
||||
if i > 0:
|
||||
set_sent(self.chain_spec, tx_hash, session=self.session)
|
||||
if i == 2:
|
||||
set_final(self.chain_spec, tx_hash, session=self.session)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, not_status=StatusBits.QUEUED, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 3)
|
||||
|
||||
tx_hash = add_0x(os.urandom(32).hex())
|
||||
signed_tx = add_0x(os.urandom(128).hex())
|
||||
create(
|
||||
self.chain_spec,
|
||||
i,
|
||||
self.bob,
|
||||
tx_hash,
|
||||
signed_tx,
|
||||
session=self.session,
|
||||
)
|
||||
txc = TxCache(
|
||||
tx_hash,
|
||||
self.bob,
|
||||
self.carol,
|
||||
self.foo_token,
|
||||
self.bar_token,
|
||||
self.from_value,
|
||||
self.to_value,
|
||||
session=self.session,
|
||||
)
|
||||
|
||||
self.session.add(txc)
|
||||
set_ready(self.chain_spec, tx_hash, session=self.session)
|
||||
set_reserved(self.chain_spec, tx_hash, session=self.session)
|
||||
set_sent(self.chain_spec, tx_hash, session=self.session)
|
||||
self.session.commit()
|
||||
|
||||
self.assertEqual(count_tx(self.chain_spec, status=StatusBits.IN_NETWORK | StatusBits.FINAL, status_target=StatusBits.IN_NETWORK), 2)
|
||||
self.assertEqual(count_tx(self.chain_spec, address=self.alice, status=StatusBits.IN_NETWORK | StatusBits.FINAL, status_target=StatusBits.IN_NETWORK), 1)
|
||||
txs = get_account_tx(self.chain_spec, self.alice, as_sender=True, as_recipient=False, not_status=StatusBits.QUEUED, status=StatusBits.IN_NETWORK, session=self.session)
|
||||
self.assertEqual(len(txs.keys()), 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -11,7 +11,7 @@ from chainqueue.sql.state import *
|
||||
from chainqueue.sql.query import get_tx_cache
|
||||
|
||||
# test imports
|
||||
from tests.base import TestTxBase
|
||||
from tests.chainqueue_base import TestTxBase
|
||||
|
||||
class TestTxCache(TestTxBase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user