diff --git a/crates/gateway/build.rs b/crates/gateway/build.rs new file mode 100644 index 0000000000..2c3d009e87 --- /dev/null +++ b/crates/gateway/build.rs @@ -0,0 +1,3 @@ +// Sets up the environment variable OUT_DIR, which holds the cairo compiler binary. +// The binary is dowloaded to OUT_DIR by the starknet_sierra_compile crate. +fn main() {} diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index aab1affc40..45330c01e7 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -6,6 +6,7 @@ use starknet_api::contract_class::ClassInfo; use starknet_api::core::CompiledClassHash; use starknet_api::rpc_transaction::RpcDeclareTransaction; use starknet_sierra_compile::cairo_lang_compiler::CairoLangSierraToCasmCompiler; +use starknet_sierra_compile::command_line_compiler::CommandLineCompiler; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; use starknet_sierra_compile::utils::into_contract_class_for_compilation; use starknet_sierra_compile::SierraToCasmCompiler; @@ -24,6 +25,11 @@ pub struct GatewayCompiler { } impl GatewayCompiler { + pub fn new_command_line_compiler(config: SierraToCasmCompilationConfig) -> Self { + Self { sierra_to_casm_compiler: Arc::new(CommandLineCompiler::new(config)) } + } + + // TODO(Arni): Cosider deleting `CairoLangSierraToCasmCompiler`. pub fn new_cairo_lang_compiler(config: SierraToCasmCompilationConfig) -> Self { Self { sierra_to_casm_compiler: Arc::new(CairoLangSierraToCasmCompiler { config }) } } diff --git a/crates/gateway/src/compilation_test.rs b/crates/gateway/src/compilation_test.rs index 8c41913c12..fd1ac08500 100644 --- a/crates/gateway/src/compilation_test.rs +++ b/crates/gateway/src/compilation_test.rs @@ -19,7 +19,7 @@ use crate::errors::GatewaySpecError; #[fixture] fn gateway_compiler() -> GatewayCompiler { - GatewayCompiler::new_cairo_lang_compiler(SierraToCasmCompilationConfig::default()) + GatewayCompiler::new_command_line_compiler(SierraToCasmCompilationConfig::default()) } #[fixture] @@ -58,14 +58,15 @@ fn test_compile_contract_class_compiled_class_hash_mismatch( #[rstest] fn test_compile_contract_class_bytecode_size_validation(declare_tx_v3: RpcDeclareTransactionV3) { let gateway_compiler = - GatewayCompiler::new_cairo_lang_compiler(SierraToCasmCompilationConfig { + GatewayCompiler::new_command_line_compiler(SierraToCasmCompilationConfig { max_bytecode_size: 1, }); let result = gateway_compiler.process_declare_tx(&RpcDeclareTransaction::V3(declare_tx_v3)); assert_matches!(result.unwrap_err(), GatewaySpecError::CompilationFailed); - let expected_compilation_error = - CompilationUtilError::CompilationError("Code size limit exceeded.".to_owned()); + let expected_compilation_error = CompilationUtilError::CompilationError( + "Error: Compilation failed.\n\nCaused by:\n Code size limit exceeded.\n".to_owned(), + ); assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str())); } @@ -84,7 +85,7 @@ fn test_compile_contract_class_bad_sierra( assert_eq!(err, GatewaySpecError::CompilationFailed); let expected_compilation_error = - CompilationUtilError::CompilationError("Invalid Sierra program.".to_owned()); + CompilationUtilError::CompilationError("Error: Invalid Sierra program.\n".to_owned()); assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str())); } diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 7a8ca45093..52a0bcd3ca 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -163,7 +163,7 @@ pub fn create_gateway( mempool_client: SharedMempoolClient, ) -> Gateway { let state_reader_factory = Arc::new(RpcStateReaderFactory { config: rpc_state_reader_config }); - let gateway_compiler = GatewayCompiler::new_cairo_lang_compiler(compiler_config); + let gateway_compiler = GatewayCompiler::new_command_line_compiler(compiler_config); Gateway::new(config, state_reader_factory, gateway_compiler, mempool_client) } diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index 0015858609..46e0967417 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -34,7 +34,7 @@ pub fn app_state( stateful_tx_validator: Arc::new(StatefulTransactionValidator { config: StatefulTransactionValidatorConfig::create_for_testing(), }), - gateway_compiler: GatewayCompiler::new_cairo_lang_compiler( + gateway_compiler: GatewayCompiler::new_command_line_compiler( SierraToCasmCompilationConfig::default(), ), state_reader_factory: Arc::new(state_reader_factory), diff --git a/crates/tests-integration/build.rs b/crates/tests-integration/build.rs new file mode 100644 index 0000000000..2c3d009e87 --- /dev/null +++ b/crates/tests-integration/build.rs @@ -0,0 +1,3 @@ +// Sets up the environment variable OUT_DIR, which holds the cairo compiler binary. +// The binary is dowloaded to OUT_DIR by the starknet_sierra_compile crate. +fn main() {}