def verify_account_balance_on_transfer( ctx: ExecutionContext, node_id: NodeIdentifier, state_root_hash: str, account_index: int, expected: int, ) -> Account: """Verifies that an account balance is as per expectation. """ # Set account. account = cache.state.get_account_by_index(ctx, account_index) # Set network / node in readiness for chain interaction. network, node = get_network_node(node_id) # Set account main purse uref. purse_uref = chain.get_account_main_purse_uref(network, node, account.account_key, state_root_hash) assert purse_uref is not None, \ f"account {account_index} main purse uref could not be retrieved - probably on-chain account does not exist" # Set account balance. balance = chain.get_account_balance(network, node, purse_uref, state_root_hash) assert balance == expected, \ f"account balance mismatch: account_index={account_index}, account_key={account.account_key}, expected={expected}, actual={balance}" return account
def get_account_balance(network: Network, node: Node, account: Account) -> int: """Returns either a faucet account or a user account. """ purse_uref = chain.get_account_main_purse_uref(network, node, account.account_key) return chain.get_account_balance(network, node, purse_uref)
def main(args): """Entry point. :param args: Parsed CLI arguments. """ network, node = get_network_node(args) purse_uref = chain.get_account_main_purse_uref(network, node, network.faucet.account_key) balance = chain.get_account_balance(network, node, purse_uref) utils.log(f"FAUCET ACCOUNT BALANCE = {balance or 'N/A'}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ if args.node: network, node = get_network_node(args) nodeset = [node] else: network, nodeset = get_network_nodeset(args) for node in nodeset: purse_uref = chain.get_account_main_purse_uref(network, node, node.account.account_key) balance = chain.get_account_balance(network, node, purse_uref) utils.log(f"VALIDATOR ACCOUNT BALANCE @ NODE #{node.index} ({node.address}) = {balance or 'N/A'}")
def verify_account_balance(ctx: ExecutionContext, account_index: int, expected: int) -> Account: """Verifies that an account balance is as per expectation. """ account = cache.state.get_account_by_index(ctx, account_index) network, node = get_network_node(ctx) state_root_hash = chain.get_state_root_hash(network, node) purse_uref = chain.get_account_main_purse_uref(network, node, account.account_key, state_root_hash) assert purse_uref is not None, \ f"account {account_index} main purse uref could not be retrieved - probably on-chain account does not exist" balance = chain.get_account_balance(network, node, purse_uref, state_root_hash) assert balance == expected, \ f"account balance mismatch: account_index={account_index}, account_key={account.account_key}, expected={expected}, actual={balance}"