Move extra tx to fixture, remove obsolete with_index methods

This commit is contained in:
nolash 2021-07-25 19:20:02 +02:00
parent 59fbc252f8
commit 5415b6adad
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 117 additions and 50 deletions

View File

@ -113,35 +113,21 @@ class BloomCache(Cache):
class DataCache(Cache):
def load_transactions_with_data_index(self, offset, limit, block_offset=None, block_limit=None, oldest=False):
if limit == 0:
limit = DEFAULT_LIMIT
rows = list_transactions_mined_with_data_index(self.session, offset, limit, block_offset, block_limit, oldest=oldest)
return self.__load_transactions(rows)
def load_transactions_with_data(self, offset, limit, block_offset=None, block_limit=None, oldest=False):
if limit == 0:
limit = DEFAULT_LIMIT
rows = list_transactions_mined_with_data(self.session, offset, limit, block_offset, block_limit, oldest=oldest)
return self.__load_transactions(rows)
def load_transactions_account_with_data_index(self, address, offset, limit, block_offset=None, block_limit=None, oldest=False):
if limit == 0:
limit = DEFAULT_LIMIT
rows = list_transactions_account_mined_with_data_index(self.session, address, offset, limit, block_offset, block_limit, oldest=oldest)
return self.__load_transactions(rows)
return self.__process_rows(rows)
def load_transactions_account_with_data(self, address, offset, limit, block_offset=None, block_limit=None, oldest=False):
if limit == 0:
limit = DEFAULT_LIMIT
rows = list_transactions_account_mined_with_data(self.session, address, offset, limit, block_offset, block_limit, oldest=oldest)
return self.__load_transactions(rows)
return self.__process_rows(rows)
def __load_transactions(self, rows):
def __process_rows(self, rows):
tx_cache = []
highest_block = -1;
lowest_block = -1;

View File

@ -45,13 +45,7 @@ def tx_filter_content(self, offset, limit, address=None, block_offset=None, bloc
c = DataCache(session)
b = None
if address == None:
if block_offset:
(lowest_block, highest_block, tx_cache) = c.load_transactions_with_data(offset, limit, block_offset=block_offset, block_limit=block_limit, oldest=oldest)
else:
(lowest_block, highest_block, tx_cache) = c.load_transactions_with_data_index(offset, limit, block_offset=block_offset, block_limit=block_limit)
else:
if block_offset:
(lowest_block, highest_block, tx_cache) = c.load_transactions_account_with_data(address, offset, limit, block_offset=block_offset, block_limit=block_limit)
else:
(lowest_block, highest_block, tx_cache) = c.load_transactions_account_with_data_index(address, offset, limit, block_offset=block_offset, block_limit=block_limit)

View File

@ -64,7 +64,6 @@ def txs(
dt.timestamp(),
)
tx_number = 42
tx_hash_second = '0x' + os.urandom(32).hex()
tx_signed_second = '0x' + os.urandom(128).hex()
@ -93,6 +92,43 @@ def txs(
]
@pytest.fixture(scope='function')
def more_txs(
init_database,
list_defaults,
list_actors,
list_tokens,
txs,
):
session = init_database
tx_number = 666
tx_hash = '0x' + os.urandom(32).hex()
tx_signed = '0x' + os.urandom(128).hex()
nonce = 3
dt = datetime.datetime.utcnow()
dt += datetime.timedelta(hours=1)
db.add_transaction(
session,
tx_hash,
list_defaults['block']+2,
tx_number,
list_actors['alice'],
list_actors['diane'],
list_tokens['bar'],
list_tokens['bar'],
2048,
4096,
False,
dt.timestamp(),
)
session.commit()
return txs + [tx_hash]
@pytest.fixture(scope='function')
def tag_txs(
init_database,

View File

@ -58,33 +58,11 @@ def test_cache_ranges(
list_defaults,
list_actors,
list_tokens,
txs,
more_txs,
):
session = init_database
tx_number = 666
tx_hash_second = '0x' + os.urandom(32).hex()
tx_signed_second = '0x' + os.urandom(128).hex()
nonce = 3
dt = datetime.datetime.utcnow()
dt += datetime.timedelta(hours=1)
db.add_transaction(
session,
tx_hash_second,
list_defaults['block']+2,
tx_number,
list_actors['alice'],
list_actors['diane'],
list_tokens['bar'],
list_tokens['bar'],
2048,
4096,
False,
dt.timestamp(),
)
oldest = list_defaults['block'] - 1
mid = list_defaults['block']
newest = list_defaults['block'] + 2
@ -149,4 +127,77 @@ def test_cache_ranges(
assert b[1] == oldest
def test_cache_ranges_data(
init_database,
list_defaults,
list_actors,
list_tokens,
txs,
):
session = init_database
oldest = list_defaults['block'] - 1
mid = list_defaults['block']
newest = list_defaults['block'] + 2
c = DataCache(session)
b = c.load_transactions_with_data(0, 100)
assert len(b) == 3
# b = c.load_transactions(1, 2)
# assert b[0] == oldest
# assert b[1] == mid
#
# b = c.load_transactions(0, 2)
# assert b[0] == mid
# assert b[1] == newest
#
# b = c.load_transactions(0, 1)
# assert b[0] == newest
# assert b[1] == newest
#
# b = c.load_transactions(0, 100, oldest=True)
# assert b[0] == oldest
# assert b[1] == newest
#
# b = c.load_transactions(0, 100, block_offset=list_defaults['block'])
# assert b[0] == mid
# assert b[1] == newest
#
# b = c.load_transactions(0, 100, block_offset=list_defaults['block'] - 1, block_limit=list_defaults['block'])
# assert b[0] == oldest
# assert b[1] == mid
#
# # now check when supplying account
# b = c.load_transactions_account(list_actors['alice'], 0, 100)
# assert b[0] == oldest
# assert b[1] == newest
#
# b = c.load_transactions_account(list_actors['bob'], 0, 100)
# assert b[0] == mid
# assert b[1] == mid
#
# b = c.load_transactions_account(list_actors['diane'], 0, 100)
# assert b[0] == oldest
# assert b[1] == newest
#
# # add block filter to the mix
# b = c.load_transactions_account(list_actors['alice'], 0, 100, block_offset=list_defaults['block'])
# assert b[0] == mid
# assert b[1] == newest
#
# b = c.load_transactions_account(list_actors['alice'], 0, 100, block_offset=list_defaults['block'])
# assert b[0] == mid
# assert b[1] == newest
#
# b = c.load_transactions_account(list_actors['bob'], 0, 100, block_offset=list_defaults['block'] - 1, block_limit=list_defaults['block'])
# assert b[0] == mid
# assert b[1] == mid
#
# b = c.load_transactions_account(list_actors['diane'], 0, 100, block_offset=list_defaults['block'] - 1, block_limit=list_defaults['block'])
# assert b[0] == oldest
# assert b[1] == oldest
#
#