diff --git a/crates/e2e-move-tests/src/tests/output.rs b/crates/e2e-move-tests/src/tests/output.rs index 2ffd4ad0..f28abb4e 100644 --- a/crates/e2e-move-tests/src/tests/output.rs +++ b/crates/e2e-move-tests/src/tests/output.rs @@ -58,7 +58,7 @@ fn test_output() { vec![], ExpectedOutput::new( VMStatus::Executed, - Some("[\"123\"]".to_string()), + Some("\"123\"".to_string()), None, None, ), @@ -72,7 +72,7 @@ fn test_output() { vec![], ExpectedOutput::new( VMStatus::Executed, - Some("[[\"123\"]]".to_string()), + Some("[\"123\"]".to_string()), None, None, ), @@ -84,7 +84,7 @@ fn test_output() { "0x2::test::option_none", vec![], vec![], - ExpectedOutput::new(VMStatus::Executed, Some("[]".to_string()), None, None), + ExpectedOutput::new(VMStatus::Executed, Some("null".to_string()), None, None), ); tests.push(test_option_none); diff --git a/crates/vm/src/json/json_to_move.rs b/crates/vm/src/json/json_to_move.rs index 39138038..9d9991a3 100644 --- a/crates/vm/src/json/json_to_move.rs +++ b/crates/vm/src/json/json_to_move.rs @@ -189,24 +189,16 @@ pub(crate) fn convert_json_value_to_move_value( let full_name = format!("{}::{}", id.module_id.short_str_lossless(), id.name); match full_name.as_str() { "0x1::option::Option" => { - let json_vals = json_val - .as_array() - .ok_or_else(deserialization_error)? - .to_owned(); - - if json_vals.is_empty() { + if json_val.is_null() { return Ok(MoveValue::Vector(vec![])); - } else if json_vals.len() == 1 { - let json_val = json_vals.into_iter().next().unwrap(); - return Ok(MoveValue::Vector(vec![convert_json_value_to_move_value( - state_view, - ty, - json_val, - depth + 1, - )?])); } - return Err(deserialization_error_with_msg("invalid option value")); + return Ok(MoveValue::Vector(vec![convert_json_value_to_move_value( + state_view, + ty, + json_val, + depth + 1, + )?])); } "0x1::object::Object" => { let addr = AccountAddress::from_hex_literal( @@ -614,7 +606,7 @@ mod json_arg_testing { ty_args: Arc::new(vec![Type::Address]), ability: AbilityInfo::struct_(AbilitySet::ALL), }; - let arg = b"[\"0x1\"]"; + let arg = b"\"0x1\""; let result = deserialize_json_args(&state_view, &ty, arg).unwrap(); assert_eq!( result, @@ -622,7 +614,7 @@ mod json_arg_testing { ); // invalid inner value - let arg = b"[\"0xgg\"]"; + let arg = b"\"0xgg\""; _ = deserialize_json_args(&state_view, &ty, arg).unwrap_err(); } @@ -639,7 +631,7 @@ mod json_arg_testing { ty_args: Arc::new(vec![Type::Address]), ability: AbilityInfo::struct_(AbilitySet::ALL), }; - let arg = b"[]"; + let arg = b"null"; let result = deserialize_json_args(&state_view, &ty, arg).unwrap(); assert_eq!( result, diff --git a/crates/vm/src/json/move_to_json.rs b/crates/vm/src/json/move_to_json.rs index 0b14c022..101eae36 100644 --- a/crates/vm/src/json/move_to_json.rs +++ b/crates/vm/src/json/move_to_json.rs @@ -149,12 +149,9 @@ fn convert_option_to_json_value(val: &MoveValue, depth: usize) -> VMResult { if elem.is_empty() { - JSONValue::Array(vec![]) + JSONValue::Null } else { - JSONValue::Array(vec![convert_move_value_to_json_value( - elem.first().unwrap(), - depth + 1, - )?]) + convert_move_value_to_json_value(elem.first().unwrap(), depth + 1)? } } _ => unreachable!(), @@ -267,7 +264,7 @@ mod move_to_json_tests { )], }); let val = convert_move_value_to_json_value(&mv, 1).unwrap(); - assert_eq!(val, json!([123u8])); + assert_eq!(val, json!(123u8)); // option none let mv = MoveValue::Struct(MoveStruct::WithTypes { @@ -280,7 +277,7 @@ mod move_to_json_tests { fields: vec![(ident_str!("vec").into(), MoveValue::Vector(vec![]))], }); let val = convert_move_value_to_json_value(&mv, 1).unwrap(); - assert_eq!(val, json!([])); + assert_eq!(val, json!(null)); // decimal128 const DECIMAL_SCALE: u128 = 1_000_000_000_000_000_000; diff --git a/precompile/binaries/stdlib/minitswap.mv b/precompile/binaries/stdlib/minitswap.mv index 69ce2466..13826d2b 100644 Binary files a/precompile/binaries/stdlib/minitswap.mv and b/precompile/binaries/stdlib/minitswap.mv differ