示例#1
0
def test_get_block_transaction_count_by_hash_v2():
    init_tx_record = initial_funding[0]
    init_tx = transaction.get_transaction_by_hash(
        init_tx_record["hash"], endpoints[init_tx_record["from-shard"]])

    raw_response = base_request("hmyv2_getBlockTransactionCountByHash",
                                params=[init_tx["blockHash"]],
                                endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert isinstance(response, int)
    assert response > 0, "Expected transaction count > 0 due to initial transactions"
示例#2
0
def test_errors():
    with pytest.raises(exceptions.RPCError):
        transaction.get_pending_transactions(fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_transaction_error_sink(fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_pool_stats(fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_transaction_by_hash('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_transaction_by_block_hash_and_index(
            '', 1, endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_transaction_by_block_number_and_index(
            1, 1, endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_transaction_receipt('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.send_raw_transaction('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_pending_cx_receipts(fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_cx_receipt_by_hash('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.resend_cx_receipt('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_staking_transaction_by_hash('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_staking_transaction_by_block_hash_and_index(
            '', 1, endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_staking_transaction_by_block_number_and_index(
            1, 1, endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_staking_transaction_error_sink(endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.send_raw_staking_transaction('', endpoint=fake_shard)
    with pytest.raises(exceptions.RPCError):
        transaction.get_pending_staking_transactions(endpoint=fake_shard)
示例#3
0
def test_get_block_transaction_count_by_hash_v1():
    init_tx_record = initial_funding[0]
    init_tx = transaction.get_transaction_by_hash(
        init_tx_record["hash"], endpoints[init_tx_record["from-shard"]])

    raw_response = base_request("hmy_getBlockTransactionCountByHash",
                                params=[init_tx["blockHash"]],
                                endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert isinstance(response, str) and response.startswith(
        "0x")  # Must be a hex string
    assert int(
        response,
        16) > 0, "Expected transaction count > 0 due to initial transactions"
示例#4
0
def test_get_block_by_hash_v2():
    """
    Note the use of a JSON object in the param. This is different from v1.

    Note: param options for 'withSigners' will NOT return any sensical data
    in staking epoch (since it returns ONE addresses) and is subject to removal, thus is not tested here.
    """
    reference_response = {
        "difficulty":
        0,
        "epoch":
        0,
        "extraData":
        "0x",
        "gasLimit":
        80000000,
        "gasUsed":
        105000,
        "hash":
        "0x8e0ca00640ea70afe078d02fd571085f14d5953dca7be8ef4efc6a02db090156",
        "logsBloom":
        "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "miner":
        "one1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqquzw7vz",
        "mixHash":
        "0x0000000000000000000000000000000000000000000000000000000000000000",
        "nonce":
        0,
        "number":
        9,
        "parentHash":
        "0xd5d0e786f1a0c6d8d2ea038ef5f8272bb4e4def1838d61b7e1c395f4b763c09d",
        "receiptsRoot":
        "0x100f3336862d22706bbe26d67e5abf90f8f25ec5a22c4446835b6beaa6b59536",
        "size":
        2410,
        "stateRoot":
        "0x8a39cac10f8d917564a4e6033dc303d6a47d9fc8768c220640de5bb89765e0cf",
        "timestamp":
        1594660718,
        "transactions": [
            {
                "blockHash":
                "0x8e0ca00640ea70afe078d02fd571085f14d5953dca7be8ef4efc6a02db090156",
                "blockNumber":
                9,
                "from":
                "one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur",
                "timestamp":
                1594660718,
                "gas":
                21000,
                "gasPrice":
                1000000000,
                "hash":
                "0x5718a2fda967f051611ccfaf2230dc544c9bdd388f5759a42b2fb0847fc8d759",
                "input":
                "0x",
                "nonce":
                0,
                "to":
                "one1v92y4v2x4q27vzydf8zq62zu9g0jl6z0lx2c8q",
                "transactionIndex":
                0,
                "value":
                100000000000000000000000,
                "shardID":
                0,
                "toShardID":
                0,
                "v":
                "0x28",
                "r":
                "0x76b6130bc018cedb9f8891343fd8982e0d7f923d57ea5250b8bfec9129d4ae22",
                "s":
                "0xfbc01c988d72235b4c71b21ce033d4fc5f82c96710b84685de0578cff075a0a"
            },
        ],
        "transactionsRoot":
        "0x8954e7b3ec6ef4b04dcaf2829d9ce8ed764f636445fe77d2f4e5ef157e69dbbd",
        "uncles": [],
        "viewID":
        9
    }

    init_tx_record = initial_funding[0]
    init_tx = transaction.get_transaction_by_hash(
        init_tx_record["hash"], endpoints[init_tx_record["from-shard"]])
    raw_response = base_request(
        "hmyv2_getBlockByHash",
        params=[init_tx["blockHash"], {
            "fullTx": True,
            "inclTx": True
        }],
        endpoint=endpoints[init_tx_record["from-shard"]])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert len(
        response["transactions"]
    ) > 0, "Expected transaction on block due to initial transactions"
    for tx in response["transactions"]:
        assert tx["blockHash"] == init_tx[
            "blockHash"], f"Transaction in block {init_tx['blockHash']} does not have same block hash"
        assert tx["shardID"] == init_tx_record[
            "from-shard"], f"Transaction in block from shard {init_tx_record['from-shard']} does not have same from shard ({tx['shardID']})"
示例#5
0
def test_get_blocks_v2():
    """
    Only difference in param of RPC is hex string in v1 and decimal in v2.

    Note: param options for 'withSigners' will NOT return any sensical data
    in staking epoch (since it returns ONE addresses) and is subject to removal, thus is not tested here.
    """
    reference_response_blk = {
        "difficulty":
        0,
        "epoch":
        0,
        "extraData":
        "0x",
        "gasLimit":
        80000000,
        "gasUsed":
        105000,
        "hash":
        "0xf14c18213b1845ee09c41c5ecd321be5b745ef42e80d8e8a6bfd116452781465",
        "logsBloom":
        "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "miner":
        "one1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqquzw7vz",
        "mixHash":
        "0x0000000000000000000000000000000000000000000000000000000000000000",
        "nonce":
        0,
        "number":
        3,
        "parentHash":
        "0xe4fe8484b94d3498acc183a8bcf9e0bef6d30b1a81d5628fbc67f9a7328651e8",
        "receiptsRoot":
        "0x100f3336862d22706bbe26d67e5abf90f8f25ec5a22c4446835b6beaa6b59536",
        "size":
        1239,
        "stakingTransactions": [],
        "stateRoot":
        "0x1dc641cf516efe9ff2250f9c8db069ba4b9954160bf70cbe376ed11904b4edf5",
        "timestamp":
        1594656146,
        "transactions": [
            {
                "blockHash":
                "0xf14c18213b1845ee09c41c5ecd321be5b745ef42e80d8e8a6bfd116452781465",
                "blockNumber":
                3,
                "from":
                "one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur",
                "timestamp":
                1594656146,
                "gas":
                21000,
                "gasPrice":
                1000000000,
                "hash":
                "0x5718a2fda967f051611ccfaf2230dc544c9bdd388f5759a42b2fb0847fc8d759",
                "input":
                "0x",
                "nonce":
                0,
                "to":
                "one1v92y4v2x4q27vzydf8zq62zu9g0jl6z0lx2c8q",
                "transactionIndex":
                0,
                "value":
                100000000000000000000000,
                "shardID":
                0,
                "toShardID":
                0,
                "v":
                "0x28",
                "r":
                "0x76b6130bc018cedb9f8891343fd8982e0d7f923d57ea5250b8bfec9129d4ae22",
                "s":
                "0xfbc01c988d72235b4c71b21ce033d4fc5f82c96710b84685de0578cff075a0a"
            },
        ],
        "transactionsRoot":
        "0x8954e7b3ec6ef4b04dcaf2829d9ce8ed764f636445fe77d2f4e5ef157e69dbbd",
        "uncles": [],
        "viewID":
        3
    }

    init_tx_record = initial_funding[0]
    init_tx = transaction.get_transaction_by_hash(
        init_tx_record["hash"], endpoints[init_tx_record["from-shard"]])
    start_blk, end_blk = max(0,
                             int(init_tx["blockNumber"], 16) - 2), int(
                                 init_tx["blockNumber"], 16)
    raw_response = base_request(
        "hmyv2_getBlocks",
        params=[start_blk, end_blk, {
            "fullTx": True,
            "inclStaking": True
        }],
        endpoint=endpoints[init_tx_record["from-shard"]])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    for blk in response:
        assert_valid_json_structure(reference_response_blk, blk)
    assert len(
        response[-1]["transactions"]
    ) > 0, "Expected transaction on last block due to initial transactions"
    for blk in response:
        assert start_blk <= blk[
            "number"] <= end_blk, f"Got block number {blk['number']}, which is not in range [{start_blk},{end_blk}]"