Exemple #1
0
def pytest_sessionstart(session):
    """
    Start the test session by sending initial test funds.
    Will block until transactions are confirmed on-chain.
    """
    assert util.is_active_shard(endpoints[0], delay_tolerance=20), "Shard 0 is not making progress..."
    assert util.is_active_shard(endpoints[1], delay_tolerance=20), "Shard 1 is not making progress..."

    # Send all txs. Note that this is the only place to break the txs invariant.
    for tx in initial_funding:
        response = base_request('hmy_sendRawTransaction', params=[tx["signed-raw-tx"]],
                                endpoint=endpoints[tx["from-shard"]])
        assert is_valid_json_rpc(response), f"Invalid JSON response: {response}"
        # Do not check for errors since resending initial txs is fine & failed txs will be caught in confirm timeout.

    # Confirm all txs within 2x timeout window (since all initial txs could be in 2 blocks).
    start_time = time.time()
    while time.time() - start_time <= 2 * tx_timeout:
        sent_txs = []
        for tx in initial_funding:
            tx_response = get_transaction(tx["hash"], tx["from-shard"])
            if (tx_response is not None):
                sent_txs.append(tx_response['blockNumber'] is not None)
            else:
                sent_txs.append(tx_response is not None)
        if all(sent_txs):
            return
    raise AssertionError("Could not confirm initial transactions on-chain.")
Exemple #2
0
def send_staking_transaction(tx_data, confirm_submission=False):
    """
    Send the given staking transaction (`tx_data`), and check that it got submitted
    to tx pool if `confirm_submission` is enabled.

    Node that tx_data follow the format of one of the entries in `initial_funding`
    """
    assert isinstance(
        tx_data, dict
    ), f"Sanity check: expected tx_data to be of type dict not {type(tx_data)}"
    for el in ["signed-raw-tx", "hash"]:
        assert el in tx_data.keys(
        ), f"Expected {el} as a key in {json.dumps(tx_data, indent=2)}"

    # Send tx
    response = base_request('hmy_sendRawStakingTransaction',
                            params=[tx_data["signed-raw-tx"]],
                            endpoint=endpoints[0])
    if confirm_submission:
        tx_hash = check_and_unpack_rpc_response(response, expect_error=False)
        assert tx_hash == tx_data["hash"], f"Expected submitted staking transaction to get tx hash " \
                                           f"of {tx_data['hash']}, got {tx_hash}"
    else:
        assert is_valid_json_rpc(
            response), f"Invalid JSON response: {response}"
Exemple #3
0
def test_call_v1(deployed_contract):
    """
    TODO: Real smart contract call, currently, it is an error case test.
    """
    address = _get_contract_address(deployed_contract["hash"], deployed_contract["from-shard"])
    raw_response = base_request("hmy_call", params=[{"to": address}, "latest"],
                                endpoint=endpoints[deployed_contract["from-shard"]])
    assert is_valid_json_rpc(raw_response), f"Invalid JSON response: {raw_response}"
    try:
        response = check_and_unpack_rpc_response(raw_response, expect_error=False)
        assert isinstance(response, str) and response.startswith("0x")  # Must be a hex string
    except Exception as e:
        pytest.skip("RPC format being reworked, fix when finished")