diff --git a/forc-plugins/forc-client/src/op/run/encode.rs b/forc-plugins/forc-client/src/op/run/encode.rs index c1f36524591..3849635226f 100644 --- a/forc-plugins/forc-client/src/op/run/encode.rs +++ b/forc-plugins/forc-client/src/op/run/encode.rs @@ -62,14 +62,17 @@ impl ScriptCallHandler { mod tests { use super::{ScriptCallHandler, Type}; + const TEST_JSON_ABI: &str = r#"{"concreteTypes":[{"concreteTypeId":"2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d", + "type":"()"},{"concreteTypeId":"b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903","type":"bool"}, + {"concreteTypeId":"c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b","type":"u8"}], + "functions":[{"inputs":[{"name":"test_u8","type":"c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b"}, + {"name":"test_bool","type":"b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903"}],"name":"main", + "output":"2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"}],"loggedTypes":[], + "messagesTypes":[],"configurables":[]}"#; + #[test] fn test_script_call_handler_generation_success() { - let test_json_abi = r#"{"types":[{"typeId":0,"type":"()","components":[],"typeParameters":null}, -{"typeId":1,"type":"bool","components":null,"typeParameters":null},{"typeId":2,"type":"u8","components":null, -"typeParameters":null}],"functions":[{"inputs":[{"name":"test_u8","type":2,"typeArguments":null},{"name":"test_bool", -"type":1,"typeArguments":null}],"name":"main","output":{"name":"","type":0,"typeArguments":null},"attributes":null}], -"loggedTypes":[],"messagesTypes":[],"configurables":[]}"#; - let generated_call_handler = ScriptCallHandler::from_json_abi_str(test_json_abi).unwrap(); + let generated_call_handler = ScriptCallHandler::from_json_abi_str(TEST_JSON_ABI).unwrap(); let expected_call_handler = ScriptCallHandler { main_arg_types: vec![Type::U8, Type::Bool], @@ -88,12 +91,7 @@ mod tests { #[test] fn test_main_encoding_success() { - let test_json_abi = r#"{"types":[{"typeId":0,"type":"()","components":[],"typeParameters":null}, -{"typeId":1,"type":"bool","components":null,"typeParameters":null},{"typeId":2,"type":"u8","components":null, -"typeParameters":null}],"functions":[{"inputs":[{"name":"test_u8","type":2,"typeArguments":null},{"name":"test_bool", -"type":1,"typeArguments":null}],"name":"main","output":{"name":"","type":0,"typeArguments":null},"attributes":null}], -"loggedTypes":[],"messagesTypes":[],"configurables":[]}"#; - let call_handler = ScriptCallHandler::from_json_abi_str(test_json_abi).unwrap(); + let call_handler = ScriptCallHandler::from_json_abi_str(TEST_JSON_ABI).unwrap(); let values = ["2", "true"]; let encoded_bytes = call_handler.encode_arguments(&values).unwrap(); @@ -104,12 +102,7 @@ mod tests { #[test] #[should_panic] fn test_main_encoding_fail_arg_type_mismatch() { - let test_json_abi = r#"{"types":[{"typeId":0,"type":"()","components":[],"typeParameters":null}, -{"typeId":1,"type":"bool","components":null,"typeParameters":null},{"typeId":2,"type":"u8","components":null, -"typeParameters":null}],"functions":[{"inputs":[{"name":"test_u8","type":2,"typeArguments":null},{"name":"test_bool", -"type":1,"typeArguments":null}],"name":"main","output":{"name":"","type":0,"typeArguments":null},"attributes":null}], -"loggedTypes":[],"messagesTypes":[],"configurables":[]}"#; - let call_handler = ScriptCallHandler::from_json_abi_str(test_json_abi).unwrap(); + let call_handler = ScriptCallHandler::from_json_abi_str(TEST_JSON_ABI).unwrap(); // The abi describes the following main function: // - fn main(test_u8: u8, test_bool: bool) // Providing a bool to u8 field should return an error. @@ -120,12 +113,7 @@ mod tests { #[test] #[should_panic(expected = "main function takes 2 arguments, 1 provided")] fn test_main_encoding_fail_arg_count_mismatch() { - let test_json_abi = r#"{"types":[{"typeId":0,"type":"()","components":[],"typeParameters":null}, -{"typeId":1,"type":"bool","components":null,"typeParameters":null},{"typeId":2,"type":"u8","components":null, -"typeParameters":null}],"functions":[{"inputs":[{"name":"test_u8","type":2,"typeArguments":null},{"name":"test_bool", -"type":1,"typeArguments":null}],"name":"main","output":{"name":"","type":0,"typeArguments":null},"attributes":null}], -"loggedTypes":[],"messagesTypes":[],"configurables":[]}"#; - let call_handler = ScriptCallHandler::from_json_abi_str(test_json_abi).unwrap(); + let call_handler = ScriptCallHandler::from_json_abi_str(TEST_JSON_ABI).unwrap(); // The abi describes the following main function: // - fn main(test_u8: u8, test_bool: bool) // Providing only 1 value should return an error as function requires 2 args.