def test_deploy_with_args(one_node_network, genesis_public_signing_key): """ Deploys test contracts that do: revert(get_arg(0)); // for u32 and u512 and revert(sum(address_bytes[u8; 32]) + u32); for multiple argument test. Tests args get correctly encoded and decoded in the contract. Test expects the test contracts args_u32.wasm and args_u512.wasm to deserialize correctly their arguments and then call revert with value of the argument (converted to a Rust native int, as expected by revert). If the test contracts don't fail or if their exit code is different than expected, the test will fail. """ node = one_node_network.docker_nodes[0] client = node.p_client.client for wasm, encode in [ (resources_path() / Contract.ARGS_U32, ABI.int_value), (resources_path() / Contract.ARGS_U512, ABI.big_int), ]: for number in [1, 12, 256, 1024]: block_hash = node.deploy_and_get_block_hash( GENESIS_ACCOUNT, wasm, on_error_raise=False, session_args=ABI.args([encode("number", number)]), ) for deploy_info in client.showDeploys(block_hash): exit_code = number + USER_ERROR_MIN assert deploy_info.is_error is True assert deploy_info.error_message == f"Exit code: {exit_code}" wasm = resources_path() / Contract.ARGS_MULTI account_hex = "0101010102020202030303030404040405050505060606060707070708080808" number = 1000 total_sum = sum([1, 2, 3, 4, 5, 6, 7, 8]) * 4 + number block_hash = node.deploy_and_get_block_hash( GENESIS_ACCOUNT, wasm, on_error_raise=False, session_args=ABI.args( [ABI.account("account", account_hex), ABI.u32("number", number)]), ) for deploy_info in client.showDeploys(block_hash): exit_code = total_sum + USER_ERROR_MIN assert deploy_info.is_error is True assert deploy_info.error_message == f"Exit code: {exit_code}" for blockInfo in client.showBlocks(10): assert blockInfo.status.stats.block_size_bytes > 0
def __init__(self, node, cli_cmd="casperlabs_client", tls_parameters=None): self.node = node self.host = (os.environ.get("TAG_NAME", None) and node.container_name or "localhost") self.port = node.grpc_external_docker_port self.port_internal = node.grpc_internal_docker_port self.cli_cmd = cli_cmd self.tls_parameters = tls_parameters or {} self.default_deploy_args = [] self.resources_directory = resources_path()
def resource(file_name): return resources_path() / file_name
def account_path(self) -> Path: return resources_path() / "accounts"
def test_deploy_with_args(one_node_network, genesis_public_signing_key): """ Deploys test contracts that do: revert(get_arg(0)); // for u32 and u512 and revert(sum(address_bytes[u8; 32]) + u32); for multiple argument test. Tests args get correctly encoded and decoded in the contract. Test expects the test contracts args_u32.wasm and args_u512.wasm to deserialize correctly their arguments and then call revert with value of the argument (converted to a Rust native int, as expected by revert). If the test contracts don't fail or if their exit code is different than expected, the test will fail. """ node = one_node_network.docker_nodes[0] client = node.p_client.client for wasm, encode in [ (resources_path() / Contract.ARGS_U32, ABI.int_value), (resources_path() / Contract.ARGS_U512, ABI.big_int), ]: for number in [1, 12, 256, 1024]: response, deploy_hash = client.deploy( session=wasm, session_args=ABI.args([encode("number", number)]), payment=resources_path() / Contract.STANDARD_PAYMENT, payment_args=MAX_PAYMENT_ABI, public_key=GENESIS_ACCOUNT.public_key_path, private_key=GENESIS_ACCOUNT.private_key_path, ) logging.info( f"DEPLOY RESPONSE: {response} deploy_hash: {deploy_hash.hex()}" ) response = client.propose() # Need to convert to hex string from bytes block_hash = response.block_hash.hex() for deploy_info in client.showDeploys(block_hash): exit_code = number + USER_ERROR_MIN assert deploy_info.is_error is True assert deploy_info.error_message == f"Exit code: {exit_code}" wasm = resources_path() / Contract.ARGS_MULTI account_hex = "0101010102020202030303030404040405050505060606060707070708080808" number = 1000 total_sum = sum([1, 2, 3, 4, 5, 6, 7, 8]) * 4 + number response, deploy_hash = client.deploy( session=wasm, session_args=ABI.args( [ABI.account("account", account_hex), ABI.u32("number", number)]), payment=resources_path() / Contract.STANDARD_PAYMENT, payment_args=MAX_PAYMENT_ABI, public_key=GENESIS_ACCOUNT.public_key_path, private_key=GENESIS_ACCOUNT.private_key_path, ) logging.info( f"DEPLOY RESPONSE: {response} deploy_hash: {deploy_hash.hex()}") response = client.propose() block_hash = response.block_hash.hex() for deploy_info in client.showDeploys(block_hash): exit_code = total_sum + USER_ERROR_MIN assert deploy_info.is_error is True assert deploy_info.error_message == f"Exit code: {exit_code}" for blockInfo in client.showBlocks(10): assert blockInfo.status.stats.block_size_bytes > 0