def test_gossip_proxy(intercepted_two_node_network):
    nodes = intercepted_two_node_network.docker_nodes
    node = nodes[0]

    tls_certificate_path = node.config.tls_certificate_local_path()
    tls_parameters = {
        "--certificate-file": tls_certificate_path,
        "--node-id": extract_common_name(tls_certificate_path),
    }
    cli = CLI(nodes[0], tls_parameters=tls_parameters)
    account = cli.node.genesis_account
    cli.set_default_deploy_args(
        "--from",
        account.public_key_hex,
        "--private-key",
        cli.private_key_path(account),
        "--public-key",
        cli.public_key_path(account),
        "--payment",
        cli.resource(Contract.STANDARD_PAYMENT),
        "--payment-args",
        cli.payment_json,
    )
    cli("deploy", "--session", cli.resource(Contract.HELLO_NAME_DEFINE))
    block_hash = cli("propose")
    wait_for_block_hash_propagated_to_all_nodes(nodes, block_hash)
def test_invalid_bigint(one_node_network):
    # Test covering fix for NODE-1182
    # Use a malformed BigInt contract argument
    node = one_node_network.docker_nodes[0]
    cli = CLI(node, "casperlabs_client")
    session_wasm = cli.resource(Contract.ARGS_U512)

    # Send in u512 with invalid string format, surrounded []
    args = '[{"name": "arg_u512", "value": {"big_int": {"value": "[1000]", "bit_width": 512}}}]'
    # fmt: off
    deploy_hash = cli("deploy", "--private-key",
                      cli.private_key_path(GENESIS_ACCOUNT),
                      "--payment-amount", 10000000, "--session", session_wasm,
                      "--session-args", cli.format_json_str(args))
    # fmt: on

    node.p_client.wait_for_deploy_processed(deploy_hash,
                                            on_error_raise=False,
                                            delay=1,
                                            timeout_seconds=30)

    status = node.d_client.show_deploy(deploy_hash).status
    assert status.state == "DISCARDED"
    assert status.message == "Error parsing deploy arguments: InvalidBigIntValue([1000])"

    # Send in u512 valid as 1000.
    args = '[{"name": "arg_u512", "value": {"big_int": {"value": "1000", "bit_width": 512}}}]'
    # fmt: off
    deploy_hash = cli("deploy", "--private-key",
                      cli.private_key_path(GENESIS_ACCOUNT),
                      "--payment-amount", 10000000, "--session", session_wasm,
                      "--session-args", cli.format_json_str(args))
    # fmt: on

    node.wait_for_deploy_processed_and_get_block_hash(deploy_hash,
                                                      on_error_raise=False)

    result = node.d_client.show_deploy(deploy_hash)

    # User(code) in revert adds 65536 to the 1000
    assert result.status.state == "PROCESSED"
    assert result.processing_results.error_message == f"Exit code: {1000 + 65536}"
def check_upgrades_applied(network):
    node = network.docker_nodes[0]

    cmd = "ls -la /etc/casperlabs /root/.casperlabs/chainspec /root/.casperlabs/chainspec/genesis"
    rc, output = node.exec_run(cmd)
    logging.info(f"============================ {cmd} => {rc}")
    logging.info(f"============================ [")
    logging.info(f"============================ {output}")
    logging.info(f"============================ ]")

    cli = CLI(network.docker_nodes[0], "casperlabs_client")
    account = cli.node.test_account

    cli.set_default_deploy_args(
        "--from", account.public_key_hex,
        "--private-key", cli.private_key_path(account),
        "--public-key", cli.public_key_path(account)
    )

    # First deploy
    deploy_hash = cli("deploy", "--payment-amount", 10000000, "--session", cli.resource(Contract.COUNTER_DEFINE))
    get_cost_and_block_hash(node, deploy_hash)

    # When activation-point-rank of an upgrade is reached, and upgrade is executed,
    # the cost of execution should change.

    # We have spec of genesis, upgrade-1 and upgrade-2 in our custom chainspec
    # (in integration-testing/resources/test-chainspec)
    # Upgrades change cost of executing opcodes, so cost of execution of the same contract should change
    # after the upgrades are applied.
    costs = []
    versions = []

    # Currently test-chainspec activation points configured like below:

    # upgrade-1/manifest.toml:activation-point-rank = 20
    # upgrade-2/manifest.toml:activation-point-rank = 30

    # So, a number of deploys above 30 should be enough to activate both upgrades.
    offset = 2  # First deploy after genesis
    upgrade_1 = 20
    upgrade_2 = 30

    for i in range(1, 35):
        position = i + offset
        if position == upgrade_1 or position == upgrade_2:
            logging.info(f'Redeploying contract at position {position}')
            deploy_hash = cli("deploy", "--payment-amount", 10000000, "--session", cli.resource(Contract.COUNTER_DEFINE))
            get_cost_and_block_hash(node, deploy_hash)
            # Add up, as another deploy shifts the block position
            offset += 1

        deploy_hash = cli("deploy", "--payment-amount", 10000000, "--session", cli.resource(Contract.COUNTER_CALL))
        cost, block_hash = get_cost_and_block_hash(node, deploy_hash)
        if cost not in costs:
            logging.info(f"Execution cost at iteration {i}, is {cost}. ")
            costs.append(cost)
            version = cli("show-block", block_hash).summary.header.protocol_version
            versions.append(version)

    logging.info(f"Costs of execution: {' '.join(str(c) for c in costs)}")
    logging.info(f"Versions: {' '.join(str(v) for v in versions)}")
    return costs