def test_cli_show_block_not_found(cli): block_hash = "00" * 32 with raises(CLIErrorExit) as ex_info: parse(cli("show-block", block_hash)) # StatusCode.NOT_FOUND: Cannot find block matching hash 0000000000000000000000000000000000000000000000000000000000000000 assert "NOT_FOUND" in str(ex_info.value) assert "Cannot find block matching hash" in str(ex_info.value)
def test_cli_deploy_propose_show_deploys_show_deploy_query_state_and_balance( cli, one_node_network ): resources_path = testing_root_path() / "resources" account = GENESIS_ACCOUNT deploy_response = cli( "deploy", "--from", account.public_key_hex, "--nonce", "1", "--payment", str(resources_path / "test_helloname.wasm"), "--session", str(resources_path / "test_helloname.wasm"), "--private-key", str(account.private_key_path), "--public-key", str(account.public_key_path), ) # 'Success! Deploy hash: xxxxxxxxx...' deploy_hash = deploy_response.split()[3] # 'Success! Block hash: xxxxxxxxx...' propose_response = cli("propose") block_hash = propose_response.split()[3] deploys = parse_show_deploys(cli("show-deploys", block_hash)) deploy_hashes = [d.deploy.deploy_hash for d in deploys] assert deploy_hash in deploy_hashes deploy_info = parse(cli("show-deploy", deploy_hash)) assert deploy_info.deploy.deploy_hash == deploy_hash result = parse( cli( "query-state", "--block-hash", block_hash, "--type", "address", "--key", account.public_key_hex, "--path", "", ) ) assert "hello_name" in [u.name for u in result.account.known_urefs] balance = int( cli("balance", "--address", account.public_key_hex, "--block-hash", block_hash) ) # assert balance == 1000000 # regular test account assert balance == 1000000000 # genesis
def parse_output(self, command, binary_output): if command in ("make-deploy", "sign-deploy"): return binary_output output = binary_output.decode("utf-8") if command in ("deploy", "send-deploy"): return output.split()[2] # "Success! Deploy 0d4036bebb95de793b28de452d594531a29f8dc3c5394526094d30723fa5ff65 deployed." if command in ("propose", ): # "Response: Success! Block 47338c65992e7d5062aec2200ad8d7284ae49f6c3e7c37fa7eb46fb6fc8ae3d8 created and added." return output.split()[3] if command == "show-blocks": return parse_show_blocks(output) if command == "show-deploys": return parse_show_deploys(output) if command in ("show-deploy", "show-block", "query-state"): return parse(output) return output
def test_client_parser_list_of_values_of_primitive_types(): r = parse(""" values: 0 values: 1 """) assert r.values == [0, 1]
def test_cli_show_blocks_and_show_block(cli): blocks = parse_show_blocks(cli("show-blocks", "--depth", "1")) assert len(blocks) > 0 for block in blocks: block_hash = block.summary.block_hash assert len(block_hash) == 32 * 2 # hex b = parse(cli("show-block", block_hash)) assert block_hash == b.summary.block_hash
def query_state(self, block_hash: str, key: str, path: str, key_type: str): """ Subcommand: query-state - Query a value in the global state. -b, --block-hash <arg> Hash of the block to query the state of -k, --key <arg> Base16 encoding of the base key. -p, --path <arg> Path to the value to query. Must be of the form 'key1/key2/.../keyn' -t, --type <arg> Type of base key. Must be one of 'hash', 'uref', 'address' -h, --help Show help message """ return parse( self.invoke_client(f'query-state ' f' --block-hash "{block_hash}"' f' --key "{key}"' f' --path "{path}"' f' --type "{key_type}"'))
def show_deploy(self, hash: str): return parse(self.invoke_client(f'show-deploy {hash}'))
def test_client_parser_deploy(): r = parse(DEPLOY) assert len(r.processing_results.block_info.summary.header.justifications) == 10