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_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)