Beispiel #1
0
def test_send_raw_transaction_v2():
    tx = {
        "from": "one13lu674f3jkfk2qhsngfc2vhcf372wprctdjvgu",
        "to": "one14jeshxg75gdr5dz8sg7fm2sjvw7snnsdw98f0y",
        # humor brain crouch walk focus slush material sort used refuse exist prefer obscure above grow maze scheme myself liquid lab fresh awful easily debris
        "amount": "1000",
        "from-shard": 0,
        "to-shard": 0,
        "hash": "0x99919613fce4bbc9f4a068373bbb67b3f7e5ce34a7a1eef866a32284ec70261a",
        "nonce": "0x0",
        "signed-raw-tx": "0xf86e80843b9aca00825208808094acb30b991ea21a3a3447823c9daa1263bd09ce0d893635c9adc5dea000008028a03ab9d7562ca97f7a57ccca3b691f5b7b8e75a2f0f4d38109bb818da5199d62cda02cb8180d0fed4cfe03d25f3458c7d11c91185273b6ae5e902d1debe998326997",
    }
    reference_response = {
        "code": -32000,
        "message": "transaction already finalized"
    }

    if get_transaction(tx["hash"], tx["from-shard"]) is not None:
        pytest.skip(f"Test transaction (hash {tx['hash']}) already present on chain...")

    # Submit new transaction...
    response = base_request('hmyv2_sendRawTransaction', params=[tx["signed-raw-tx"]],
                            endpoint=endpoints[tx["from-shard"]])
    tx_hash = check_and_unpack_rpc_response(response, expect_error=False)
    assert tx_hash == tx["hash"], f"Expect submitted transaction to get tx hash of {tx['hash']}, got {tx_hash}"

    # Test finalized transaction error...
    start_time = time.time()
    while time.time() - start_time <= tx_timeout:
        if get_transaction(tx["hash"], tx["from-shard"]) is not None:
            raw_response = base_request('hmyv2_sendRawTransaction', params=[tx["signed-raw-tx"]],
                                        endpoint=endpoints[tx["from-shard"]])
            response = check_and_unpack_rpc_response(raw_response, expect_error=True)
            assert_valid_json_structure(reference_response, response)
            assert reference_response["code"] == response["code"], f"Expected error code {reference_response['code']}, " \
                                                                   f"got {response['code']}"
            return
        time.sleep(0.25)
    raise AssertionError(f"Timeout! Finalized transaction not found for {json.dumps(tx, indent=2)}")
Beispiel #2
0
def test_send_raw_transaction_v1():
    tx = {
        "from": "one1p5x4t7mvd94jn5awxmhlvgqmlazx5egzz7rveg",
        "to": "one1mjunf85vnhc4drv57ugsyg2fxjnsq920qzkpwq",
        # identify energy glimpse train script text town amused major slot armed fiction park alter dance live snow path picture desk metal voice distance good
        "amount": "1000",
        "from-shard": 0,
        "to-shard": 0,
        "hash": "0x5c5029de0c45a692265ec55d5218834c837c4c8d7cd2ed9598a858ed8ee8c811",
        "nonce": "0x0",
        "signed-raw-tx": "0xf86e80843b9aca00825208808094dcb9349e8c9df1568d94f71102214934a700154f893635c9adc5dea000008028a0e727143889e1ac8fbcaed655e186407b6b6978cbff63f79c0a6bd57bfb75ef06a07409113d6df43969d20552c9ea239e930a1ae736a6f3d2b3d4b8a3392217f99d",
    }
    reference_response = {
        "code": -32000,
        "message": "transaction already finalized"
    }

    if get_transaction(tx["hash"], tx["from-shard"]) is not None:
        pytest.skip(f"Test transaction (hash {tx['hash']}) already present on chain...")

    # Submit new transaction...
    response = base_request('hmy_sendRawTransaction', params=[tx["signed-raw-tx"]],
                            endpoint=endpoints[tx["from-shard"]])
    tx_hash = check_and_unpack_rpc_response(response, expect_error=False)
    assert tx_hash == tx["hash"], f"Expect submitted transaction to get tx hash of {tx['hash']}, got {tx_hash}"

    # Test finalized transaction error...
    start_time = time.time()
    while time.time() - start_time <= tx_timeout:
        if get_transaction(tx["hash"], tx["from-shard"]) is not None:
            raw_response = base_request('hmy_sendRawTransaction', params=[tx["signed-raw-tx"]],
                                        endpoint=endpoints[tx["from-shard"]])
            response = check_and_unpack_rpc_response(raw_response, expect_error=True)
            assert_valid_json_structure(reference_response, response)
            assert reference_response["code"] == response["code"], f"Expected error code {reference_response['code']}, " \
                                                                   f"got {response['code']}"
            return
        time.sleep(0.25)
    raise AssertionError(f"Timeout! Finalized transaction not found for {json.dumps(tx, indent=2)}")
Beispiel #3
0
def test_get_latest_chain_headers():
    """
    Note that v1 & v2 have the same responses.
    """
    reference_response = {
        "beacon-chain-header": {
            "shard-id": 0,
            "block-header-hash":
            "0x127437058641851cdfe10e9509aa060b169acbce79eb63d04e3be2cfbe596695",
            "block-number": 171,
            "view-id": 171,
            "epoch": 33
        },
        "shard-chain-header": {
            "shard-id": 1,
            "block-header-hash":
            "0x0ca6c681e128f47e35e4c578b6381f3f8dda8ec9fcb0a8935a0bf12a2e7a19a3",
            "block-number": 171,
            "view-id": 171,
            "epoch": 33
        }
    }

    # Check v1
    raw_response = base_request("hmy_getLatestChainHeaders",
                                endpoint=endpoints[1])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["beacon-chain-header"]["shard-id"] == 0
    assert response["shard-chain-header"]["shard-id"] == 1

    # Check v2
    raw_response = base_request("hmyv2_getLatestChainHeaders",
                                endpoint=endpoints[1])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["beacon-chain-header"]["shard-id"] == 0
    assert response["shard-chain-header"]["shard-id"] == 1
def test_get_block_by_number_v1():
    reference_response = {
        "difficulty": 0,
        "epoch": "0x0",
        "extraData": "0x",
        "gasLimit": "0x4c4b400",
        "gasUsed": "0x0",
        "hash":
        "0x0994da932016ba93937ad46b9a1207ecd6d4fbd689d7f8ddf1f926cd3ebc6016",
        "logsBloom":
        "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "miner": "one1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqquzw7vz",
        "mixHash":
        "0x0000000000000000000000000000000000000000000000000000000000000000",
        "nonce": 0,
        "number": "0x1",
        "parentHash":
        "0x61610810993c42bacd55a124e3b9009b9ae225a2f727750db4d2171504be59fb",
        "receiptsRoot":
        "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
        "size": "0x31e",
        "stakingTransactions": [],
        "stateRoot":
        "0x9e470e803db498e6ba3c9108d3f951060e7121289c2354b8b185349ddef4fc0a",
        "timestamp": "0x5f09ad95",
        "transactions": [],
        "transactionsRoot":
        "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
        "uncles": [],
        "viewID": "0x1"
    }

    raw_response = base_request("hmy_getBlockByNumber",
                                params=["0x0", True],
                                endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
def test_get_sharding_structure():
    """
    Note that v1 & v2 have the same responses.
    """
    reference_response = {
        "current": True,
        "http": "http://127.0.0.1:9500",
        "shardID": 0,
        "ws": "ws://127.0.0.1:9800"
    }

    # Check v1
    raw_response = base_request("hmy_getShardingStructure",
                                endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert isinstance(
        response,
        list), f"Expected response to be of type list, not {type(response)}"
    for d in response:
        assert isinstance(
            d, dict), f"Expected type dict in response elements, not {type(d)}"
        assert_valid_json_structure(reference_response, d)
    assert response[0]["current"]

    # Check v2
    raw_response = base_request("hmyv2_getShardingStructure",
                                endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert isinstance(
        response,
        list), f"Expected response to be of type list, not {type(response)}"
    for d in response:
        assert isinstance(
            d, dict), f"Expected type dict in response elements, not {type(d)}"
        assert_valid_json_structure(reference_response, d)
    assert response[0]["current"]
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']})"
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}]"
def test_get_node_metadata():
    """
    Note that v1 & v2 have the same responses.
    """
    reference_response = {
        "blskey": [
            "65f55eb3052f9e9f632b2923be594ba77c55543f5c58ee1454b9cfd658d25e06373b0f7d42a19c84768139ea294f6204"
        ],
        "version":
        "Harmony (C) 2020. harmony, version v6110-v2.1.9-34-g24ec31c1 (danielvdm@ 2020-07-11T05:03:50-0700)",
        "network":
        "localnet",
        "chain-config": {
            "chain-id": 2,
            "cross-tx-epoch": 0,
            "cross-link-epoch": 2,
            "staking-epoch": 2,
            "prestaking-epoch": 0,
            "quick-unlock-epoch": 0,
            "eip155-epoch": 0,
            "s3-epoch": 0,
            "receipt-log-epoch": 0
        },
        "is-leader":
        True,
        "shard-id":
        0,
        "current-epoch":
        0,
        "blocks-per-epoch":
        5,
        "role":
        "Validator",
        "dns-zone":
        "",
        "is-archival":
        False,
        "node-unix-start-time":
        1594469045,
        "p2p-connectivity": {
            "total-known-peers": 24,
            "connected": 23,
            "not-connected": 1
        }
    }

    # Check v1
    raw_response = base_request("hmy_getNodeMetadata", endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["shard-id"] == 0
    assert response["network"] == "localnet"
    assert response["chain-config"]["chain-id"] == 2

    # Check v2
    raw_response = base_request("hmyv2_getNodeMetadata", endpoint=endpoints[0])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["shard-id"] == 0
    assert response["network"] == "localnet"
    assert response["chain-config"]["chain-id"] == 2
def test_get_latest_chain_headers():
    """
    Note that v1 & v2 have the same responses.
    """
    reference_response = {
        "beacon-chain-header": {
            "epoch": 18,
            "extraData": "0x",
            "gasLimit": "0x4c4b400",
            "gasUsed": "0x0",
            "hash":
            "0xdb6099006bb637578a94fa3003b2b68947ae8fcdc7e9f89ea0f83edd5ad65c9e",
            "logsBloom":
            "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "difficulty": "0",
            "miner": "0x6911b75b2560be9a8f71164a33086be4511fc99a",
            "mixHash":
            "0x0000000000000000000000000000000000000000000000000000000000000000",
            "number": "0xab",
            "sha3Uncles":
            '0x0000000000000000000000000000000000000000000000000000000000000000',
            "nonce": '0x0000000000000000',
            "parentHash":
            "0x9afbaa3db3c2f5393b7b765aa48091c7a6cc3c3fdf19fb88f8ee2c88e257988d",
            "receiptsRoot":
            "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "shardID": 0,
            "stateRoot":
            "0x4d0b5b168bd3214e32f95718ef591e04c54f060f89e4304c8d4ff2745ebad3a9",
            "timestamp": "0x60751990",
            "transactionsRoot":
            "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "viewID": 171
        },
        "shard-chain-header": {
            "epoch": 17,
            "extraData": "0x",
            "gasLimit": "0x4c4b400",
            "gasUsed": "0x0",
            "hash":
            "0xdf4c2be8e676f728a419415bdd393a5c174e0b1431e016f870d0777d86668708",
            "logsBloom":
            "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "difficulty": "0",
            "miner": "0xd06193871db8d5bc92dead4780e3624038174e88",
            "mixHash":
            "0x0000000000000000000000000000000000000000000000000000000000000000",
            "number": "0xa7",
            "sha3Uncles":
            '0x0000000000000000000000000000000000000000000000000000000000000000',
            "nonce": '0x0000000000000000',
            "parentHash":
            "0x336990a12d8697c5f9247790261aa1bdea33aed37031d09664680b86779f08a6",
            "receiptsRoot":
            "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "shardID": 1,
            "stateRoot":
            "0xddd8a842df3ffd77555d64ab782abf6effe95bc2eab48610ac05a5445b55df92",
            "timestamp": "0x60751991",
            "transactionsRoot":
            "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "viewID": 167
        }
    }

    # Check v1
    raw_response = base_request("hmy_getLatestChainHeaders",
                                endpoint=endpoints[1])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["beacon-chain-header"]["shardID"] == 0
    assert response["shard-chain-header"]["shardID"] == 1

    # Check v2
    raw_response = base_request("hmyv2_getLatestChainHeaders",
                                endpoint=endpoints[1])
    response = check_and_unpack_rpc_response(raw_response, expect_error=False)
    assert_valid_json_structure(reference_response, response)
    assert response["beacon-chain-header"]["shardID"] == 0
    assert response["shard-chain-header"]["shardID"] == 1
Beispiel #10
0
def test_pending_transactions_v1():
    tx = {
        "from": "one1twhzfc2wr4j5ka7gs9pmllpnrdyaskcl5lq8ye",
        "to": "one13awvzpjt7n3hcrmxax3elps7a6vw46u63kc28p",
        # month liar edit pull vague intact entire slab satoshi angle core unlock useless wrestle kite merry sure quiz day frame update recycle fault lecture
        "amount": "1000",
        "from-shard": 0,
        "to-shard": 0,
        "hash": "0xef8091e621745bd17133664c96842ef9d730a842f69bce6402b49490af0a17ef",
        "nonce": "0x0",
        "signed-raw-tx": "0xf86e80843b9aca008252088080948f5cc1064bf4e37c0f66e9a39f861eee98eaeb9a893635c9adc5dea000008028a0e876d901525a8799a8eb3ea03e2c1a43129c2ff3136ec10f6345f2899bab5026a05c4f1e659b9d371c2e9994aee240b966e36b6dd609747d42c9d9c9f23371d808",
    }
    reference_response = [
        {
            "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "blockNumber": None,
            "from": "one1twhzfc2wr4j5ka7gs9pmllpnrdyaskcl5lq8ye",
            "timestamp": "0x0",
            "gas": "0x5208",
            "gasPrice": "0x3b9aca00",
            "hash": "0xef8091e621745bd17133664c96842ef9d730a842f69bce6402b49490af0a17ef",
            "input": "0x",
            "nonce": "0x0",
            "to": "one13awvzpjt7n3hcrmxax3elps7a6vw46u63kc28p",
            "transactionIndex": "0x0",
            "value": "0x3635c9adc5dea00000",
            "shardID": 0,
            "toShardID": 0,
            "v": "0x28",
            "r": "0xe876d901525a8799a8eb3ea03e2c1a43129c2ff3136ec10f6345f2899bab5026",
            "s": "0x5c4f1e659b9d371c2e9994aee240b966e36b6dd609747d42c9d9c9f23371d808"
        }
    ]

    in_initially_funded = False
    for init_tx in initial_funding:
        if init_tx["to"] == tx["from"] and init_tx["to-shard"] == tx["from-shard"]:
            in_initially_funded = True
            break
    if not in_initially_funded:
        raise AssertionError(f"Test transaction from address {tx['from']} "
                             f"not found in set of initially funded accounts.")

    if get_transaction(tx["hash"], tx["from-shard"]) is not None:
        pytest.skip(f"Test transaction (hash {tx['hash']}) already present on chain...")

    send_transaction(tx, confirm_submission=True)

    start_time = time.time()
    while time.time() - start_time <= tx_timeout:
        raw_response = base_request("hmy_pendingTransactions", endpoint=endpoints[tx["from-shard"]])
        response = check_and_unpack_rpc_response(raw_response, expect_error=False)
        assert_valid_json_structure(reference_response, response)
        for pending_tx in response:
            if pending_tx["hash"] == tx["hash"]:
                assert pending_tx["shardID"] == tx["from-shard"], f"Pending tx has from shard {pending_tx['shardID']}, " \
                                                                  f"expected shard {tx['from-shard']}"
                assert pending_tx["toShardID"] == tx["to-shard"], f"Pending tx has to shard {pending_tx['toShardID']}, " \
                                                                  f"expected shard {tx['to-shard']}"
                return

    raise AssertionError(f"Timeout! Pending transaction not found for {json.dumps(tx, indent=2)}")
Beispiel #11
0
def test_get_pending_cx_receipts():
    """
    Note that v1 & v2 have the same responses.
    """
    cx = {
        "from": "one19l4hghvh40fyldxfznn0a3ss7d5gk0dmytdql4",
        "to": "one1ds3fayprfl6j7yd6mpwfncj9c0ajmhvmvhnmpm",
        # erupt concert hat tree anger discover disease town gasp lemon gesture fiber spread season mixture host awake tennis issue orbit member film winter glass
        "amount": "1000",
        "from-shard": 0,
        "to-shard": 1,
        "hash": "0x0988bcaecba9cc731245ee7ae9595d1202448413bc6e517b4c0c8da9abb1e479",
        "nonce": "0x0",
        "signed-raw-tx": "0xf86e80843b9aca008252088001946c229e90234ff52f11bad85c99e245c3fb2ddd9b893635c9adc5dea000008027a0fc7e0c3790b7c507749f4286e5b6cc59357129586fc48a326442c27886e0236ba0587c72684d05fad0c1c2111d55d810bc086cd5adf129806a89a019b539b19d26",
    }
    reference_response = [
        {
            "receipts": [
                {
                    "txHash": "0x819b0d7902134dadd07851edba0e8694e60c1aee057a96d2ceb4a9118cee0298",
                    "from": "one1t40su52axu207vgc6ymcmwe0xmml4njrskk2vf",
                    "to": "one1qljfd3pnfjwr86ll6d0s6khcqhw8969p9l7fw3",
                    "shardID": 1,
                    "toShardID": 0,
                    "amount": 500000000000000000000
                }
            ],
            "merkleProof": {
                "blockNum": 35,
                "blockHash": "0xe07abb23824f658f452012f22e2d557a270c320058a39d6c6d5d2d53d1d7e427",
                "shardID": 1,
                "receiptHash": "0xb7f422b693a5cffd3d98b2fd4f9f833e10421bcd6d488e5cd8c2fcbcf1ecd13c",
                "shardIDs": [
                    0
                ],
                "shardHashes": [
                    "0x31db710789deaa5a1721f7bf66d3eabddfbb9e712b5ba6cdc7b183f5d9dc9b51"
                ]
            },
            "header": {
                "shard-id": 1,
                "block-header-hash": "0x2e0295f760bc69cdf840576636f61602f8b13ea5172562837c10a9b6f5fa711e",
                "block-number": 35,
                "view-id": 35,
                "epoch": 5
            },
            "commitSig": "G7oQCfiRJjl8s1i7B2xxPWZefCW5muiqyNY0PwcNOFt2QQkRC95ongKIGuIKCLMAVkDpkZRdC7B0cUoe3tKceT6/9++sxcwPRQ2NBWA/u6Gkl6UneKs4Xzhpuez2MoOG",
            "commitBitmap": "Pw=="
        }
    ]

    if get_transaction(cx["hash"], cx["from-shard"]) is not None:
        pytest.skip(f"Test cross shard transaction (hash {cx['hash']}) already present on chain...")

    send_transaction(cx, confirm_submission=True)

    start_time = time.time()
    v1_success, v2_success = False, False
    while time.time() - start_time <= tx_timeout * 2:  # Cross shards are generally slower...
        if not v1_success:
            raw_response = base_request("hmy_getPendingCXReceipts", endpoint=endpoints[cx["to-shard"]])
            response = check_and_unpack_rpc_response(raw_response, expect_error=False)
            assert_valid_json_structure(reference_response, response)
            for cx_receipt in response:
                for r in cx_receipt["receipts"]:
                    if r["txHash"] == cx["hash"]:
                        v1_success = True

        if not v2_success:
            raw_response = base_request("hmyv2_getPendingCXReceipts", endpoint=endpoints[cx["to-shard"]])
            response = check_and_unpack_rpc_response(raw_response, expect_error=False)
            assert_valid_json_structure(reference_response, response)
            for cx_receipt in response:
                for r in cx_receipt["receipts"]:
                    if r["txHash"] == cx["hash"]:
                        v2_success = True

        time.sleep(0.5)
        if v1_success and v2_success:
            return

    raise AssertionError(f"Timeout! Pending transaction not found for {json.dumps(cx)}")