示例#1
0
def test_get_leader_address():
    """
    Note that v1 & v2 have the same responses.
    """
    reference_response = "0x6911b75b2560be9a8f71164a33086be4511fc99a"

    # Check v1
    raw_response = base_request("hmy_getLeader", endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert type(reference_response) == type(response)
    if response.startswith("one1"):
        assert account.is_valid_address(
            response), f"Leader address is not a valid ONE address"
    else:
        ref_len = len(reference_response.replace("0x", ""))
        assert ref_len == len(response.replace(
            "0x", "")), f"Leader address hash is not of length {ref_len}"

    # Check v2
    raw_response = base_request("hmyv2_getLeader", endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    if response.startswith("one1"):
        assert account.is_valid_address(
            response), f"Leader address is not a valid ONE address"
    else:
        ref_len = len(reference_response.replace("0x", ""))
        assert ref_len == len(response.replace(
            "0x", "")), f"Leader address hash is not of length {ref_len}"
示例#2
0
 def validateONEAddress(self, oneAddress):
     valid = False
     try:
         valid = account.is_valid_address(oneAddress)
     except Exception as ex:
         HmyBidderLog.error(f'Validator validateONEAddress {ex}')
     finally:
         return valid
示例#3
0
def assert_valid_json_structure(reference, candidate):
    """
    Asserts that the given `candidate` dict (from JSON format) has the
    same keys and values as the `reference` dict (from JSON format).

    Note that if there is a list, the OVERLAPPING elements that are
    non-null/non-None are the ONLY elements checked.
    """
    if reference is None or candidate is None:
        return
    assert type(reference) == type(candidate), f"Expected type {type(reference)} not {type(candidate)} in {candidate}"
    if type(reference) == list and reference and candidate:  # If no element in list to check, ignore...
        for i in range(min(len(reference), len(candidate))):
            assert_valid_json_structure(reference[i], candidate[i])
    elif type(reference) == dict:
        for key in reference.keys():
            assert key in candidate.keys(), f"Expected key '{key}' in {json.dumps(candidate, indent=2)}"
            assert_valid_json_structure(reference[key], candidate[key])
    elif type(reference) == str:
        if reference.startswith("0x"):
            assert candidate.startswith("0x"), f"Expected a hex string, reference: {reference}, got {candidate}"
        if reference.startswith("one1") and account.is_valid_address(reference):
            assert account.is_valid_address(
                candidate), f"Expected a valid ONE address, reference: {reference}, got {candidate} "
示例#4
0
def assert_valid_test_from_address(address, shard, is_staking=False):
    """
    Asserts that the given address is a valid 'from' address for a test transaction.

    Note that this considers the invariant for transactions.
    """
    assert isinstance(
        address, str), f"Sanity check: Expect address {address} as a string."
    assert isinstance(shard,
                      int), f"Sanity check: Expect shard {shard} as am int."
    assert isinstance(
        is_staking,
        bool), f"Sanity check: Expect is_staking {is_staking} as a bool."
    assert account.is_valid_address(
        address), f"{address} is an invalid ONE address"
    if not account.get_balance(address, endpoint=endpoints[shard]) >= 1e18:
        raise AssertionError(
            f"Account {address} does not have at least 1 ONE on shard {shard}")
    if not is_staking and account.get_transaction_count(
            address, endpoint=endpoints[shard]) != 0:
        raise AssertionError(
            f"Account {address} has already sent a transaction, breaking the txs invariant"
        )
示例#5
0
 def validateONEAdress(self, one_address):
     return account.is_valid_address(one_address)
示例#6
0
def test_is_valid_address():
    assert account.is_valid_address(
        'one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur')
    assert not account.is_valid_address(
        'one1wje75aedczmj4dwjs0812xcg7vx0dy231cajk0')