-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add txs pagesize integration test script
- Loading branch information
Showing
2 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from functools import partial | ||
import os | ||
import argparse | ||
import graphsense | ||
from graphsense.api import addresses_api, entities_api | ||
|
||
''' | ||
Retrieves all rows iteratively in pages of given pagesize and verifies temporal | ||
order. | ||
''' | ||
def txs_pagesize_tester(currency, id, **kwargs): | ||
configuration = graphsense.Configuration( | ||
host = os.environ.get('API_URL', "http://localhost:9000") | ||
) | ||
|
||
configuration.api_key['api_key'] = os.environ.get('API_KEY', None) | ||
|
||
# Enter a context with an instance of the API client | ||
with graphsense.ApiClient(configuration) as api_client: | ||
# Create an instance of the API class | ||
if id.isdigit(): | ||
api_instance = entities_api.EntitiesApi(api_client) | ||
if 'neighbor' in kwargs: | ||
request_method = partial(api_instance.list_entity_links, | ||
currency, | ||
int(id), | ||
int(kwargs['neighbor']) | ||
) | ||
kwargs.pop('neighbor') | ||
else: | ||
request_method = partial(api_instance.list_entity_txs, | ||
currency, | ||
int(id) | ||
) | ||
else: | ||
api_instance = addresses_api.AddressesApi(api_client) | ||
if 'neighbor' in kwargs: | ||
request_method = partial(api_instance.list_address_links, | ||
currency, | ||
id, | ||
kwargs['neighbor'] | ||
) | ||
kwargs.pop('neighbor') | ||
else: | ||
request_method = partial(api_instance.list_address_txs, | ||
currency, | ||
id | ||
) | ||
page = "" | ||
# example passing only required values which don't have defaults set | ||
min_timestamp = None | ||
timestamps = [] | ||
desc = kwargs.get('order') == 'desc' | ||
while True: | ||
#print(f'page {page}') | ||
# Get all transactions an address has been involved in | ||
kwargs['page'] = page | ||
api_response = request_method(**kwargs) | ||
page = getattr(api_response, 'next_page', None) | ||
#print(page) | ||
resp = api_response.links if hasattr(api_response, 'links') else api_response.address_txs | ||
assert len(resp) <= kwargs['pagesize'], \ | ||
f"response length bigger than pagesize {len(resp)}" | ||
for tx in resp: | ||
#print(f'{tx}') | ||
timestamps.append(tx.timestamp) | ||
if min_timestamp is None: | ||
min_timestamp = tx.timestamp | ||
continue | ||
if desc and tx.timestamp > min_timestamp \ | ||
or not desc and tx.timestamp < min_timestamp: | ||
raise RuntimeError(f'tx {tx.tx_hash} {tx.currency} {tx.timestamp} {min_timestamp}') | ||
min_timestamp = tx.timestamp | ||
|
||
if page is None: | ||
break | ||
return timestamps | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Process some input parameters.") | ||
|
||
parser.add_argument('--currency', type=str, required=True, help='Specify the currency as a string.') | ||
parser.add_argument('--token_currency', type=str, required=False, help='Specify the token currency as a string.') | ||
parser.add_argument('--id', type=str, required=True, help='Specify the ID as a string.') | ||
|
||
parser.add_argument('--neighbor', type=str, help='Specify the neighbor as a string (optional).') | ||
|
||
parser.add_argument('--pagesize', type=int, required=True, help='Specify the page size as an integer.') | ||
parser.add_argument('--min', type=int, required=False, help='Specify the min height as an integer.') | ||
parser.add_argument('--max', type=int, required=False, help='Specify the max height as an integer.') | ||
parser.add_argument('--desc', action='store_true', required=False, help='Specify if results should be retrieved in descending order (default: ascending).') | ||
|
||
# Parse the arguments | ||
args = parser.parse_args() | ||
|
||
kwargs = {} | ||
kwargs['pagesize'] = args.pagesize | ||
if args.min: | ||
kwargs['min_height'] = args.min | ||
if args.max: | ||
kwargs['max_height'] = args.max | ||
if args.desc: | ||
kwargs['order'] = 'desc' | ||
if not args.neighbor and args.token_currency: | ||
kwargs['token_currency'] = args.token_currency | ||
|
||
txs_pagesize_tester(args.currency, args.id, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
from txs_pagesize_tester import txs_pagesize_tester | ||
|
||
pagesizes = [100, 53, 7, 1] | ||
|
||
test_sets = [ | ||
{'currency': 'eth', | ||
'id': '0x255c0dc1567739ceb2c8cd0fddcf1706563868d0' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x10c318b1d817396a8a66016438ac9dfb615ffcf1', | ||
'min_height': 7957441 | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x10c318b1d817396a8a66016438ac9dfb615ffcf1', | ||
'max_height': 7957441 | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x10c318b1d817396a8a66016438ac9dfb615ffcf1', | ||
'min_height': 7957441, | ||
'max_height': 9207262 | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'eth' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'usdc' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'weth' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'weth', | ||
'min_height': 9010434, | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'weth', | ||
'max_height': 12878677, | ||
}, | ||
{'currency': 'eth', | ||
'id': '0x09826189b333741c3542f12dfa6bb9e06c7237e3', | ||
'token_currency': 'weth', | ||
'min_height': 9010434, | ||
'max_height': 12878677, | ||
}, | ||
{'currency': 'eth', | ||
'id': '0xd75821a3e9a7878869bfd854d1f99f5e2d360790', | ||
'neighbor': '0x641faa71fa1545b7dd398fba8bf94d2f6d8e766d' | ||
}, | ||
{'currency': 'eth', | ||
'id': '0xd75821a3e9a7878869bfd854d1f99f5e2d360790', | ||
'neighbor': '0x641faa71fa1545b7dd398fba8bf94d2f6d8e766d', | ||
'min_height': 6495332, | ||
}, | ||
{'currency': 'eth', | ||
'id': '0xd75821a3e9a7878869bfd854d1f99f5e2d360790', | ||
'neighbor': '0x641faa71fa1545b7dd398fba8bf94d2f6d8e766d', | ||
'max_height': 6545717, | ||
}, | ||
{'currency': 'eth', | ||
'id': '0xd75821a3e9a7878869bfd854d1f99f5e2d360790', | ||
'neighbor': '0x641faa71fa1545b7dd398fba8bf94d2f6d8e766d', | ||
'min_height': 6495332, | ||
'max_height': 6545717, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB' | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'max_height': 40216462, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'max_height': 40216462, | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'trx' | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'trx', | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'trx', | ||
'max_height': 40216462, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'trx', | ||
'max_height': 40216462, | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'usdt' | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'usdt', | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'usdt', | ||
'max_height': 40216462, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TUzemi3pXCBAUJpoPTYfVwHucsbk6tT5GB', | ||
'token_currency': 'usdt', | ||
'max_height': 40216462, | ||
'min_height': 20429760, | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TJsC8UgrLaEJz3vgKsyNFDDYFEM42K3GjC', | ||
'neighbor': 'TNdK2XuTpzjcM9vns8LG9258bxaLap5gih', | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TJsC8UgrLaEJz3vgKsyNFDDYFEM42K3GjC', | ||
'neighbor': 'TNdK2XuTpzjcM9vns8LG9258bxaLap5gih', | ||
'max_height': 39913745 | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TJsC8UgrLaEJz3vgKsyNFDDYFEM42K3GjC', | ||
'neighbor': 'TNdK2XuTpzjcM9vns8LG9258bxaLap5gih', | ||
'min_height': 39696021 | ||
}, | ||
{'currency': 'trx', | ||
'id': 'TJsC8UgrLaEJz3vgKsyNFDDYFEM42K3GjC', | ||
'neighbor': 'TNdK2XuTpzjcM9vns8LG9258bxaLap5gih', | ||
'min_height': 39696021, | ||
'max_height': 39913745 | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'min_height': 718034, | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'max_height': 731854, | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'min_height': 718034, | ||
'max_height': 731854, | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'neighbor': 'bc1qtg3rejp0vw7mvkm03wc8fttjteaeqseq8046gm' | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'neighbor': 'bc1qtg3rejp0vw7mvkm03wc8fttjteaeqseq8046gm', | ||
'min_height': 730710, | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'neighbor': 'bc1qtg3rejp0vw7mvkm03wc8fttjteaeqseq8046gm', | ||
'max_height': 736094, | ||
}, | ||
{'currency': 'btc', | ||
'id': '1FN9eZU2b2S6u6mJy8nrVjPxQhCdkmE7mr', | ||
'neighbor': 'bc1qtg3rejp0vw7mvkm03wc8fttjteaeqseq8046gm', | ||
'min_height': 730710, | ||
'max_height': 736094, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'min_height': 718034, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'max_height': 731854, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'min_height': 718034, | ||
'max_height': 731854, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'neighbor': '887478908' | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'neighbor': '887478908', | ||
'min_height': 730710, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'neighbor': '887478908', | ||
'max_height': 736094, | ||
}, | ||
{'currency': 'btc', | ||
'id': '890145530', | ||
'neighbor': '887478908', | ||
'min_height': 730710, | ||
'max_height': 736094, | ||
}, | ||
] | ||
|
||
|
||
for order in ['desc', 'asc']: | ||
for kwargs in test_sets: | ||
direction_set = [None] | ||
if 'neighbor' not in kwargs: | ||
direction_set = [None, 'out', 'in'] | ||
for direction in direction_set: | ||
prev_timestamps = None | ||
if direction: | ||
kwargs['direction'] = direction | ||
else: | ||
kwargs.pop('direction', None) | ||
print(f'Testing {kwargs}, order = {order}, direction = {direction}') | ||
for pagesize in pagesizes: | ||
print(f'pagesize = {pagesize}') | ||
timestamps = txs_pagesize_tester(pagesize=pagesize, | ||
order=order, | ||
**kwargs | ||
) | ||
if prev_timestamps is None: | ||
prev_timestamps = timestamps | ||
assert timestamps == prev_timestamps, \ | ||
"result lengths not equal" | ||
prev_timestamp = timestamps | ||
print(f'length {len(timestamps)}') | ||
|
||
|
||
|