Exemplo n.º 1
0
def test_kv_func(target: str, should_pass: bool, args: dict) -> None:
    """ Unit test for kv_func. """
    mock_func = pytest_mock.mock.Mock()
    if should_pass:
        kv_utils.kv_func(target, mock_func, *args)
        mock_func.assert_called_once()
    else:
        mock_func.side_effect = ValueError('')
        with pytest.raises((ValueError)):
            kv_utils.kv_func(target, mock_func, *args)
Exemplo n.º 2
0
from silksnake.remote.kv_remote import DEFAULT_TARGET

def kv_seek_tx_senders(kv_view: kv_remote.RemoteView, block_height: int, count: int = 1):
    """ Search for the provided block range in KV 'Receipts' bucket of turbo-geth/silkworm running at target.
    """
    for index, block_number in enumerate(range(block_height, block_height + count)):
        encoded_canonical_block_number = sedes.encode_canonical_block_number(block_number)
        print('CANONICAL HEADER\nREQ1 block_number:', block_number, '(key: ' + str(encoded_canonical_block_number.hex()) + ')')
        key, block_hash = kv_view.get(tables.BLOCK_HEADERS_LABEL, encoded_canonical_block_number)
        decoded_block_number = sedes.decode_canonical_block_number(key)
        assert decoded_block_number == block_number, 'ERR block number {} does not match!'.format(decoded_block_number)
        print('RSP1 block_hash:', block_hash.hex(), '\n')

        encoded_block_key = sedes.encode_block_key(block_number, block_hash)
        print('TX_SENDERS\nREQ2 block_number:', block_number, '(key: ' + str(encoded_block_key.hex()) + ')')
        key, value = kv_view.get(tables.TRANSACTION_SENDERS_LABEL, encoded_block_key)
        account_address_list = kv_metadata.decode_account_address_list(value) if key == encoded_block_key else []
        print('RSP2 senders(' + str(len(account_address_list)) + '): [')
        for account_address in account_address_list:
            print('address#' + str(account_address_list.index(account_address)), account_address.hex())
        print(']' if index == count - 1 else ']\n')

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('block_number', help='the block number as integer')
    parser.add_argument('-c', '--count', default=1, help='the number of blocks to seek as integer')
    parser.add_argument('-t', '--target', default=DEFAULT_TARGET, help='the server location as string <address>:<port>')
    args = parser.parse_args()

    kv_utils.kv_func(args.target, kv_seek_tx_senders, int(args.block_number), int(args.count))
Exemplo n.º 3
0
        key, value = kv_view.get(tables.BLOCK_HEADERS_LABEL,
                                 encoded_difficulty_block_key)
        decoded_block_number, decoded_block_hash = sedes.decode_difficulty_block_key(
            key)
        block_total_difficulty = sedes.decode_block_total_difficulty(value)
        assert decoded_block_number == block_number, 'ERR block number {} does not match!'.format(
            decoded_block_number)
        assert decoded_block_hash == block_hash, 'ERR block hash {} does not match!'.format(
            decoded_block_hash)
        print('RSP3 block_total_difficulty:', block_total_difficulty)

        if index != count - 1:
            print('\n')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('block_number', help='the block number as integer')
    parser.add_argument('-c',
                        '--count',
                        default=1,
                        help='the number of blocks to seek as integer')
    parser.add_argument('-t',
                        '--target',
                        default=DEFAULT_TARGET,
                        help='the server location as string <address>:<port>')
    args = parser.parse_args()

    kv_utils.kv_func(args.target, kv_seek_block_header, int(args.block_number),
                     int(args.count))
Exemplo n.º 4
0
              '(key: ' + str(change_set_key.hex()) + ')')
        key, value = kv_view.get(tables.PLAIN_STORAGE_CHANGE_SET_LABEL,
                                 change_set_key)
        storage_changeset = changeset.PlainStorageChangeSet(value)
        print('RSP2 key:', key.hex(), storage_changeset, '[')
        for i, (address, incarnation,
                change_set) in enumerate(storage_changeset):
            print('storage_change#' + str(i), 'address:', address,
                  'incarnation:', incarnation, change_set)
        print(']\n')

        if index != count - 1:
            print('\n')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('block_number', help='the block number as integer')
    parser.add_argument('-c',
                        '--count',
                        default=1,
                        help='the number of blocks to seek as integer')
    parser.add_argument('-t',
                        '--target',
                        default=DEFAULT_TARGET,
                        help='the server location as string <address>:<port>')
    args = parser.parse_args()

    kv_utils.kv_func(args.target, kv_seek_plain_change_sets,
                     int(args.block_number), int(args.count))
Exemplo n.º 5
0
        key, value = kv_view.get(tables.BLOCK_RECEIPTS_LABEL,
                                 encoded_block_key)
        decoded_block_number, decoded_block_hash = sedes.decode_block_key(key)
        block_receipt_list = receipt.TransactionReceipt.from_bytes(value)
        assert decoded_block_number == block_number, 'ERR block number {} does not match!'.format(
            decoded_block_number)
        assert decoded_block_hash == block_hash, 'ERR block hash {} does not match!'.format(
            decoded_block_hash)
        print('RSP2 block_receipts(' + str(len(block_receipt_list)) + '): [')
        for block_receipt in block_receipt_list:
            print('receipt#' + str(block_receipt_list.index(block_receipt)),
                  block_receipt)
        print(']' if index == count - 1 else ']\n')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('block_number', help='the block number as integer')
    parser.add_argument('-c',
                        '--count',
                        default=1,
                        help='the number of blocks to seek as integer')
    parser.add_argument('-t',
                        '--target',
                        default=DEFAULT_TARGET,
                        help='the server location as string <address>:<port>')
    args = parser.parse_args()

    kv_utils.kv_func(args.target, kv_seek_block_receipt,
                     int(args.block_number), int(args.count))
Exemplo n.º 6
0
                       block_height: int,
                       count: int = 1):
    """ Search for the provided block range in 'ETH_SUPPLY.v2' table of Turbo-Geth/Silkworm running at target.
    """
    for block_number in range(block_height, block_height + count):
        encoded_block_number = sedes.encode_block_number(block_number)
        print('REQ block_number:', block_number,
              '(key: ' + str(encoded_block_number.hex()) + ')')
        key, value = kv_view.get(tables.ETH_SUPPLY_LABEL, encoded_block_number)
        assert key == encoded_block_number, 'ERR key `{0}` does not match!'.format(
            key.hex())
        supply = int.from_bytes(value, 'big')
        print('RSP supply:', supply, '\n')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('block_number', help='the block number as integer')
    parser.add_argument('-c',
                        '--count',
                        default=1,
                        help='the number of blocks to seek as integer')
    parser.add_argument('-t',
                        '--target',
                        default=DEFAULT_TARGET,
                        help='the server location as string <address>:<port>')
    args = parser.parse_args()

    kv_utils.kv_func(args.target, kv_seek_eth_supply, int(args.block_number),
                     int(args.count))