Skip to content

Commit

Permalink
feat(bindgen): add AccountInterface to function (#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev authored Dec 6, 2024
1 parent 575040c commit b821845
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion crates/dojo/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 12 additions & 7 deletions crates/dojo/bindgen/src/plugins/typescript/generator/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -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))
}

Expand Down

0 comments on commit b821845

Please sign in to comment.