def test_two_network_repeated_deploy(two_node_network): """ Test that a repeated deploy is rejected on a different node """ nodes = two_node_network.docker_nodes clis = [CLI(node) for node in nodes] accounts = (Account("genesis"), Account(1)) # Generate and save signed_deploy with signed_deploy_file_path(clis[0], accounts[0]) as signed_deploy_path: # First deployment of signed_deploy from node-0 should succeed deploy_hash = clis[0]("send-deploy", "-i", signed_deploy_path) block_hash = nodes[0].wait_for_deploy_processed_and_get_block_hash(deploy_hash) deploy_info = clis[0]("show-deploy", deploy_hash) assert not deploy_info.processing_results[0].is_error wait_for_block_hash_propagated_to_all_nodes(nodes, block_hash) # Second deployment of signed_deploy to node-1 should fail. deploy_hash = clis[1]("send-deploy", "-i", signed_deploy_path) deploy_info = clis[1]("show-deploy", deploy_hash) assert not deploy_info.processing_results[0].is_error result = nodes[1].p_client.client.wait_for_deploy_processed(deploy_hash) assert "DISCARDED" in str(result) assert "Duplicate or expired" in str(result)
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_one_network_repeated_deploy(one_node_network_fn): """ Test that a repeated deploy is rejected on same node. """ node = one_node_network_fn.docker_nodes[0] cli = CLI(node) account = Account("genesis") # Generate and save signed_deploy with signed_deploy_file_path(cli, account) as signed_deploy_path: # First deployment of signed_deploy, should succeed deploy_hash = cli("send-deploy", "-i", signed_deploy_path) deploy_info = cli.node.p_client.client.wait_for_deploy_processed(deploy_hash) blocks_with_deploy = [ bi.block_info.summary.block_hash.hex() for bi in deploy_info.processing_results ] blocks_with_deploy_after_replay = [ bi.block_info.summary.block_hash.hex() for bi in deploy_info.processing_results ] assert not deploy_info.processing_results[0].is_error # Second deployment of signed_deploy should fail deploy_hash = cli("send-deploy", "-i", signed_deploy_path) deploy_info = cli.node.p_client.client.wait_for_deploy_processed(deploy_hash) assert not deploy_info.processing_results[0].is_error blocks_with_deploy_after_replay = [ bi.block_info.summary.block_hash.hex() for bi in deploy_info.processing_results ] assert blocks_with_deploy_after_replay == blocks_with_deploy
def unbond_from_network(network: OneNodeNetwork, bonding_amount: int, account_number: int): node = network.docker_nodes[1] account = Account(account_number) cli = CLI(node) # fmt: off cli("unbond", "--amount", bonding_amount, '--public-key', account.public_key_path, "--private-key", account.private_key_path, "--payment-amount", EXECUTION_PAYMENT_AMOUNT, "--from", account.public_key_hex) # fmt: on block_hash = cli("propose") return block_hash, account
def bond_to_the_network(network: OneNodeNetwork, bond_amount: int, account_number: int): # Using account that will not exist in bonds.txt from high number account = Account(account_number) node0, node1 = network.docker_nodes cli = CLI(node0) # fmt: off cli("bond", "--amount", bond_amount, '--public-key', account.public_key_path, '--private-key', account.private_key_path, '--payment-amount', EXECUTION_PAYMENT_AMOUNT, '--from', account.public_key_hex) # fmt: on block_hash = cli("propose") return block_hash, account
def test_grpc_encryption_python_cli(encrypted_two_node_network): nodes = encrypted_two_node_network.docker_nodes tls_parameters = { "--certificate-file": nodes[0].config.tls_certificate_local_path(), "--node-id": extract_common_name(nodes[0].config.tls_certificate_local_path()), } cli = CLI(nodes[0], tls_parameters=tls_parameters) logging.info( f"""EXECUTING {' '.join(cli.expand_args(["show-blocks", "--depth", 1]))}""" ) blocks = cli("show-blocks", "--depth", 1) assert len(blocks) > 0 logging.debug(f"{blocks}")
def add_funded_account_to_network(network: OneNodeNetwork, account_number: int): node0 = network.docker_nodes[0] cli = CLI(node0) prev_number = len(network.docker_nodes) account = network.add_new_node_to_network(account=Account(account_number)) assert (len(network.docker_nodes) == prev_number + 1), f"Total number of nodes should be {prev_number + 1}." response = node0.d_client.transfer( amount=1000000000, private_key=GENESIS_ACCOUNT.private_key_docker_path, target_account=account.public_key, ) assert "Success!" in response block_hash = cli("propose") for deployInfo in node0.p_client.showDeploys(block_hash): assert (deployInfo.is_error is False), f"Transfer Failed: {deployInfo.error_message}"
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 test_grpc_encryption_python_cli_and_proxy(encrypted_two_node_network): node = encrypted_two_node_network.docker_nodes[0] tls_certificate_path = node.config.tls_certificate_local_path() tls_key_path = local_path(node.config.tls_key_path()) tls_parameters = { "--certificate-file": tls_certificate_path, "--node-id": extract_common_name(tls_certificate_path), } cli = CLI(node, tls_parameters=tls_parameters) cli.port = 50401 # We will be talking to proxy on 50401, node is on 40401 proxy_client = grpc_proxy.proxy_client( node, node_port=40401, node_host=cli.host, proxy_port=50401, client_certificate_file=tls_certificate_path, client_key_file=tls_key_path, server_certificate_file=tls_certificate_path, server_key_file=tls_key_path, ) cli.host = "localhost" logging.info( f"""EXECUTING {' '.join(cli.expand_args(["show-blocks", "--depth", 1]))}""" ) block_infos = cli("show-blocks", "--depth", 1) logging.info(f"{block_infos[0]}") assert len(block_infos) > 0 block_info = cli("show-block", block_infos[0].summary.block_hash) logging.info(f"{block_info}") proxy_client.stop() with raises(CLIErrorExit) as excinfo: block_info = cli("show-block", block_infos[0].summary.block_hash) # Expected grpc error: UNAVAILABLE assert '"grpc_status":14' in str(excinfo.value)
def test_cli_abi_unsigned_python(node, unsigned_type, test_contract, value): check_cli_abi_unsigned(CLI(node), unsigned_type, value, test_contract)
def cli(one_node_network): return CLI(one_node_network.docker_nodes[0], "casperlabs_client")
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