def remove_associated_key(node, identity_key: str, weight_key, key: str): args_json = json.dumps([{"account": key}]) args = ABI.args_from_json(args_json) return node.deploy_and_propose( from_address=identity_key, payment_contract=REMOVE_KEY_CONTRACT, session_contract=REMOVE_KEY_CONTRACT, public_key=weight_key.public_key_path, private_key=weight_key.private_key_path, session_args=args, )
def set_key_thresholds(node, identity_key: str, weight_key, key_management_weight: int, deploy_weight: int): args_json = json.dumps([{ "u32": key_management_weight }, { "u32": deploy_weight }]) args = ABI.args_from_json(args_json) return node.deploy_and_propose( from_address=identity_key, payment_contract=SET_THRESHOLDS_CONTRACT, session_contract=SET_THRESHOLDS_CONTRACT, public_key=weight_key.public_key_path, private_key=weight_key.private_key_path, session_args=args, )
def call_ttt(network: CasperLabsNetwork, account: Account, ttt_contract_hash: str, json_args: str) -> (str, str): """ Wrapper method for contract deployment. """ node = network.docker_nodes[0] payment = node.p_client.node.resources_folder / Contract.STANDARD_PAYMENT client = node.p_client.client status, deploy_hash = client.deploy( from_addr=account.public_key_binary, gas_price=1, private_key=account.private_key_path, public_key=account.public_key_path, payment=payment, payment_args=[ABI.u512("amount", 10000000)], session_hash=bytes.fromhex(ttt_contract_hash), session_args=ABI.args_from_json(json_args)) response = client.propose() block_hash = response.block_hash.hex() return block_hash, deploy_hash.hex()
def test_args_parser(): account = ( b"\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08" b"\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07" ) amount = 123456 args = [{"name": "amount", "value": {"long_value": amount}}, {"name": "account", "value": {"bytes_value": account.hex()}}, {"name": "purse_id", "value": {"optional_value": {}}}, {"name": "number", "value": {"big_int": {"value": "2", "bit_width": 512}}}] json_str = json.dumps(args) assert ABI.args_from_json(json_str) == ABI.args( [ABI.long_value(amount), ABI.account(account), ABI.optional_value(None), ABI.big_int(2)] )
def test_args_parser(): account_hex = "0001000200030004000500060007000800000001000200030004000500060007" account_bytes = ( b"\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08" b"\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07") u32 = 1024 u64 = 1234567890 json_str = json.dumps([{ "u32": u32 }, { "account": account_hex }, { "u64": u64 }]) assert ABI.args_from_json(json_str) == ABI.args( [ABI.u32(1024), ABI.account(account_bytes), ABI.u64(1234567890)])
def test_args_from_json(): account = bytes(range(32)) long_value = 123456 big_int_value = 123456789012345678901234567890 args = [ { "name": "amount", "value": { "long_value": long_value } }, { "name": "account", "value": { "bytes_value": account.hex() } }, { "name": "purse_id", "value": { "optional_value": {} } }, { "name": "number", "value": { "big_int": { "value": f"{big_int_value}", "bit_width": 512 } }, }, ] json_str = json.dumps(args) args = ABI.args_from_json(json_str) assert args[0] == ABI.long_value("amount", long_value) assert args[1] == ABI.account("account", account) assert args[2] == ABI.optional_value("purse_id", None) assert args[3] == ABI.big_int("number", big_int_value)
def account_weight_abi(key: str, weight: int): args_json = json.dumps([{"account": key}, {"u32": weight}]) return ABI.args_from_json(args_json)