From b821845f062dd9e8d0a713e9a4d56886f69d12b8 Mon Sep 17 00:00:00 2001 From: Starknet Dev <42612612+starknetdev@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:17:50 +0000 Subject: [PATCH] feat(bindgen): add `AccountInterface` to function (#2770) --- crates/dojo/bindgen/src/lib.rs | 3 ++- .../plugins/typescript/generator/function.rs | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/dojo/bindgen/src/lib.rs b/crates/dojo/bindgen/src/lib.rs index 5fafebf89e..704745c31e 100644 --- a/crates/dojo/bindgen/src/lib.rs +++ b/crates/dojo/bindgen/src/lib.rs @@ -257,9 +257,10 @@ mod tests { None }; + dbg!(&config.manifest_path()); let data = gather_dojo_data(&config.manifest_path().to_path_buf(), "ns", "dev", skip_migrations) - .unwrap(); + .expect("Failed to gather dojo data"); assert_eq!(data.models.len(), 6); diff --git a/crates/dojo/bindgen/src/plugins/typescript/generator/function.rs b/crates/dojo/bindgen/src/plugins/typescript/generator/function.rs index 8161ab6a6b..e678ed5b60 100644 --- a/crates/dojo/bindgen/src/plugins/typescript/generator/function.rs +++ b/crates/dojo/bindgen/src/plugins/typescript/generator/function.rs @@ -13,8 +13,13 @@ impl TsFunctionGenerator { fn check_imports(&self, buffer: &mut Buffer) { if !buffer.has("import { DojoProvider } from ") { buffer.insert(0, "import { DojoProvider } from \"@dojoengine/core\";".to_owned()); - buffer - .insert(1, format!("import {{ Account, {} }} from \"starknet\";", JS_BIGNUMBERISH)); + buffer.insert( + 1, + format!( + "import {{ Account, AccountInterface, {} }} from \"starknet\";", + JS_BIGNUMBERISH + ), + ); buffer.insert(2, "import * as models from \"./models.gen\";\n".to_owned()); } } @@ -79,7 +84,7 @@ impl TsFunctionGenerator { fn format_function_inputs(&self, token: &Function) -> String { let inputs = match token.state_mutability { - StateMutability::External => vec!["snAccount: Account".to_owned()], + StateMutability::External => vec!["snAccount: Account | AccountInterface".to_owned()], StateMutability::View => Vec::new(), }; token @@ -260,8 +265,8 @@ mod tests { fn test_generate_system_function() { let generator = TsFunctionGenerator {}; let function = create_change_theme_function(); - let expected = "\tconst actions_changeTheme = async (snAccount: Account, value: \ - BigNumberish) => { + let expected = "\tconst actions_changeTheme = async (snAccount: Account | \ + AccountInterface, value: BigNumberish) => { \t\ttry { \t\t\treturn await provider.execute( \t\t\t\tsnAccount, @@ -293,7 +298,7 @@ mod tests { fn test_format_function_inputs() { let generator = TsFunctionGenerator {}; let function = create_change_theme_function(); - let expected = "snAccount: Account, value: BigNumberish"; + let expected = "snAccount: Account | AccountInterface, value: BigNumberish"; assert_eq!(expected, generator.format_function_inputs(&function)) } #[test] @@ -308,7 +313,7 @@ mod tests { fn test_format_function_inputs_complex() { let generator = TsFunctionGenerator {}; let function = create_change_theme_function(); - let expected = "snAccount: Account, value: BigNumberish"; + let expected = "snAccount: Account | AccountInterface, value: BigNumberish"; assert_eq!(expected, generator.format_function_inputs(&function)) }