diff --git a/crates/e2e-move-tests/Cargo.toml b/crates/e2e-move-tests/Cargo.toml index d6b5e665..f66ce477 100644 --- a/crates/e2e-move-tests/Cargo.toml +++ b/crates/e2e-move-tests/Cargo.toml @@ -22,6 +22,7 @@ sha3 = { workspace = true } bytes = { workspace = true } bigdecimal = { workspace = true } bech32 = { workspace = true } +base64 = { workspace = true } initia-move-types = { workspace = true } initia-move-vm = { workspace = true } diff --git a/crates/e2e-move-tests/src/tests/cosmos.rs b/crates/e2e-move-tests/src/tests/cosmos.rs index 9877ddc1..d3fe38f1 100644 --- a/crates/e2e-move-tests/src/tests/cosmos.rs +++ b/crates/e2e-move-tests/src/tests/cosmos.rs @@ -8,6 +8,7 @@ use move_core_types::account_address::AccountAddress; use move_core_types::language_storage::TypeTag; use move_core_types::vm_status::VMStatus; +use base64::{self, Engine}; use bech32::{Bech32, Hrp}; use sha3::{Digest, Sha3_256}; @@ -397,7 +398,7 @@ fn test_cosmos_pay_fee() { let timeout_fee_denom = str::from_utf8(FEE_B_SYMBOL).unwrap(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"fee\":{{\"ack_fee\":[{{\"amount\":\"{ack_fee_amount}\",\"denom\":\"{ack_fee_denom}\"}}],\"recv_fee\":[{{\"amount\":\"{recv_fee_amount}\",\"denom\":\"{recv_fee_denom}\"}}],\"timeout_fee\":[{{\"amount\":\"{timeout_fee_amount}\",\"denom\":\"{timeout_fee_denom}\"}}]}},\"relayers\":[],\"signer\":\"{sender_cosmos_addr}\",\"source_channel\":\"{source_channel}\",\"source_port\":\"{source_port}\"}}"); + let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"fee\":{{\"ack_fee\":[{{\"amount\":\"{ack_fee_amount}\",\"denom\":\"{ack_fee_denom}\"}}],\"recv_fee\":[{{\"amount\":\"{recv_fee_amount}\",\"denom\":\"{recv_fee_denom}\"}}],\"timeout_fee\":[{{\"amount\":\"{timeout_fee_amount}\",\"denom\":\"{timeout_fee_denom}\"}}]}},\"relayers\":[],\"signer\":\"{sender_cosmos_addr}\",\"source_channel_id\":\"{source_channel}\",\"source_port_id\":\"{source_port}\"}}"); let test_pay_fee = ( sender, @@ -442,12 +443,13 @@ fn test_cosmos_move_execute() { let arg1 = vec![1, 2, 3]; let arg2 = vec![4, 5, 6]; - let arg1_hex = hex::encode(arg1.clone()); - let arg2_hex = hex::encode(arg2.clone()); + let base64 = base64::engine::general_purpose::STANDARD; + let arg1_base64 = base64.encode(arg1.clone()); + let arg2_base64 = base64.encode(arg2.clone()); let module_addr_hex = module_address.to_hex_literal(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"args\":[\"{arg1_hex}\",\"{arg2_hex}\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); let test_move_execute = ( sender, @@ -532,12 +534,13 @@ fn test_cosmos_move_script() { let arg1 = vec![1, 2, 3]; let arg2 = vec![4, 5, 6]; - let code_bytes_hex = hex::encode(code_bytes.clone()); - let arg1_hex = hex::encode(arg1.clone()); - let arg2_hex = hex::encode(arg2.clone()); + let base64 = base64::engine::general_purpose::STANDARD; + let code_bytes_base64 = base64.encode(code_bytes.clone()); + let arg1_base64 = base64.encode(arg1.clone()); + let arg2_base64 = base64.encode(arg2.clone()); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"args\":[\"{arg1_hex}\",\"{arg2_hex}\"],\"code_bytes\":\"{code_bytes_hex}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); let test_move_script = ( sender, @@ -575,10 +578,11 @@ fn test_cosmos_move_script_with_json() { let arg1 = b"\"hello\"".to_vec(); let arg2 = b"\"world\"".to_vec(); - let code_bytes_hex = hex::encode(code_bytes.clone()); + let base64 = base64::engine::general_purpose::STANDARD; + let code_bytes_base64 = base64.encode(code_bytes.clone()); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"code_bytes\":\"{code_bytes_hex}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); let test_move_script = ( sender, diff --git a/precompile/binaries/minlib/cosmos.mv b/precompile/binaries/minlib/cosmos.mv index cac09be4..1225e496 100644 Binary files a/precompile/binaries/minlib/cosmos.mv and b/precompile/binaries/minlib/cosmos.mv differ diff --git a/precompile/binaries/stdlib/cosmos.mv b/precompile/binaries/stdlib/cosmos.mv index cac09be4..1225e496 100644 Binary files a/precompile/binaries/stdlib/cosmos.mv and b/precompile/binaries/stdlib/cosmos.mv differ diff --git a/precompile/modules/initia_stdlib/sources/cosmos.move b/precompile/modules/initia_stdlib/sources/cosmos.move index 46faa211..237f975c 100644 --- a/precompile/modules/initia_stdlib/sources/cosmos.move +++ b/precompile/modules/initia_stdlib/sources/cosmos.move @@ -11,6 +11,7 @@ module initia_std::cosmos { use std::error; use std::coin::metadata_to_denom; use std::collection::collection_to_class_id; + use std::base64; use initia_std::json; @@ -78,7 +79,7 @@ module initia_std::cosmos { module_name: String, function_name: String, type_args: vector, - args: vector> + args: vector // base64 encoded } public entry fun move_execute( @@ -89,6 +90,7 @@ module initia_std::cosmos { type_args: vector, args: vector> ) { + let args = vector::map(args, |arg| base64::to_string(arg)); stargate( sender, json::marshal( @@ -142,9 +144,9 @@ module initia_std::cosmos { struct ScriptRequest has copy, drop { _type_: String, sender: String, - code_bytes: vector, + code_bytes: String, // base64 encoded type_args: vector, - args: vector> + args: vector // base64 encoded } public entry fun move_script( @@ -153,6 +155,8 @@ module initia_std::cosmos { type_args: vector, args: vector> ) { + let args = vector::map(args, |arg| base64::to_string(arg)); + let code_bytes = base64::to_string(code_bytes); stargate( sender, json::marshal( @@ -170,7 +174,7 @@ module initia_std::cosmos { struct ScriptJSONRequest has copy, drop { _type_: String, sender: String, - code_bytes: vector, + code_bytes: String, type_args: vector, args: vector } @@ -181,6 +185,7 @@ module initia_std::cosmos { type_args: vector, args: vector ) { + let code_bytes = base64::to_string(code_bytes); stargate( sender, json::marshal( @@ -356,8 +361,8 @@ module initia_std::cosmos { struct PayFeeRequest has copy, drop { _type_: String, _signer_: String, - source_port: String, - source_channel: String, + source_port_id: String, + source_channel_id: String, fee: Fee, relayers: vector } @@ -381,8 +386,8 @@ module initia_std::cosmos { &PayFeeRequest { _type_: string::utf8(b"/ibc.applications.fee.v1.MsgPayPacketFee"), _signer_: address::to_sdk(signer::address_of(sender)), - source_port, - source_channel, + source_port_id: source_port, + source_channel_id: source_channel, fee: Fee { recv_fee: vector[ CosmosCoin { diff --git a/precompile/modules/minitia_stdlib/sources/cosmos.move b/precompile/modules/minitia_stdlib/sources/cosmos.move index 045b61ec..ce745752 100644 --- a/precompile/modules/minitia_stdlib/sources/cosmos.move +++ b/precompile/modules/minitia_stdlib/sources/cosmos.move @@ -11,6 +11,7 @@ module minitia_std::cosmos { use std::error; use std::coin::metadata_to_denom; use std::collection::collection_to_class_id; + use std::base64; use minitia_std::json; @@ -78,7 +79,7 @@ module minitia_std::cosmos { module_name: String, function_name: String, type_args: vector, - args: vector> + args: vector // base64 encoded } public entry fun move_execute( @@ -89,6 +90,7 @@ module minitia_std::cosmos { type_args: vector, args: vector> ) { + let args = vector::map(args, |arg| base64::to_string(arg)); stargate( sender, json::marshal( @@ -142,9 +144,9 @@ module minitia_std::cosmos { struct ScriptRequest has copy, drop { _type_: String, sender: String, - code_bytes: vector, + code_bytes: String, // base64 encoded type_args: vector, - args: vector> + args: vector // base64 encoded } public entry fun move_script( @@ -153,6 +155,8 @@ module minitia_std::cosmos { type_args: vector, args: vector> ) { + let args = vector::map(args, |arg| base64::to_string(arg)); + let code_bytes = base64::to_string(code_bytes); stargate( sender, json::marshal( @@ -170,7 +174,7 @@ module minitia_std::cosmos { struct ScriptJSONRequest has copy, drop { _type_: String, sender: String, - code_bytes: vector, + code_bytes: String, type_args: vector, args: vector } @@ -181,6 +185,7 @@ module minitia_std::cosmos { type_args: vector, args: vector ) { + let code_bytes = base64::to_string(code_bytes); stargate( sender, json::marshal( @@ -356,8 +361,8 @@ module minitia_std::cosmos { struct PayFeeRequest has copy, drop { _type_: String, _signer_: String, - source_port: String, - source_channel: String, + source_port_id: String, + source_channel_id: String, fee: Fee, relayers: vector } @@ -381,8 +386,8 @@ module minitia_std::cosmos { &PayFeeRequest { _type_: string::utf8(b"/ibc.applications.fee.v1.MsgPayPacketFee"), _signer_: address::to_sdk(signer::address_of(sender)), - source_port, - source_channel, + source_port_id: source_port, + source_channel_id: source_channel, fee: Fee { recv_fee: vector[ CosmosCoin {