Move extra tx to fixture, remove obsolete with_index methods
This commit is contained in:
parent
59fbc252f8
commit
5415b6adad
@ -113,35 +113,21 @@ class BloomCache(Cache):
|
|||||||
|
|
||||||
class DataCache(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):
|
def load_transactions_with_data(self, offset, limit, block_offset=None, block_limit=None, oldest=False):
|
||||||
if limit == 0:
|
if limit == 0:
|
||||||
limit = DEFAULT_LIMIT
|
limit = DEFAULT_LIMIT
|
||||||
rows = list_transactions_mined_with_data(self.session, offset, limit, block_offset, block_limit, oldest=oldest)
|
rows = list_transactions_mined_with_data(self.session, offset, limit, block_offset, block_limit, oldest=oldest)
|
||||||
return self.__load_transactions(rows)
|
return self.__process_rows(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)
|
|
||||||
|
|
||||||
|
|
||||||
def load_transactions_account_with_data(self, address, offset, limit, block_offset=None, block_limit=None, oldest=False):
|
def load_transactions_account_with_data(self, address, offset, limit, block_offset=None, block_limit=None, oldest=False):
|
||||||
if limit == 0:
|
if limit == 0:
|
||||||
limit = DEFAULT_LIMIT
|
limit = DEFAULT_LIMIT
|
||||||
rows = list_transactions_account_mined_with_data(self.session, address, offset, limit, block_offset, block_limit, oldest=oldest)
|
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 = []
|
tx_cache = []
|
||||||
highest_block = -1;
|
highest_block = -1;
|
||||||
lowest_block = -1;
|
lowest_block = -1;
|
||||||
|
@ -45,13 +45,7 @@ def tx_filter_content(self, offset, limit, address=None, block_offset=None, bloc
|
|||||||
c = DataCache(session)
|
c = DataCache(session)
|
||||||
b = None
|
b = None
|
||||||
if address == 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)
|
(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:
|
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)
|
(lowest_block, highest_block, tx_cache) = c.load_transactions_account_with_data_index(address, offset, limit, block_offset=block_offset, block_limit=block_limit)
|
||||||
|
|
||||||
|
@ -64,7 +64,6 @@ def txs(
|
|||||||
dt.timestamp(),
|
dt.timestamp(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
tx_number = 42
|
tx_number = 42
|
||||||
tx_hash_second = '0x' + os.urandom(32).hex()
|
tx_hash_second = '0x' + os.urandom(32).hex()
|
||||||
tx_signed_second = '0x' + os.urandom(128).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')
|
@pytest.fixture(scope='function')
|
||||||
def tag_txs(
|
def tag_txs(
|
||||||
init_database,
|
init_database,
|
||||||
|
@ -58,33 +58,11 @@ def test_cache_ranges(
|
|||||||
list_defaults,
|
list_defaults,
|
||||||
list_actors,
|
list_actors,
|
||||||
list_tokens,
|
list_tokens,
|
||||||
txs,
|
more_txs,
|
||||||
):
|
):
|
||||||
|
|
||||||
session = init_database
|
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
|
oldest = list_defaults['block'] - 1
|
||||||
mid = list_defaults['block']
|
mid = list_defaults['block']
|
||||||
newest = list_defaults['block'] + 2
|
newest = list_defaults['block'] + 2
|
||||||
@ -149,4 +127,77 @@ def test_cache_ranges(
|
|||||||
assert b[1] == oldest
|
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
|
||||||
|
#
|
||||||
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user