Skip to content

Commit

Permalink
Updates hardcoded JSON ABI.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jul 22, 2024
1 parent 3c844ec commit 637d43a
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions forc-plugins/forc-client/src/op/run/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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();
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 637d43a

Please sign in to comment.