diff --git a/Cargo.lock b/Cargo.lock index c6ba2d2..5acd4e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cairo-lang-casm" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-utils", "indoc", @@ -340,7 +340,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-defs", @@ -365,7 +365,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-utils", ] @@ -373,7 +373,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -389,7 +389,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -400,7 +400,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-utils", "good_lp", @@ -409,7 +409,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -426,7 +426,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -446,7 +446,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -469,7 +469,7 @@ dependencies = [ [[package]] name = "cairo-lang-parser" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -488,7 +488,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -506,7 +506,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "quote", @@ -516,7 +516,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -529,7 +529,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "ark-ff", @@ -554,6 +554,8 @@ dependencies = [ "num-integer", "num-traits", "rand", + "serde", + "serde_json", "sha2", "smol_str", "starknet-types-core", @@ -564,7 +566,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -589,7 +591,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-utils", @@ -615,7 +617,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -630,7 +632,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -645,7 +647,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -668,7 +670,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -688,7 +690,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -697,7 +699,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -726,7 +728,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -748,7 +750,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -763,7 +765,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "genco", "xshell", @@ -772,7 +774,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -798,7 +800,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -820,7 +822,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -832,7 +834,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.8.2" -source = "git+https://github.com/cryptonerdcn/cairo.git?rev=37b729536426532aee6c0633090e5a1e46a2b197#37b729536426532aee6c0633090e5a1e46a2b197" +source = "git+https://github.com/cryptonerdcn/cairo.git?rev=79c83907997f9b715d25e9b6693a06c56f482cab#79c83907997f9b715d25e9b6693a06c56f482cab" dependencies = [ "hashbrown 0.14.5", "indexmap 2.6.0", @@ -2625,7 +2627,7 @@ dependencies = [ [[package]] name = "wasm-cairo" -version = "0.10.2" +version = "0.10.3" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -2634,6 +2636,7 @@ dependencies = [ "cairo-lang-test-runner", "clap", "console_error_panic_hook", + "js-sys", "parking_lot_core 0.8.0", "rust-embed", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index fb79664..c155173 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-cairo" -version = "0.10.2" +version = "0.10.3" authors = ["cryptonerdcn (https://twitter.com/cryptonerdcn)"] edition = "2018" description = "WASM runtime for Cairo language and Starknet" @@ -18,10 +18,11 @@ default = ["console_error_panic_hook", "wee_alloc"] clap = { version = "4.2.5", features = ["derive"] } serde_json = "1.0.91" wasm-bindgen = "0.2.87" -cairo-lang-starknet = { package = "cairo-lang-starknet", git = "https://github.com/cryptonerdcn/cairo.git", rev = "37b729536426532aee6c0633090e5a1e46a2b197"} -cairo-lang-compiler = { package = "cairo-lang-compiler", git = "https://github.com/cryptonerdcn/cairo.git", rev = "37b729536426532aee6c0633090e5a1e46a2b197"} -cairo-lang-runner = { package = "cairo-lang-runner", git = "https://github.com/cryptonerdcn/cairo.git", rev = "37b729536426532aee6c0633090e5a1e46a2b197", features = ["alloc"], default-features = false} -cairo-lang-test-runner = { package = "cairo-lang-test-runner", git = "https://github.com/cryptonerdcn/cairo.git", rev = "37b729536426532aee6c0633090e5a1e46a2b197", features = ["alloc"], default-features = false} +js-sys = "0.3" +cairo-lang-starknet = { package = "cairo-lang-starknet", git = "https://github.com/cryptonerdcn/cairo.git", rev = "79c83907997f9b715d25e9b6693a06c56f482cab"} +cairo-lang-compiler = { package = "cairo-lang-compiler", git = "https://github.com/cryptonerdcn/cairo.git", rev = "79c83907997f9b715d25e9b6693a06c56f482cab"} +cairo-lang-runner = { package = "cairo-lang-runner", git = "https://github.com/cryptonerdcn/cairo.git", rev = "79c83907997f9b715d25e9b6693a06c56f482cab", features = ["alloc"], default-features = false} +cairo-lang-test-runner = { package = "cairo-lang-test-runner", git = "https://github.com/cryptonerdcn/cairo.git", rev = "79c83907997f9b715d25e9b6693a06c56f482cab", features = ["alloc"], default-features = false} # The `console_error_panic_hook` crate provides better debugging of panics by diff --git a/src/cli.rs b/src/cli.rs index 1a89e54..ed5f50b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,7 +5,7 @@ use std::{path::Path, result}; use cairo_lang_compiler::{ wasm_cairo_interface::compile_cairo_project_with_input_string, CompilerConfig, }; -use cairo_lang_runner::wasm_cairo_interface::run_with_input_program_string; +use cairo_lang_runner::wasm_cairo_interface::{run_with_input_program_string, run_with_sierra_json_string}; use cairo_lang_starknet::wasm_cairo_interface::starknet_wasm_compile_with_input_string; use cairo_lang_test_runner::wasm_cairo_interface::run_tests_with_input_string_parsed; /// Command line args parser. @@ -41,6 +41,11 @@ pub fn main() -> anyhow::Result<()> { run_cairo_program(args.input_program_string.unwrap(), None, true, true, false, true); println!("{}", cairo_program_result_str.unwrap()); } + "runSierraProgram" => { + let sierra_program_result_str = + run_sierra_program(args.input_program_string.unwrap(), None, true, false, true); + println!("{}", sierra_program_result_str.unwrap()); + } "runTests" => { let test_results_str = run_tests(args.input_program_string.unwrap()); println!("{}", test_results_str.unwrap()); @@ -103,6 +108,21 @@ fn run_cairo_program( Ok(cairo_program_result_str) } +fn run_sierra_program( + sierra_program: String, + available_gas: Option, + print_full_memory: bool, + run_profiler: bool, + use_dbg_print_hint: bool, +) -> Result { + let sierra_program_result = run_with_sierra_json_string(&sierra_program, available_gas, print_full_memory, run_profiler, use_dbg_print_hint); + let result_str = match sierra_program_result { + Ok(result) => result, + Err(e) => e.to_string() + }; + Ok(result_str) +} + fn compile_starknet_contract( starknet_contract: String, allow_warnings: bool, diff --git a/src/lib.rs b/src/lib.rs index 13583f0..adc1a4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,11 +4,12 @@ use std::path::Path; use cairo_lang_compiler::{ wasm_cairo_interface::compile_cairo_project_with_input_string, CompilerConfig, }; -use cairo_lang_runner::wasm_cairo_interface::run_with_input_program_string; +use cairo_lang_runner::wasm_cairo_interface::{run_with_input_program_string, run_with_sierra_json_string}; use cairo_lang_starknet::wasm_cairo_interface::starknet_wasm_compile_with_input_string; use cairo_lang_test_runner::wasm_cairo_interface::run_tests_with_input_string_parsed; use wasm_bindgen::prelude::*; +use js_sys::{Uint8Array, ArrayBuffer}; // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator. @@ -74,6 +75,26 @@ pub fn run_cairo_program( Ok(cairo_program_result_str) } +#[wasm_bindgen(js_name = runSierraProgram)] +pub fn run_sierra_program( + sierra_program: String, + available_gas: Option, + print_full_memory: bool, + run_profiler: bool, + use_dbg_print_hint: bool, +) -> Result { + let gas = match available_gas { + Some(0) => None, + other => other + }; + let sierra_program_result = run_with_sierra_json_string(&sierra_program, gas, print_full_memory, run_profiler, use_dbg_print_hint); + let result_str = match sierra_program_result { + Ok(result) => result, + Err(e) => e.to_string() + }; + Ok(result_str) +} + #[wasm_bindgen(js_name = runTests)] pub fn run_tests( cairo_program: String, @@ -130,3 +151,142 @@ pub fn compile_starknet_contract( }; Ok(sierra_contract_str) } + +#[wasm_bindgen(js_name = compileCairoProgramFromFile)] +pub fn compile_cairo_program_from_file(array_buffer: ArrayBuffer, replace_ids: bool) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => { + log("File content converted to string successfully"); + compile_cairo_program(content, replace_ids) + }, + Err(e) => { + let error_msg = format!("Failed to decode content: {}", e); + log(&error_msg); + Err(JsError::new(&error_msg)) + } + } +} + +#[wasm_bindgen(js_name = testFileRead)] +pub fn test_file_read(array_buffer: ArrayBuffer) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => Ok(format!("Content length: {}", content.len())), + Err(e) => Err(JsError::new(&format!("Failed to decode content: {}", e))) + } +} + +#[wasm_bindgen(js_name = runCairoProgramFromFile)] +pub fn run_cairo_program_from_file( + array_buffer: ArrayBuffer, + available_gas: Option, + allow_warnings: bool, + print_full_memory: bool, + run_profiler: bool, + use_dbg_print_hint: bool, +) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => { + run_cairo_program( + content, + available_gas, + allow_warnings, + print_full_memory, + run_profiler, + use_dbg_print_hint, + ) + }, + Err(e) => Err(JsError::new(&format!("Failed to decode content: {}", e))) + } +} + +#[wasm_bindgen(js_name = runSierraProgramFromFile)] +pub fn run_sierra_program_from_file( + array_buffer: ArrayBuffer, + available_gas: Option, + print_full_memory: bool, + run_profiler: bool, + use_dbg_print_hint: bool, +) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => run_sierra_program(content, available_gas, print_full_memory, run_profiler, use_dbg_print_hint), + Err(e) => Err(JsError::new(&format!("Failed to decode content: {}", e))) + } +} + +#[wasm_bindgen(js_name = runTestsFromFile)] +pub fn run_tests_from_file( + array_buffer: ArrayBuffer, + allow_warnings: bool, + filter: String, + include_ignored: bool, + ignored: bool, + starknet: bool, + run_profiler: String, + gas_disabled: bool, + print_resource_usage: bool, +) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => { + run_tests( + content, + allow_warnings, + filter, + include_ignored, + ignored, + starknet, + run_profiler, + gas_disabled, + print_resource_usage, + ) + }, + Err(e) => Err(JsError::new(&format!("Failed to decode content: {}", e))) + } +} + +#[wasm_bindgen(js_name = compileStarknetContractFromFile)] +pub fn compile_starknet_contract_from_file( + array_buffer: ArrayBuffer, + allow_warnings: bool, + replace_ids: bool, +) -> Result { + let uint8_array = Uint8Array::new(&array_buffer); + let len = uint8_array.length() as usize; + let mut bytes = vec![0; len]; + uint8_array.copy_to(&mut bytes); + + match String::from_utf8(bytes) { + Ok(content) => { + compile_starknet_contract( + content, + allow_warnings, + replace_ids, + ) + }, + Err(e) => Err(JsError::new(&format!("Failed to decode content: {}", e))) + } +}