From b4abf82467f5552dd63bc267a59f585ab7407000 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 17 Sep 2024 09:24:01 +0530 Subject: [PATCH 001/104] update dependencies --- Cargo.lock | 148 +++++++++++++----- Cargo.toml | 4 +- crates/orchestrator/src/jobs/da_job/mod.rs | 37 ++--- .../orchestrator/src/tests/jobs/da_job/mod.rs | 4 +- .../gps-fact-checker/src/fact_info.rs | 9 +- .../starknet/src/conversion.rs | 8 +- crates/settlement-clients/starknet/src/lib.rs | 61 ++++---- 7 files changed, 177 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14db58fd..87fb231b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3977,7 +3977,7 @@ dependencies = [ "mongodb", "orchestrator", "reqwest 0.12.7", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "serde_json", "starknet", @@ -4093,11 +4093,11 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" dependencies = [ - "heck 0.4.1", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.66", @@ -4189,7 +4189,7 @@ dependencies = [ "dotenvy", "mockall", "reqwest 0.12.7", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "starknet", "tokio", @@ -4212,7 +4212,7 @@ dependencies = [ "log", "mockall", "reqwest 0.12.7", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "settlement-client-interface", "snos", @@ -4901,7 +4901,7 @@ dependencies = [ "async-trait", "cfg-if", "data-encoding", - "enum-as-inner 0.6.0", + "enum-as-inner 0.6.1", "futures-channel", "futures-io", "futures-util", @@ -6453,7 +6453,7 @@ dependencies = [ "num-traits 0.2.19", "omniqueue", "prover-client-interface", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "serde_json", "settlement-client-interface", @@ -7602,6 +7602,18 @@ dependencies = [ "rustc_version 0.4.0", ] +[[package]] +name = "rstest" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b423f0e62bdd61734b67cd21ff50871dfaeb9cc74f869dcd6af974fbcb19936" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros 0.22.0", + "rustc_version 0.4.0", +] + [[package]] name = "rstest_macros" version = "0.17.0" @@ -7650,6 +7662,24 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "rstest_macros" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e1711e7d14f74b12a58411c542185ef7fb7f2e7f8ee6e2940a883628522b42" +dependencies = [ + "cfg-if", + "glob", + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version 0.4.0", + "syn 2.0.66", + "unicode-ident", +] + [[package]] name = "ruint" version = "1.12.3" @@ -8460,7 +8490,7 @@ dependencies = [ "log", "prover-client-interface", "reqwest 0.12.7", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "serde_json", "snos", @@ -8678,15 +8708,14 @@ dependencies = [ [[package]] name = "starknet" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f8002bf3d750dd2c0434aca8b5e88e2438cd6c452f4c18f34d0a8a9f42cb1a" +checksum = "1e633a772f59214c296d5037c95c36b72792c9360323818da2b625c7b4ec4b49" dependencies = [ "starknet-accounts", "starknet-contract", - "starknet-core 0.9.0", - "starknet-crypto 0.6.2", - "starknet-ff", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", "starknet-macros", "starknet-providers", "starknet-signers", @@ -8694,13 +8723,14 @@ dependencies = [ [[package]] name = "starknet-accounts" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e39a5807a735343493781dd5e640c4af838de470b0a73f420bed642fdc2ff1" +checksum = "eee8a6b588a22c7e79f5d8d4e33413387db63a8beb98be8610138541794cc0a5" dependencies = [ "async-trait", "auto_impl", - "starknet-core 0.9.0", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", "starknet-providers", "starknet-signers", "thiserror", @@ -8708,15 +8738,15 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4996991356cd0e9499c663680eba7e77de4109e4995f652c1608899a65c09ee" +checksum = "a5f91344f1e0b81873b6dc235c50ae4d084c6ea4dd4a1e3e27ad895803adb610" dependencies = [ "serde", "serde_json", "serde_with 2.3.3", "starknet-accounts", - "starknet-core 0.9.0", + "starknet-core 0.11.1", "starknet-providers", "thiserror", ] @@ -8741,11 +8771,12 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed286d637e34fb8ae1cd2f9615120ec8ff38d1cffd311ed7fdd497cdd2bd01f" +checksum = "d506e02a4083290d13b427dfe437fd95aa8b56315c455bb2f9cdeca76620d457" dependencies = [ "base64 0.21.7", + "crypto-bigint 0.5.5", "flate2", "hex", "serde", @@ -8753,8 +8784,8 @@ dependencies = [ "serde_json_pythonic", "serde_with 2.3.3", "sha3", - "starknet-crypto 0.6.2", - "starknet-ff", + "starknet-crypto 0.7.1", + "starknet-types-core", ] [[package]] @@ -8771,7 +8802,7 @@ dependencies = [ "num-traits 0.2.19", "rfc6979 0.4.0", "sha2", - "starknet-crypto-codegen", + "starknet-crypto-codegen 0.3.3", "starknet-curve 0.3.0", "starknet-ff", "zeroize", @@ -8791,12 +8822,32 @@ dependencies = [ "num-traits 0.2.19", "rfc6979 0.4.0", "sha2", - "starknet-crypto-codegen", + "starknet-crypto-codegen 0.3.3", "starknet-curve 0.4.2", "starknet-ff", "zeroize", ] +[[package]] +name = "starknet-crypto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2a821ad8d98c6c3e4d0e5097f3fe6e2ed120ada9d32be87cd1330c7923a2f0" +dependencies = [ + "crypto-bigint 0.5.5", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "rfc6979 0.4.0", + "sha2", + "starknet-crypto-codegen 0.4.0", + "starknet-curve 0.5.0", + "starknet-types-core", + "zeroize", +] + [[package]] name = "starknet-crypto-codegen" version = "0.3.3" @@ -8808,6 +8859,17 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "starknet-crypto-codegen" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" +dependencies = [ + "starknet-curve 0.5.0", + "starknet-types-core", + "syn 2.0.66", +] + [[package]] name = "starknet-curve" version = "0.3.0" @@ -8826,6 +8888,15 @@ dependencies = [ "starknet-ff", ] +[[package]] +name = "starknet-curve" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56935b306dcf0b8f14bb2a1257164b8478bb8be4801dfae0923f5b266d1b457c" +dependencies = [ + "starknet-types-core", +] + [[package]] name = "starknet-ff" version = "0.3.7" @@ -8837,7 +8908,6 @@ dependencies = [ "crypto-bigint 0.5.5", "getrandom", "hex", - "num-bigint", "serde", ] @@ -8866,30 +8936,31 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.1.7" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95d549d3078bdbe775d0deaa8ddb57a19942989ce7c1f2dfd60beeb322bb4945" +checksum = "f4fe4f8d615329410578cbedcdbaa4a36c7f28f68c3f3ac56006cfbdaeaa2b41" dependencies = [ - "starknet-core 0.10.0", + "starknet-core 0.11.1", "syn 2.0.66", ] [[package]] name = "starknet-providers" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a4bd1c262936543d6d14d299f476585e8c9625a4e284d9255b54f1c2e68e64a" +checksum = "59c85e0a0f4563ae95dfeae14ea0f0c70610efc0ec2462505c64eff5765e7b97" dependencies = [ "async-trait", "auto_impl", "ethereum-types", "flate2", + "getrandom", "log", "reqwest 0.11.27", "serde", "serde_json", "serde_with 2.3.3", - "starknet-core 0.9.0", + "starknet-core 0.11.1", "thiserror", "url", ] @@ -8904,7 +8975,7 @@ dependencies = [ "lazy_static", "mockall", "reqwest 0.12.7", - "rstest 0.18.2", + "rstest 0.22.0", "serde", "settlement-client-interface", "starknet", @@ -8916,17 +8987,18 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c5eb659e66b56ceafb9025cd601226d8f34d273f1b826cd4053ab6333ff0898" +checksum = "c17da2139119dbe3aacf1d5d4338798a5c489d17f424916ceb9d2efd83554f87" dependencies = [ "async-trait", "auto_impl", "crypto-bigint 0.5.5", "eth-keystore", + "getrandom", "rand", - "starknet-core 0.9.0", - "starknet-crypto 0.6.2", + "starknet-core 0.11.1", + "starknet-crypto 0.7.1", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 78a46eae..84b73151 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,10 +55,10 @@ reqwest = { version = "0.12.7", features = [ "native-tls", "json", ] } -rstest = "0.18.2" +rstest = "0.22.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" -starknet = "0.9.0" +starknet = "0.11.0" tempfile = "3.8.1" thiserror = "1.0.57" tokio = { version = "1.37.0" } diff --git a/crates/orchestrator/src/jobs/da_job/mod.rs b/crates/orchestrator/src/jobs/da_job/mod.rs index 800cc195..66aff30c 100644 --- a/crates/orchestrator/src/jobs/da_job/mod.rs +++ b/crates/orchestrator/src/jobs/da_job/mod.rs @@ -9,9 +9,10 @@ use color_eyre::eyre::WrapErr; use lazy_static::lazy_static; use num_bigint::{BigUint, ToBigUint}; use num_traits::{Num, Zero}; -use starknet::core::types::{BlockId, FieldElement, MaybePendingStateUpdate, StateUpdate}; +use starknet::core::types::{ + BlockId, ContractStorageDiffItem, DeclaredClassItem, Felt, MaybePendingStateUpdate, StateUpdate, +}; use starknet::providers::Provider; -use starknet_core::types::{ContractStorageDiffItem, DeclaredClassItem}; use thiserror::Error; use tracing::log; use uuid::Uuid; @@ -189,7 +190,7 @@ pub fn fft_transformation(elements: Vec) -> Vec { transform } -pub fn convert_to_biguint(elements: Vec) -> Vec { +pub fn convert_to_biguint(elements: Vec) -> Vec { // Initialize the vector with 4096 BigUint zeros let mut biguint_vec = vec![BigUint::zero(); 4096]; @@ -239,16 +240,16 @@ pub async fn state_update_to_blob_data( block_no: u64, state_update: StateUpdate, config: Arc, -) -> color_eyre::Result> { +) -> color_eyre::Result> { let mut state_diff = state_update.state_diff; - let mut blob_data: Vec = vec![FieldElement::from(state_diff.storage_diffs.len())]; + let mut blob_data: Vec = vec![Felt::from(state_diff.storage_diffs.len())]; - let deployed_contracts: HashMap = + let deployed_contracts: HashMap = state_diff.deployed_contracts.into_iter().map(|item| (item.address, item.class_hash)).collect(); - let replaced_classes: HashMap = + let replaced_classes: HashMap = state_diff.replaced_classes.into_iter().map(|item| (item.contract_address, item.class_hash)).collect(); - let mut nonces: HashMap = + let mut nonces: HashMap = state_diff.nonces.into_iter().map(|item| (item.contract_address, item.nonce)).collect(); // sort storage diffs @@ -263,7 +264,7 @@ pub async fn state_update_to_blob_data( // @note: if nonce is null and there is some len of writes, make an api call to get the contract // nonce for the block - if nonce.is_none() && !storage_entries.is_empty() && address != FieldElement::ONE { + if nonce.is_none() && !storage_entries.is_empty() && address != Felt::ONE { let get_current_nonce_result = config .starknet_client() .get_nonce(BlockId::Number(block_no), address) @@ -287,7 +288,7 @@ pub async fn state_update_to_blob_data( } } // Handle declared classes - blob_data.push(FieldElement::from(state_diff.declared_classes.len())); + blob_data.push(Felt::from(state_diff.declared_classes.len())); // sort storage diffs state_diff.declared_classes.sort_by_key(|class| class.class_hash); @@ -317,7 +318,7 @@ async fn store_blob_data(blob_data: Vec, block_number: u64, config: Arc /// DA word encoding: /// |---padding---|---class flag---|---new nonce---|---num changes---| /// 127 bits 1 bit 64 bits 64 bits -fn da_word(class_flag: bool, nonce_change: Option, num_changes: u64) -> FieldElement { +fn da_word(class_flag: bool, nonce_change: Option, num_changes: u64) -> Felt { // padding of 127 bits let mut binary_string = "0".repeat(127); @@ -349,7 +350,7 @@ fn da_word(class_flag: bool, nonce_change: Option, num_changes: u6 // Now convert the BigUint to a decimal string let decimal_string = biguint.to_str_radix(10); - FieldElement::from_dec_str(&decimal_string).expect("issue while converting to fieldElement") + Felt::from_dec_str(&decimal_string).expect("issue while converting to fieldElement") } #[cfg(test)] @@ -366,9 +367,9 @@ pub mod test { use majin_blob_types::serde; use rstest::rstest; use serde_json::json; + use starknet::core::types::{Felt, StateUpdate}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; - use starknet_core::types::{FieldElement, StateUpdate}; use url::Url; use da_client_interface::MockDaClient; @@ -376,9 +377,9 @@ pub mod test { use crate::jobs::da_job::da_word; /// Tests `da_word` function with various inputs for class flag, new nonce, and number of changes. - /// Verifies that `da_word` produces the correct FieldElement based on the provided parameters. + /// Verifies that `da_word` produces the correct Felt based on the provided parameters. /// Uses test cases with different combinations of inputs and expected output strings. - /// Asserts the function's correctness by comparing the computed and expected FieldElements. + /// Asserts the function's correctness by comparing the computed and expected Felts. #[rstest] #[case(false, 1, 1, "18446744073709551617")] #[case(false, 1, 0, "18446744073709551616")] @@ -390,9 +391,9 @@ pub mod test { #[case] num_changes: u64, #[case] expected: String, ) { - let new_nonce = if new_nonce > 0 { Some(FieldElement::from(new_nonce)) } else { None }; + let new_nonce = if new_nonce > 0 { Some(Felt::from(new_nonce)) } else { None }; let da_word = da_word(class_flag, new_nonce, num_changes); - let expected = FieldElement::from_dec_str(expected.as_str()).unwrap(); + let expected = Felt::from_dec_str(expected.as_str()).unwrap(); assert_eq!(da_word, expected); } @@ -540,7 +541,7 @@ pub mod test { let nonce = entry.nonce.clone(); let response = json!({ "id": 1,"jsonrpc":"2.0","result": nonce }); let field_element = - FieldElement::from_dec_str(&address).expect("issue while converting the hex to field").to_bytes_be(); + Felt::from_dec_str(&address).expect("issue while converting the hex to field").to_bytes_be(); let hex_field_element = vec_u8_to_hex_string(&field_element); server.mock(|when, then| { diff --git a/crates/orchestrator/src/tests/jobs/da_job/mod.rs b/crates/orchestrator/src/tests/jobs/da_job/mod.rs index c5c2259b..10e518e5 100644 --- a/crates/orchestrator/src/tests/jobs/da_job/mod.rs +++ b/crates/orchestrator/src/tests/jobs/da_job/mod.rs @@ -6,7 +6,7 @@ use color_eyre::eyre::eyre; use mockall::predicate::always; use rstest::rstest; use serde_json::json; -use starknet_core::types::{FieldElement, MaybePendingStateUpdate, PendingStateUpdate, StateDiff}; +use starknet::core::types::{Felt, MaybePendingStateUpdate, PendingStateUpdate, StateDiff}; use uuid::Uuid; use da_client_interface::MockDaClient; @@ -110,7 +110,7 @@ async fn test_da_job_process_job_failure_on_pending_block() { let internal_id = "1"; let pending_state_update = MaybePendingStateUpdate::PendingUpdate(PendingStateUpdate { - old_root: FieldElement::default(), + old_root: Felt::default(), state_diff: StateDiff { storage_diffs: vec![], deprecated_declared_classes: vec![], diff --git a/crates/prover-services/gps-fact-checker/src/fact_info.rs b/crates/prover-services/gps-fact-checker/src/fact_info.rs index d203cf2c..10e87972 100644 --- a/crates/prover-services/gps-fact-checker/src/fact_info.rs +++ b/crates/prover-services/gps-fact-checker/src/fact_info.rs @@ -8,7 +8,8 @@ use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::types::relocatable::MaybeRelocatable; use cairo_vm::vm::runners::cairo_pie::CairoPie; use cairo_vm::Felt252; -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; +// use starknet::core::types::FieldElement; use super::error::FactCheckerError; use super::fact_node::generate_merkle_root; @@ -25,12 +26,14 @@ pub struct FactInfo { pub fact: B256, } -pub fn get_fact_info(cairo_pie: &CairoPie, program_hash: Option) -> Result { +pub fn get_fact_info(cairo_pie: &CairoPie, program_hash: Option) -> Result { let program_output = get_program_output(cairo_pie)?; let fact_topology = get_fact_topology(cairo_pie, program_output.len())?; let program_hash = match program_hash { Some(hash) => hash, - None => compute_program_hash_chain(&cairo_pie.metadata.program, BOOTLOADER_VERSION)?, + None => Felt::from_bytes_be( + &compute_program_hash_chain(&cairo_pie.metadata.program, BOOTLOADER_VERSION)?.to_bytes_be(), + ), }; let output_root = generate_merkle_root(&program_output, &fact_topology)?; let fact = keccak256([program_hash.to_bytes_be(), *output_root.node_hash].concat()); diff --git a/crates/settlement-clients/starknet/src/conversion.rs b/crates/settlement-clients/starknet/src/conversion.rs index 816999ea..3c3f34fb 100644 --- a/crates/settlement-clients/starknet/src/conversion.rs +++ b/crates/settlement-clients/starknet/src/conversion.rs @@ -1,9 +1,9 @@ -use starknet::core::types::FieldElement; +use starknet::core::types::Felt; -pub(crate) fn slice_slice_u8_to_vec_field(slices: &[[u8; 32]]) -> Vec { +pub(crate) fn slice_slice_u8_to_vec_field(slices: &[[u8; 32]]) -> Vec { slices.iter().map(slice_u8_to_field).collect() } -pub(crate) fn slice_u8_to_field(slice: &[u8; 32]) -> FieldElement { - FieldElement::from_byte_slice_be(slice).expect("could not convert u8 slice to FieldElement") +pub(crate) fn slice_u8_to_field(slice: &[u8; 32]) -> Felt { + Felt::from_bytes_be_slice(slice) } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 8d2f5041..42b8e74d 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -9,12 +9,12 @@ use color_eyre::Result; use lazy_static::lazy_static; use mockall::{automock, predicate::*}; use starknet::accounts::ConnectedAccount; -use starknet::core::types::{ExecutionResult, MaybePendingTransactionReceipt}; +use starknet::core::types::TransactionExecutionStatus; use starknet::providers::Provider; use starknet::{ accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount}, core::{ - types::{BlockId, BlockTag, FieldElement, FunctionCall}, + types::{BlockId, BlockTag, Felt, FunctionCall}, utils::get_selector_from_name, }, providers::{jsonrpc::HttpTransport, JsonRpcClient}, @@ -30,7 +30,7 @@ use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field}; pub struct StarknetSettlementClient { pub account: SingleOwnerAccount>, LocalWallet>, - pub core_contract_address: FieldElement, + pub core_contract_address: Felt, pub tx_finality_retry_delay_in_seconds: u64, } @@ -48,15 +48,15 @@ impl StarknetSettlementClient { let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.rpc_url))); let public_key = settings.get_settings_or_panic(ENV_PUBLIC_KEY); - let signer_address = FieldElement::from_hex_be(&public_key).expect("invalid signer address"); + let signer_address = Felt::from_hex(&public_key).expect("invalid signer address"); // TODO: Very insecure way of building the signer. Needs to be adjusted. let private_key = settings.get_settings_or_panic(ENV_PRIVATE_KEY); - let signer = FieldElement::from_hex_be(&private_key).expect("Invalid private key"); + let signer = Felt::from_hex(&private_key).expect("Invalid private key"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(signer)); let core_contract_address = - FieldElement::from_hex_be(&settlement_cfg.core_contract_address).expect("Invalid core contract address"); + Felt::from_hex(&settlement_cfg.core_contract_address).expect("Invalid core contract address"); let account = SingleOwnerAccount::new( provider.clone(), @@ -75,18 +75,18 @@ impl StarknetSettlementClient { } lazy_static! { - pub static ref CONTRACT_WRITE_UPDATE_STATE_SELECTOR: FieldElement = + pub static ref CONTRACT_WRITE_UPDATE_STATE_SELECTOR: Felt = get_selector_from_name("update_state").expect("Invalid update state selector"); // TODO: `stateBlockNumber` does not exists yet in our implementation: // https://github.com/keep-starknet-strange/piltover // It should get added to match the solidity implementation of the core contract. - pub static ref CONTRACT_READ_STATE_BLOCK_NUMBER: FieldElement = + pub static ref CONTRACT_READ_STATE_BLOCK_NUMBER: Felt = get_selector_from_name("stateBlockNumber").expect("Invalid update state selector"); } // TODO: Note that we already have an implementation of the appchain core contract client available here: // https://github.com/keep-starknet-strange/zaun/tree/main/crates/l3/appchain-core-contract-client -// However, this implementation uses different FieldElement types, and incorporating all of them +// However, this implementation uses different Felt types, and incorporating all of them // into this repository would introduce unnecessary complexity. // Therefore, we will wait for the update of starknet_rs in the Zaun repository before adapting // the StarknetSettlementClient implementation. @@ -110,13 +110,13 @@ impl SettlementClient for StarknetSettlementClient { ) -> Result { let program_output = slice_slice_u8_to_vec_field(program_output.as_slice()); let onchain_data_hash = slice_u8_to_field(&onchain_data_hash); - let mut calldata: Vec = Vec::with_capacity(program_output.len() + 2); + let mut calldata: Vec = Vec::with_capacity(program_output.len() + 2); calldata.extend(program_output); calldata.push(onchain_data_hash); - calldata.push(FieldElement::from(onchain_data_size)); + calldata.push(Felt::from(onchain_data_size)); let invoke_result = self .account - .execute(vec![Call { + .execute_v1(vec![Call { to: self.core_contract_address, selector: *CONTRACT_WRITE_UPDATE_STATE_SELECTOR, calldata, @@ -128,20 +128,26 @@ impl SettlementClient for StarknetSettlementClient { /// Should verify the inclusion of a tx in the settlement layer async fn verify_tx_inclusion(&self, tx_hash: &str) -> Result { - let tx_hash = FieldElement::from_hex_be(tx_hash)?; + let tx_hash = Felt::from_hex(tx_hash)?; let tx_receipt = self.account.provider().get_transaction_receipt(tx_hash).await?; - match tx_receipt { - MaybePendingTransactionReceipt::Receipt(tx) => match tx.execution_result() { - ExecutionResult::Succeeded => Ok(SettlementVerificationStatus::Verified), - ExecutionResult::Reverted { reason } => { - Ok(SettlementVerificationStatus::Rejected(format!("Tx {} has been reverted: {}", tx_hash, reason))) - } - }, - MaybePendingTransactionReceipt::PendingReceipt(tx) => match tx.execution_result() { - ExecutionResult::Succeeded => Ok(SettlementVerificationStatus::Pending), - ExecutionResult::Reverted { reason } => Ok(SettlementVerificationStatus::Rejected(format!( + let execution_result = tx_receipt.receipt.execution_result(); + let status = execution_result.status(); + + match tx_receipt.block.is_pending() { + true => match status { + TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Pending), + TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( "Pending tx {} has been reverted: {}", - tx_hash, reason + tx_hash, + execution_result.revert_reason().unwrap() + ))), + }, + false => match status { + TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Verified), + TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( + "Tx {} has been reverted: {}", + tx_hash, + execution_result.revert_reason().unwrap() ))), }, } @@ -164,10 +170,10 @@ impl SettlementClient for StarknetSettlementClient { let duration_to_wait_between_polling = Duration::from_secs(self.tx_finality_retry_delay_in_seconds); sleep(duration_to_wait_between_polling).await; - let tx_hash = FieldElement::from_hex_be(tx_hash)?; + let tx_hash = Felt::from_hex(tx_hash)?; loop { let tx_receipt = self.account.provider().get_transaction_receipt(tx_hash).await?; - if let MaybePendingTransactionReceipt::PendingReceipt(_) = tx_receipt { + if tx_receipt.block.is_pending() { retries += 1; if retries > MAX_RETRIES_VERIFY_TX_FINALITY { return Err(eyre!("Max retries exceeeded while waiting for tx {tx_hash} finality.")); @@ -197,7 +203,8 @@ impl SettlementClient for StarknetSettlementClient { if block_number.is_empty() { return Err(eyre!("Could not fetch last block number from core contract.")); } - Ok(block_number[0].try_into()?) + + Ok(u64::from_le_bytes(block_number[0].to_bytes_le()[0..8].try_into().unwrap())) } /// Returns the nonce for the wallet in use. From 827fed49f6e4051399a6bcb830f7fc56c68f3c56 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 17 Sep 2024 12:00:02 +0530 Subject: [PATCH 002/104] update imports --- e2e-tests/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 54314c5a..15382eee 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -13,11 +13,11 @@ use orchestrator::queue::job_queue::WorkerTriggerType; use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; -use starknet::core::types::{FieldElement, MaybePendingStateUpdate}; +use starknet::core::types::{Felt, MaybePendingStateUpdate}; use std::collections::HashMap; use std::fs::{read, File}; use std::io::Read; -use std::str::FromStr; +// use std::str::FromStr; use std::time::{Duration, Instant}; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -327,7 +327,7 @@ pub async fn mock_starknet_get_nonce(starknet_client: &mut StarknetClient, l2_bl let vec: Vec = serde_json::from_str(&contents).unwrap(); for ele in vec { - let address = FieldElement::from_str(&ele.address).unwrap(); + let address = Felt::from_hex(&ele.address).unwrap(); let hex_field_element = vec_u8_to_hex_string(&address.to_bytes_be()); let response = json!({ "id": 640641,"jsonrpc":"2.0","result": ele.nonce }); From c2e9bf1f38836993d030a2f682c5539807cbef92 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 17 Sep 2024 12:30:36 +0530 Subject: [PATCH 003/104] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 308df458..da15ad66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Changed +- Bumped dependencies, and associated api changes done - ethereum DA client builder - AWS config built from TestConfigBuilder. - Better TestConfigBuilder, with sync config clients. From 47b7c6483a695b546967ba4a31135c36038d27b1 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 17 Sep 2024 13:35:37 +0530 Subject: [PATCH 004/104] added testcase for bytes conversion --- crates/settlement-clients/starknet/src/lib.rs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 42b8e74d..ba418eef 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -133,23 +133,24 @@ impl SettlementClient for StarknetSettlementClient { let execution_result = tx_receipt.receipt.execution_result(); let status = execution_result.status(); - match tx_receipt.block.is_pending() { - true => match status { + if tx_receipt.block.is_pending() { + match status { TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Pending), TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( "Pending tx {} has been reverted: {}", tx_hash, execution_result.revert_reason().unwrap() ))), - }, - false => match status { + } + } else { + match status { TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Verified), TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( "Tx {} has been reverted: {}", tx_hash, execution_result.revert_reason().unwrap() ))), - }, + } } } @@ -212,3 +213,18 @@ impl SettlementClient for StarknetSettlementClient { todo!("Yet to impl nonce call for Starknet.") } } + +#[cfg(test)] +mod tests { + use std::u64; + + use starknet::core::types::Felt; + #[test] + fn test_felt_conversion() { + let number_in_felt = Felt::from_hex("0x8").unwrap(); + let number_final = u64::from_le_bytes(number_in_felt.to_bytes_le()[0..8].try_into().unwrap()); + println!("{number_in_felt} {number_final}"); + + assert!(number_final == 8, "Should be 8"); + } +} From 35a02cadb12d0f86e635ee76a7683c9c18237d85 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 17 Sep 2024 13:50:13 +0530 Subject: [PATCH 005/104] fix clippy error --- crates/settlement-clients/starknet/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index ba418eef..1429eb8f 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -216,7 +216,6 @@ impl SettlementClient for StarknetSettlementClient { #[cfg(test)] mod tests { - use std::u64; use starknet::core::types::Felt; #[test] From 1fefb1217cbd78dacc1a00073ee1fa365b459c07 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Wed, 18 Sep 2024 11:53:01 +0530 Subject: [PATCH 006/104] use zaun for starknet --- Cargo.lock | 43 +++++++++++++++++ Cargo.toml | 2 + crates/settlement-clients/starknet/Cargo.toml | 1 + crates/settlement-clients/starknet/src/lib.rs | 46 +++++++++---------- e2e-tests/tests.rs | 5 +- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87fb231b..f6ea40ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1090,6 +1090,48 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "appchain-core-contract-client" +version = "0.1.0" +source = "git+https://github.com/byteZorvin/zaun?branch=type-update#fdfc6d4376f680a000fb0bd4b17a85207ad5fefd" +dependencies = [ + "appchain-utils", + "async-trait", + "color-eyre", + "dirs", + "hex", + "log", + "num-traits 0.2.19", + "serde_json", + "starknet", + "starknet-accounts", + "starknet-core 0.11.1", + "starknet-ff", + "starknet-providers", +] + +[[package]] +name = "appchain-utils" +version = "0.1.0" +source = "git+https://github.com/byteZorvin/zaun?branch=type-update#fdfc6d4376f680a000fb0bd4b17a85207ad5fefd" +dependencies = [ + "async-trait", + "color-eyre", + "hex", + "log", + "num-traits 0.2.19", + "serde_json", + "starknet", + "starknet-accounts", + "starknet-contract", + "starknet-core 0.11.1", + "starknet-ff", + "starknet-providers", + "starknet-signers", + "thiserror", + "url", +] + [[package]] name = "ark-ec" version = "0.4.2" @@ -8969,6 +9011,7 @@ dependencies = [ name = "starknet-settlement-client" version = "0.1.0" dependencies = [ + "appchain-core-contract-client", "async-trait", "c-kzg", "color-eyre", diff --git a/Cargo.toml b/Cargo.toml index 84b73151..c3a75cc7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ hex = "0.4" itertools = "0.13.0" mockall = "0.13.0" testcontainers = "0.18.0" +appchain-core-contract-client = { git = "https://github.com/byteZorvin/zaun", branch = "type-update" } # Cairo VM cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [ @@ -89,6 +90,7 @@ cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [ # TODO: update back to the main repo once it's merged # Sharp (Starkware) snos = { git = "https://github.com/keep-starknet-strange/snos" } +starknet-os = { git = "https://github.com/keep-starknet-strange/snos" } # Madara prover API madara-prover-common = { git = "https://github.com/Moonsong-Labs/madara-prover-api", branch = "od/use-latest-cairo-vm" } diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index 47e01149..bb6c1f71 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -17,6 +17,7 @@ starknet = { workspace = true } tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } +appchain-core-contract-client = { workspace = true } [dev-dependencies] tokio-test = "*" diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 42b8e74d..8a735d2c 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -3,6 +3,7 @@ pub mod conversion; use std::sync::Arc; +use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; use color_eyre::eyre::{eyre, Ok}; use color_eyre::Result; @@ -12,7 +13,7 @@ use starknet::accounts::ConnectedAccount; use starknet::core::types::TransactionExecutionStatus; use starknet::providers::Provider; use starknet::{ - accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount}, + accounts::{ExecutionEncoding, SingleOwnerAccount}, core::{ types::{BlockId, BlockTag, Felt, FunctionCall}, utils::get_selector_from_name, @@ -22,6 +23,7 @@ use starknet::{ }; use tokio::time::{sleep, Duration}; +use appchain_core_contract_client::clients::StarknetCoreContractClient; use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus}; use utils::settings::Settings; @@ -29,7 +31,8 @@ use crate::config::StarknetSettlementConfig; use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field}; pub struct StarknetSettlementClient { - pub account: SingleOwnerAccount>, LocalWallet>, + pub account: Arc>, LocalWallet>>, + pub starknet_core_contract_client: StarknetCoreContractClient, pub core_contract_address: Felt, pub tx_finality_retry_delay_in_seconds: u64, } @@ -45,7 +48,8 @@ const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; impl StarknetSettlementClient { pub async fn new_with_settings(settings: &impl Settings) -> Self { let settlement_cfg = StarknetSettlementConfig::new_with_settings(settings); - let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.rpc_url))); + let provider: Arc> = + Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.rpc_url.clone()))); let public_key = settings.get_settings_or_panic(ENV_PUBLIC_KEY); let signer_address = Felt::from_hex(&public_key).expect("invalid signer address"); @@ -58,17 +62,22 @@ impl StarknetSettlementClient { let core_contract_address = Felt::from_hex(&settlement_cfg.core_contract_address).expect("Invalid core contract address"); - let account = SingleOwnerAccount::new( - provider.clone(), - signer, - signer_address, - provider.chain_id().await.unwrap(), - ExecutionEncoding::Legacy, - ); + let account: Arc>, LocalWallet>> = + Arc::new(SingleOwnerAccount::new( + provider.clone(), + signer.clone(), + signer_address, + provider.chain_id().await.unwrap(), + ExecutionEncoding::Legacy, + )); + + let starknet_core_contract_client: StarknetCoreContractClient = + StarknetCoreContractClient::new(core_contract_address, account.clone()); StarknetSettlementClient { account, core_contract_address, + starknet_core_contract_client, tx_finality_retry_delay_in_seconds: settlement_cfg.tx_finality_retry_delay_in_seconds, } } @@ -110,19 +119,10 @@ impl SettlementClient for StarknetSettlementClient { ) -> Result { let program_output = slice_slice_u8_to_vec_field(program_output.as_slice()); let onchain_data_hash = slice_u8_to_field(&onchain_data_hash); - let mut calldata: Vec = Vec::with_capacity(program_output.len() + 2); - calldata.extend(program_output); - calldata.push(onchain_data_hash); - calldata.push(Felt::from(onchain_data_size)); - let invoke_result = self - .account - .execute_v1(vec![Call { - to: self.core_contract_address, - selector: *CONTRACT_WRITE_UPDATE_STATE_SELECTOR, - calldata, - }]) - .send() - .await?; + let onchain_data_size = Felt::from(onchain_data_size); + let core_contract: &CoreContract = self.starknet_core_contract_client.as_ref(); + let invoke_result = core_contract.update_state(program_output, onchain_data_hash, onchain_data_size).await?; + Ok(format!("0x{:x}", invoke_result.transaction_hash)) } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 54314c5a..3c4f198b 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -13,11 +13,10 @@ use orchestrator::queue::job_queue::WorkerTriggerType; use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; -use starknet::core::types::{FieldElement, MaybePendingStateUpdate}; +use starknet::core::types::{Felt, MaybePendingStateUpdate}; use std::collections::HashMap; use std::fs::{read, File}; use std::io::Read; -use std::str::FromStr; use std::time::{Duration, Instant}; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -327,7 +326,7 @@ pub async fn mock_starknet_get_nonce(starknet_client: &mut StarknetClient, l2_bl let vec: Vec = serde_json::from_str(&contents).unwrap(); for ele in vec { - let address = FieldElement::from_str(&ele.address).unwrap(); + let address = Felt::from_hex(&ele.address).unwrap(); let hex_field_element = vec_u8_to_hex_string(&address.to_bytes_be()); let response = json!({ "id": 640641,"jsonrpc":"2.0","result": ele.nonce }); From c674a6acb2339be0e68389fe9b8f391f4d04216a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 26 Sep 2024 12:12:21 +0530 Subject: [PATCH 007/104] add simple test for settlement --- .env.test | 8 +- .gitignore | 4 +- Cargo.lock | 152 +++++----- Cargo.toml | 2 +- .../da-clients/da-client-interface/src/lib.rs | 8 - .../starknet/.tool-versions | 2 + crates/settlement-clients/starknet/Cargo.toml | 6 + .../settlement-clients/starknet/src/config.rs | 4 +- crates/settlement-clients/starknet/src/lib.rs | 4 +- .../src/tests/mock_contracts/.gitignore | 2 + .../src/tests/mock_contracts/Scarb.lock | 22 ++ .../src/tests/mock_contracts/Scarb.toml | 19 ++ .../src/tests/mock_contracts/src/lib.cairo | 17 ++ .../starknet/src/tests/mod.rs | 259 ++++++++++++++++++ .../starknet/src/tests/test.rs | 178 ++++++++++++ docker-compose.yml | 16 ++ 16 files changed, 620 insertions(+), 83 deletions(-) create mode 100644 crates/settlement-clients/starknet/.tool-versions create mode 100644 crates/settlement-clients/starknet/src/tests/mock_contracts/.gitignore create mode 100644 crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.lock create mode 100644 crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.toml create mode 100644 crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo create mode 100644 crates/settlement-clients/starknet/src/tests/mod.rs create mode 100644 crates/settlement-clients/starknet/src/tests/test.rs create mode 100644 docker-compose.yml diff --git a/.env.test b/.env.test index c51cf932..bfe23b85 100644 --- a/.env.test +++ b/.env.test @@ -61,4 +61,10 @@ STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C DEFAULT_L1_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4" TEST_DUMMY_CONTRACT_ADDRESS="0xE5b6F5e695BA6E4aeD92B68c4CC8Df1160D69A81" STARKNET_OPERATOR_ADDRESS="0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7" -ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" \ No newline at end of file +ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" + + +##### STARKNET SETTLEMENT TEST ##### +STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 +ACCOUNT_CONTRACT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 +STARKNET_RPC_URL=http://localhost:9944 diff --git a/.gitignore b/.gitignore index 12b6524c..b296e1f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,9 @@ *.code-workspace .vscode +db/ + lcov.info -**/*-SN.zip \ No newline at end of file +**/*-SN.zip diff --git a/Cargo.lock b/Cargo.lock index f6ea40ad..02b12d80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1086,9 +1086,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "appchain-core-contract-client" @@ -1532,19 +1532,21 @@ dependencies = [ [[package]] name = "async-process" -version = "1.8.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" +checksum = "63255f1dc2381611000436537bbedfe83183faa303a5a0edaf191edef06526bb" dependencies = [ - "async-io 1.13.0", - "async-lock 2.8.0", + "async-channel 2.3.1", + "async-io 2.3.3", + "async-lock 3.4.0", "async-signal", + "async-task", "blocking", "cfg-if", - "event-listener 3.1.0", - "futures-lite 1.13.0", + "event-listener 5.3.1", + "futures-lite 2.3.0", "rustix 0.38.34", - "windows-sys 0.48.0", + "tracing", ] [[package]] @@ -1579,21 +1581,21 @@ dependencies = [ [[package]] name = "async-std" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +checksum = "c634475f29802fde2b8f0b505b1bd00dfe4df7d4a000f0b36f7671197d5c3615" dependencies = [ "async-attributes", "async-channel 1.9.0", "async-global-executor", - "async-io 1.13.0", - "async-lock 2.8.0", + "async-io 2.3.3", + "async-lock 3.4.0", "async-process", "crossbeam-utils", "futures-channel", "futures-core", "futures-io", - "futures-lite 1.13.0", + "futures-lite 2.3.0", "gloo-timers", "kv-log-macro", "log", @@ -2588,7 +2590,7 @@ checksum = "709d9aa1c37abb89d40f19f5d0ad6f0d88cb1581264e571c9350fc5bb89cf1c5" dependencies = [ "serde", "serde_repr", - "serde_with 3.8.1", + "serde_with 3.9.0", ] [[package]] @@ -4157,9 +4159,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -4284,17 +4286,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "event-listener" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - [[package]] name = "event-listener" version = "5.3.1" @@ -4676,9 +4667,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gloo-timers" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" dependencies = [ "futures-channel", "futures-core", @@ -6709,7 +6700,7 @@ dependencies = [ "rand", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with 3.9.0", "sha3", "thiserror", "vergen", @@ -6738,7 +6729,7 @@ dependencies = [ "primitive-types", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with 3.9.0", ] [[package]] @@ -8369,9 +8360,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" dependencies = [ "base64 0.22.1", "chrono", @@ -8381,7 +8372,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "serde_with_macros 3.8.1", + "serde_with_macros 3.9.0", "time", ] @@ -8411,9 +8402,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" dependencies = [ "darling 0.20.9", "proc-macro2", @@ -8671,7 +8662,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with 3.9.0", "serde_yaml", "starknet-crypto 0.6.2", "starknet-gateway-types", @@ -8757,7 +8748,7 @@ dependencies = [ "starknet-accounts", "starknet-contract", "starknet-core 0.11.1", - "starknet-crypto 0.7.1", + "starknet-crypto 0.7.2", "starknet-macros", "starknet-providers", "starknet-signers", @@ -8772,7 +8763,7 @@ dependencies = [ "async-trait", "auto_impl", "starknet-core 0.11.1", - "starknet-crypto 0.7.1", + "starknet-crypto 0.7.2", "starknet-providers", "starknet-signers", "thiserror", @@ -8826,7 +8817,26 @@ dependencies = [ "serde_json_pythonic", "serde_with 2.3.3", "sha3", - "starknet-crypto 0.7.1", + "starknet-crypto 0.7.2", + "starknet-types-core", +] + +[[package]] +name = "starknet-core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538240cbe6663c673fe77465f294da707080f39678dd7066761554899e46100" +dependencies = [ + "base64 0.21.7", + "crypto-bigint 0.5.5", + "flate2", + "hex", + "serde", + "serde_json", + "serde_json_pythonic", + "serde_with 3.9.0", + "sha3", + "starknet-crypto 0.7.2", "starknet-types-core", ] @@ -8844,7 +8854,7 @@ dependencies = [ "num-traits 0.2.19", "rfc6979 0.4.0", "sha2", - "starknet-crypto-codegen 0.3.3", + "starknet-crypto-codegen", "starknet-curve 0.3.0", "starknet-ff", "zeroize", @@ -8864,7 +8874,7 @@ dependencies = [ "num-traits 0.2.19", "rfc6979 0.4.0", "sha2", - "starknet-crypto-codegen 0.3.3", + "starknet-crypto-codegen", "starknet-curve 0.4.2", "starknet-ff", "zeroize", @@ -8872,9 +8882,9 @@ dependencies = [ [[package]] name = "starknet-crypto" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2a821ad8d98c6c3e4d0e5097f3fe6e2ed120ada9d32be87cd1330c7923a2f0" +checksum = "60a5064173a8e8d2675e67744fd07f310de44573924b6b7af225a6bdd8102913" dependencies = [ "crypto-bigint 0.5.5", "hex", @@ -8884,8 +8894,7 @@ dependencies = [ "num-traits 0.2.19", "rfc6979 0.4.0", "sha2", - "starknet-crypto-codegen 0.4.0", - "starknet-curve 0.5.0", + "starknet-curve 0.5.1", "starknet-types-core", "zeroize", ] @@ -8901,17 +8910,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "starknet-crypto-codegen" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" -dependencies = [ - "starknet-curve 0.5.0", - "starknet-types-core", - "syn 2.0.66", -] - [[package]] name = "starknet-curve" version = "0.3.0" @@ -8932,9 +8930,9 @@ dependencies = [ [[package]] name = "starknet-curve" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56935b306dcf0b8f14bb2a1257164b8478bb8be4801dfae0923f5b266d1b457c" +checksum = "bcde6bd74269b8161948190ace6cf069ef20ac6e79cd2ba09b320efa7500b6de" dependencies = [ "starknet-types-core", ] @@ -8970,7 +8968,7 @@ dependencies = [ "rstest 0.18.2", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with 3.9.0", "sha3", "thiserror", "tokio", @@ -8978,11 +8976,11 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fe4f8d615329410578cbedcdbaa4a36c7f28f68c3f3ac56006cfbdaeaa2b41" +checksum = "8986a940af916fc0a034f4e42c6ba76d94f1e97216d75447693dfd7aefaf3ef2" dependencies = [ - "starknet-core 0.11.1", + "starknet-core 0.12.0", "syn 2.0.66", ] @@ -9011,17 +9009,23 @@ dependencies = [ name = "starknet-settlement-client" version = "0.1.0" dependencies = [ + "anyhow", "appchain-core-contract-client", + "async-std", "async-trait", "c-kzg", "color-eyre", + "dotenvy", + "env_logger", "lazy_static", "mockall", "reqwest 0.12.7", "rstest 0.22.0", "serde", + "serde_json", "settlement-client-interface", "starknet", + "tempfile", "tokio", "tokio-test", "url", @@ -9041,7 +9045,7 @@ dependencies = [ "getrandom", "rand", "starknet-core 0.11.1", - "starknet-crypto 0.7.1", + "starknet-crypto 0.7.2", "thiserror", ] @@ -9343,14 +9347,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand 2.1.0", + "once_cell", "rustix 0.38.34", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -9390,7 +9395,7 @@ dependencies = [ "reqwest 0.12.7", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with 3.9.0", "thiserror", "tokio", "tokio-stream", @@ -10363,6 +10368,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index c3a75cc7..b2136a05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ rstest = "0.22.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" starknet = "0.11.0" -tempfile = "3.8.1" +tempfile = "3.12.0" thiserror = "1.0.57" tokio = { version = "1.37.0" } tokio-stream = "0.1.15" diff --git a/crates/da-clients/da-client-interface/src/lib.rs b/crates/da-clients/da-client-interface/src/lib.rs index f6158e17..572af75f 100644 --- a/crates/da-clients/da-client-interface/src/lib.rs +++ b/crates/da-clients/da-client-interface/src/lib.rs @@ -27,11 +27,3 @@ pub trait DaClient: Send + Sync { /// Should return the max bytes per blob async fn max_bytes_per_blob(&self) -> u64; } - -/// Trait for every new DaConfig to implement -#[async_trait] -pub trait DaConfig { - /// Should create a new instance of the DaConfig from the environment variables - fn new_from_env() -> Self; - async fn build_client(&self) -> T; -} diff --git a/crates/settlement-clients/starknet/.tool-versions b/crates/settlement-clients/starknet/.tool-versions new file mode 100644 index 00000000..fca91f1c --- /dev/null +++ b/crates/settlement-clients/starknet/.tool-versions @@ -0,0 +1,2 @@ +starknet-foundry 0.30.0 +scarb 2.8.2 diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index bb6c1f71..d0a40cb0 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -18,6 +18,12 @@ tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } appchain-core-contract-client = { workspace = true } +tempfile.workspace = true +anyhow = "1.0.89" +env_logger = "0.11.5" +dotenvy.workspace = true [dev-dependencies] +async-std = { version = "1.13.0", features = ["attributes"] } +serde_json.workspace = true tokio-test = "*" diff --git a/crates/settlement-clients/starknet/src/config.rs b/crates/settlement-clients/starknet/src/config.rs index 3f3eb146..88e51d9e 100644 --- a/crates/settlement-clients/starknet/src/config.rs +++ b/crates/settlement-clients/starknet/src/config.rs @@ -19,9 +19,9 @@ pub struct StarknetSettlementConfig { pub tx_finality_retry_delay_in_seconds: u64, } -impl SettlementConfig for StarknetSettlementConfig { +impl StarknetSettlementConfig { /// Should create a new instance of the DaConfig from the environment variables - fn new_with_settings(settings: &impl Settings) -> Self { + pub fn new_with_settings(settings: &impl Settings) -> Self { let rpc_url = settings.get_settings_or_panic(ENV_STARKNET_RPC_URL); let rpc_url = Url::from_str(&rpc_url).unwrap_or_else(|_| panic!("Failed to parse {}", ENV_STARKNET_RPC_URL)); let core_contract_address = settings.get_settings_or_panic(ENV_CORE_CONTRACT_ADDRESS); diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 7009a011..395d78e0 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -1,5 +1,7 @@ pub mod config; pub mod conversion; +#[cfg(test)] +pub mod tests; use std::sync::Arc; @@ -215,7 +217,7 @@ impl SettlementClient for StarknetSettlementClient { } #[cfg(test)] -mod tests { +mod test { use starknet::core::types::Felt; #[test] diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/.gitignore b/crates/settlement-clients/starknet/src/tests/mock_contracts/.gitignore new file mode 100644 index 00000000..73aa31e6 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/.gitignore @@ -0,0 +1,2 @@ +target +.snfoundry_cache/ diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.lock b/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.lock new file mode 100644 index 00000000..8b9d4818 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.lock @@ -0,0 +1,22 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "mock_contracts" +version = "0.1.0" +dependencies = [ + "snforge_std", +] + +[[package]] +name = "snforge_scarb_plugin" +version = "0.1.0" +source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496" + +[[package]] +name = "snforge_std" +version = "0.30.0" +source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496" +dependencies = [ + "snforge_scarb_plugin", +] diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.toml b/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.toml new file mode 100644 index 00000000..d02816bb --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/Scarb.toml @@ -0,0 +1,19 @@ +[package] +name = "mock_contracts" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet = "2.8.2" + +[dev-dependencies] +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.30.0" } + +[[target.starknet-contract]] +sierra = true +casm = true + +[scripts] +test = "snforge test" diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo new file mode 100644 index 00000000..c89eeed2 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo @@ -0,0 +1,17 @@ +#[starknet::interface] +pub trait IPiltover { + fn update_state(self: @TContractState); +} + +#[starknet::contract] +mod Piltover { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl IPiltoverImpl of super::IPiltover { + fn update_state(self: @ContractState) {} + } +} diff --git a/crates/settlement-clients/starknet/src/tests/mod.rs b/crates/settlement-clients/starknet/src/tests/mod.rs new file mode 100644 index 00000000..35e469a2 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/mod.rs @@ -0,0 +1,259 @@ +mod test; + +use anyhow::bail; +use rstest::rstest; +use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, Url}; +use std::ops::Range; +use std::sync::Mutex; +use std::{ + collections::HashMap, + future::Future, + path::{Path, PathBuf}, + process::{Child, Command, Output, Stdio}, + str::FromStr, + time::Duration, +}; +use tempfile::TempDir; + +pub struct MadaraCmd { + process: Option, + ready: bool, + json_rpc: Option>, + rpc_url: Url, + tempdir: TempDir, + _port: MadaraPortNum, +} + +async fn wait_for_cond>>(mut cond: impl FnMut() -> F, duration: Duration) { + let mut attempt = 0; + loop { + let Err(err) = cond().await else { + break; + }; + + attempt += 1; + if attempt >= 10 { + panic!("No answer from the node after {attempt} attempts: {:#}", err) + } + + tokio::time::sleep(duration).await; + } +} + +impl MadaraCmd { + pub fn wait_with_output(mut self) -> Output { + self.process.take().unwrap().wait_with_output().unwrap() + } + + pub fn json_rpc(&mut self) -> &JsonRpcClient { + self.json_rpc.get_or_insert_with(|| JsonRpcClient::new(HttpTransport::new(self.rpc_url.clone()))) + } + + pub fn db_dir(&self) -> &Path { + self.tempdir.path() + } + + pub async fn wait_for_ready(&mut self) -> &mut Self { + let endpoint = self.rpc_url.join("/health").unwrap(); + wait_for_cond( + || async { + let res = reqwest::get(endpoint.clone()).await?; + res.error_for_status()?; + anyhow::Ok(()) + }, + Duration::from_millis(1000), + ) + .await; + self.ready = true; + self + } + + pub async fn wait_for_sync_to(&mut self, block_n: u64) -> &mut Self { + let rpc = self.json_rpc(); + wait_for_cond( + || async { + match rpc.block_hash_and_number().await { + Ok(got) => { + if got.block_number < block_n { + bail!("got block_n {}, expected {block_n}", got.block_number); + } + anyhow::Ok(()) + } + Err(err) => bail!(err), + } + }, + Duration::from_millis(5000), + ) + .await; + self + } +} + +impl Drop for MadaraCmd { + fn drop(&mut self) { + let Some(mut child) = self.process.take() else { return }; + let kill = || { + let mut kill = Command::new("kill").args(["-s", "TERM", &child.id().to_string()]).spawn()?; + kill.wait()?; + anyhow::Ok(()) + }; + if let Err(_err) = kill() { + child.kill().unwrap() + } + child.wait().unwrap(); + } +} + +// this really should use unix sockets, sad + +const PORT_RANGE: Range = 19944..20000; + +struct AvailablePorts> { + to_reuse: Vec, + next: I, +} + +lazy_static::lazy_static! { + static ref AVAILABLE_PORTS: Mutex>> = Mutex::new(AvailablePorts { to_reuse: vec![], next: PORT_RANGE }); +} + +pub struct MadaraPortNum(pub u16); +impl Drop for MadaraPortNum { + fn drop(&mut self) { + let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); + guard.to_reuse.push(self.0); + } +} + +pub fn get_port() -> MadaraPortNum { + let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); + if let Some(el) = guard.to_reuse.pop() { + return MadaraPortNum(el); + } + MadaraPortNum(guard.next.next().expect("no more port to use")) +} + +pub struct MadaraCmdBuilder { + args: Vec, + env: HashMap, + tempdir: TempDir, + port: MadaraPortNum, +} + +impl Default for MadaraCmdBuilder { + fn default() -> Self { + Self::new() + } +} + +impl MadaraCmdBuilder { + pub fn new() -> Self { + Self { + args: Default::default(), + env: Default::default(), + tempdir: TempDir::with_prefix("madara-test").unwrap(), + port: get_port(), + } + } + + pub fn args(mut self, args: impl IntoIterator>) -> Self { + self.args = args.into_iter().map(Into::into).collect(); + self + } + + pub fn env(mut self, env: impl IntoIterator, impl Into)>) -> Self { + self.env = env.into_iter().map(|(k, v)| (k.into(), v.into())).collect(); + self + } + + pub fn run(self) -> MadaraCmd { + let target_bin = option_env!("COVERAGE_BIN").unwrap_or("./target/debug/madara"); + let target_bin = PathBuf::from_str(target_bin).expect("target bin is not a path"); + if !target_bin.exists() { + panic!("No binary to run: {:?}", target_bin) + } + + let process = Command::new(target_bin) + .envs(self.env) + .args(self.args.into_iter().chain([ + "--telemetry-disabled".into(), // important: disable telemetry!! + "--no-prometheus".into(), + "--base-path".into(), + format!("{}", self.tempdir.as_ref().display()), + "--rpc-port".into(), + format!("{}", self.port.0), + ])) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + + MadaraCmd { + process: Some(process), + ready: false, + json_rpc: None, + rpc_url: Url::parse(&format!("http://127.0.0.1:{}/", self.port.0)).unwrap(), + tempdir: self.tempdir, + _port: self.port, + } + } +} + +use rstest::fixture; +use std::env; + +#[fixture] +pub fn set_workdir() { + env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/")) + .expect("Failed to set working directory"); + let output = std::process::Command::new("cargo") + .arg("locate-project") + .arg("--workspace") + .arg("--message-format=plain") + .output() + .expect("Failed to execute command"); + + let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); + let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); + + env::set_current_dir(&project_root).expect("Failed to set working directory"); +} + +#[rstest] +fn madara_help_shows(_set_workdir: ()) { + let _ = env_logger::builder().is_test(true).try_init(); + let output = MadaraCmdBuilder::new().args(["--help"]).run().wait_with_output(); + assert!(output.status.success()); + + let stdout = String::from_utf8(output.stdout).unwrap(); + assert!(stdout.contains("Madara: High performance Starknet sequencer/full-node"), "stdout: {stdout}"); +} + +#[rstest] +#[tokio::test] +async fn madara_can_sync_a_few_blocks(_set_workdir: ()) { + use starknet::core::types::{BlockHashAndNumber, Felt}; + + let _ = env_logger::builder().is_test(true).try_init(); + let mut node = MadaraCmdBuilder::new() + .args([ + "--network", + "sepolia", + "--no-sync-polling", + "--n-blocks-to-sync", + "20", + "--no-l1-sync", + "--preset=sepolia", + ]) + .run(); + node.wait_for_ready().await; + node.wait_for_sync_to(19).await; + + assert_eq!( + node.json_rpc().block_hash_and_number().await.unwrap(), + BlockHashAndNumber { + // https://sepolia.voyager.online/block/19 + block_hash: Felt::from_hex_unchecked("0x4177d1ba942a4ab94f86a476c06f0f9e02363ad410cdf177c54064788c9bcb5"), + block_number: 19 + } + ); +} diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs new file mode 100644 index 00000000..a38ce5c1 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -0,0 +1,178 @@ +use super::{MadaraCmd, MadaraCmdBuilder}; +use crate::StarknetSettlementClient; +use rstest::{fixture, rstest}; +use settlement_client_interface::SettlementClient; +use starknet::{ + accounts::{Account, ExecutionEncoding, SingleOwnerAccount}, + contract::ContractFactory, + core::types::{ + contract::{CompiledClass, SierraClass}, + BlockId, BlockTag, Felt, + }, + macros::felt, + providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Url, + }, + signers::{LocalWallet, SigningKey}, +}; +use std::env; +use std::path::PathBuf; +use std::sync::Arc; +use utils::settings::env::EnvSettingsProvider; +use utils::settings::Settings; + +pub async fn spin_up_madara() -> MadaraCmd { + env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/")) + .expect("Failed to set working directory"); + let output = std::process::Command::new("cargo") + .arg("locate-project") + .arg("--workspace") + .arg("--message-format=plain") + .output() + .expect("Failed to execute command"); + + let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); + let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); + + env::set_current_dir(&project_root).expect("Failed to set working directory"); + + let _ = env_logger::builder().is_test(true).try_init(); + let mut node = MadaraCmdBuilder::new() + .args([ + "--network", + "devnet", + "--no-sync-polling", + "--n-blocks-to-sync", + "20", + "--authority", + "--devnet", + "--preset=test", + "--no-l1-sync", + ]) + .run(); + node.wait_for_ready().await; + node +} + +// #[fixture] +// async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { +#[fixture] +async fn setup() -> SingleOwnerAccount, LocalWallet> { + // let madara_process = spin_up_madara().await; + // println!("RPC url {:?}", madara_process.rpc_url); + + let env_settings = EnvSettingsProvider::default(); + let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); + + // let provider = JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:9944").unwrap())); + let provider = JsonRpcClient::new(HttpTransport::new(rpc_url)); + let signer = LocalWallet::from(SigningKey::from_secret_scalar( + Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).unwrap(), + )); + let address = Felt::from_hex(&env_settings.get_settings_or_panic("ACCOUNT_CONTRACT_ADDRESS")).unwrap(); + + let mut account = SingleOwnerAccount::new( + provider, + signer, + address, + Felt::from_hex("0x4d41444152415f54455354").unwrap(), // chain id = MADARA_TEST + ExecutionEncoding::New, + ); + + // `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest + // block. Optionally change the target block to pending with the following line: + account.set_block_id(BlockId::Tag(BlockTag::Pending)); + // (account, madara_process) + account +} + +#[rstest] +#[tokio::test] +// async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { +async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { + dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); + // let (account, madara_process) = setup.await; + let account = setup.await; + + // let endpoint = madara_process.rpc_url.join("/health").unwrap(); + let endpoint = Url::parse("http://localhost:9944").unwrap().join("/health").unwrap(); + let response = reqwest::get(endpoint.clone()).await.unwrap(); + println!("Response from health: {:?}", response); + + // println!("the db being used is {:?}", madara_process.tempdir); + let account = Arc::new(account); + + // NOTE: you will need to declare this class first + let sierra_class: SierraClass = serde_json::from_reader( + std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.contract_class.json").unwrap(), + ) + .unwrap(); + + let compiled_class: CompiledClass = serde_json::from_reader( + std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.compiled_contract_class.json").unwrap(), + ) + .unwrap(); + + let flattened_class = sierra_class.clone().flatten().unwrap(); + let compiled_class_hash = compiled_class.class_hash().unwrap(); + let class_hash = flattened_class.class_hash(); + account.declare_v2(Arc::new(flattened_class), compiled_class_hash).send().await.unwrap(); + + // This done since madara currently does not increment nonce for pending transactions + tokio::time::sleep(tokio::time::Duration::from_secs(4)).await; + + let contract_factory = ContractFactory::new(class_hash, account); + contract_factory + .deploy_v1(vec![felt!("123456")], felt!("1122"), false) + .send() + .await + .expect("Unable to deploy contract"); +} + +#[rstest] +#[tokio::test] +async fn test_settle(#[future] setup: SingleOwnerAccount, LocalWallet>) { + dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); + // let (account, madara_process) = setup.await; + let account = setup.await; + + // let endpoint = madara_process.rpc_url.join("/health").unwrap(); + let endpoint = Url::parse("http://localhost:9944").unwrap().join("/health").unwrap(); + let response = reqwest::get(endpoint.clone()).await.unwrap(); + println!("Response from health: {:?}", response); + + // println!("the db being used is {:?}", madara_process.tempdir); + let account = Arc::new(account); + + // NOTE: you will need to declare this class first + let sierra_class: SierraClass = serde_json::from_reader( + std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.contract_class.json").unwrap(), + ) + .unwrap(); + + let compiled_class: CompiledClass = serde_json::from_reader( + std::fs::File::open("/Users/bytezorvin/work/karnot/madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.compiled_contract_class.json").unwrap(), + ) + .unwrap(); + + let flattened_class = sierra_class.clone().flatten().unwrap(); + let compiled_class_hash = compiled_class.class_hash().unwrap(); + let class_hash = flattened_class.class_hash(); + account.declare_v2(Arc::new(flattened_class), compiled_class_hash).send().await.unwrap(); + + // This done since madara currently does not increment nonce for pending transactions + tokio::time::sleep(tokio::time::Duration::from_secs(4)).await; + + let contract_factory = ContractFactory::new(class_hash, account); + contract_factory + .deploy_v1(vec![felt!("123456")], felt!("1122"), false) + .send() + .await + .expect("Unable to deploy contract"); + + let env_settings = EnvSettingsProvider {}; + let settlement_client = StarknetSettlementClient::new_with_settings(&env_settings).await; + let onchain_data_hash = [0; 32]; + settlement_client.update_state_calldata(vec![], onchain_data_hash, 1).await.unwrap(); +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e2c4df03 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + localstack: + image: localstack/localstack + container_name: localstack + environment: + - DEFAULT_REGION=us-east-1 + - AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID + - AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY + ports: + - "4566:4566" + + mongodb: + image: mongo:latest + container_name: mongodb + ports: + - "27017:27017" From a5a6e18bd213bfa0e2c4e0ad7644acd93ea35b9e Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 26 Sep 2024 15:36:38 +0530 Subject: [PATCH 008/104] add sepolia issue --- .env.test | 2 +- .../settlement-clients/ethereum/src/config.rs | 5 +- crates/settlement-clients/ethereum/src/lib.rs | 4 +- .../settlement-client-interface/src/lib.rs | 7 --- .../settlement-clients/starknet/src/config.rs | 1 - crates/settlement-clients/starknet/src/lib.rs | 2 +- .../starknet/src/tests/test.rs | 57 +++++++++---------- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/.env.test b/.env.test index bfe23b85..e09d69d4 100644 --- a/.env.test +++ b/.env.test @@ -66,5 +66,5 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" ##### STARKNET SETTLEMENT TEST ##### STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 -ACCOUNT_CONTRACT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 +STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 diff --git a/crates/settlement-clients/ethereum/src/config.rs b/crates/settlement-clients/ethereum/src/config.rs index 89b0dcd5..5cd90b74 100644 --- a/crates/settlement-clients/ethereum/src/config.rs +++ b/crates/settlement-clients/ethereum/src/config.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; -use settlement_client_interface::SettlementConfig; use url::Url; use utils::settings::Settings; @@ -15,8 +14,8 @@ pub struct EthereumSettlementConfig { pub core_contract_address: String, } -impl SettlementConfig for EthereumSettlementConfig { - fn new_with_settings(settings: &impl Settings) -> Self { +impl EthereumSettlementConfig { + pub fn new_with_settings(settings: &impl Settings) -> Self { let rpc_url = settings.get_settings_or_panic(SETTLEMENT_RPC_URL); let rpc_url = Url::from_str(&rpc_url).unwrap_or_else(|_| panic!("Failed to parse {}", SETTLEMENT_RPC_URL)); let core_contract_address = settings.get_settings_or_panic(ENV_CORE_CONTRACT_ADDRESS); diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index fb37cdf8..d8843498 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -27,11 +27,11 @@ use mockall::{automock, predicate::*}; use alloy::providers::ProviderBuilder; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; -#[cfg(feature = "testing")] -use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus}; #[cfg(not(feature = "testing"))] use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus}; #[cfg(feature = "testing")] +use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; +#[cfg(feature = "testing")] use url::Url; use utils::env_utils::get_env_var_or_panic; diff --git a/crates/settlement-clients/settlement-client-interface/src/lib.rs b/crates/settlement-clients/settlement-client-interface/src/lib.rs index afe3d2e7..88ae00d0 100644 --- a/crates/settlement-clients/settlement-client-interface/src/lib.rs +++ b/crates/settlement-clients/settlement-client-interface/src/lib.rs @@ -2,7 +2,6 @@ use async_trait::async_trait; use color_eyre::eyre::Result; use mockall::automock; use mockall::predicate::*; -use utils::settings::Settings; pub const SETTLEMENT_SETTINGS_NAME: &str = "settlement_settings"; @@ -49,9 +48,3 @@ pub trait SettlementClient: Send + Sync { /// Should retrieve the latest transaction count to be used as nonce. async fn get_nonce(&self) -> Result; } - -/// Trait for every new SettlementConfig to implement -pub trait SettlementConfig { - /// Should create a new instance of the SettlementConfig from the environment variables - fn new_with_settings(settings: &impl Settings) -> Self; -} diff --git a/crates/settlement-clients/starknet/src/config.rs b/crates/settlement-clients/starknet/src/config.rs index 88e51d9e..f7f595c9 100644 --- a/crates/settlement-clients/starknet/src/config.rs +++ b/crates/settlement-clients/starknet/src/config.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; -use settlement_client_interface::SettlementConfig; use url::Url; use utils::env_utils::get_env_var_or_default; use utils::settings::Settings; diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 395d78e0..fd6bf6b9 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -26,7 +26,7 @@ use starknet::{ use tokio::time::{sleep, Duration}; use appchain_core_contract_client::clients::StarknetCoreContractClient; -use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus}; +use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; use utils::settings::Settings; use crate::config::StarknetSettlementConfig; diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index a38ce5c1..4cacc425 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -7,13 +7,10 @@ use starknet::{ contract::ContractFactory, core::types::{ contract::{CompiledClass, SierraClass}, - BlockId, BlockTag, Felt, + BlockId, BlockTag, DeclareTransactionResult, Felt, }, macros::felt, - providers::{ - jsonrpc::{HttpTransport, JsonRpcClient}, - Url, - }, + providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, Url}, signers::{LocalWallet, SigningKey}, }; use std::env; @@ -22,6 +19,7 @@ use std::sync::Arc; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; +#[allow(unused)] pub async fn spin_up_madara() -> MadaraCmd { env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/")) .expect("Failed to set working directory"); @@ -61,22 +59,30 @@ pub async fn spin_up_madara() -> MadaraCmd { async fn setup() -> SingleOwnerAccount, LocalWallet> { // let madara_process = spin_up_madara().await; // println!("RPC url {:?}", madara_process.rpc_url); + dotenvy::from_filename_override(".env").expect("Failed to load the .env file"); let env_settings = EnvSettingsProvider::default(); let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); + println!("RPC url {:?}", rpc_url); + // let endpoint = madara_process.rpc_url.join("/health").unwrap(); + // let endpoint = rpc_url.join("/health").unwrap(); + // let response = reqwest::get(endpoint.clone()).await.expect("Failed to connect to Provider"); + // assert!(response.status().is_success(), "Failed to connect to Provider"); // let provider = JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:9944").unwrap())); - let provider = JsonRpcClient::new(HttpTransport::new(rpc_url)); + let provider: JsonRpcClient = JsonRpcClient::new(HttpTransport::new(rpc_url)); let signer = LocalWallet::from(SigningKey::from_secret_scalar( - Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).unwrap(), + Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).expect("Invalid private key"), )); - let address = Felt::from_hex(&env_settings.get_settings_or_panic("ACCOUNT_CONTRACT_ADDRESS")).unwrap(); + let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")).unwrap(); + let chain_id = provider.chain_id().await.unwrap(); + println!("address {:?}", env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")); let mut account = SingleOwnerAccount::new( provider, signer, address, - Felt::from_hex("0x4d41444152415f54455354").unwrap(), // chain id = MADARA_TEST + chain_id, ExecutionEncoding::New, ); @@ -91,15 +97,9 @@ async fn setup() -> SingleOwnerAccount, LocalWallet #[tokio::test] // async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { - dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); // let (account, madara_process) = setup.await; let account = setup.await; - // let endpoint = madara_process.rpc_url.join("/health").unwrap(); - let endpoint = Url::parse("http://localhost:9944").unwrap().join("/health").unwrap(); - let response = reqwest::get(endpoint.clone()).await.unwrap(); - println!("Response from health: {:?}", response); - // println!("the db being used is {:?}", madara_process.tempdir); let account = Arc::new(account); @@ -137,39 +137,36 @@ async fn test_settle(#[future] setup: SingleOwnerAccount Date: Thu, 26 Sep 2024 18:33:09 +0530 Subject: [PATCH 009/104] to be fixed: validation error --- crates/settlement-clients/starknet/src/lib.rs | 2 +- .../src/tests/mock_contracts/src/lib.cairo | 14 +++++- .../starknet/src/tests/test.rs | 45 +++++++++---------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index fd6bf6b9..95cd5485 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -70,7 +70,7 @@ impl StarknetSettlementClient { signer.clone(), signer_address, provider.chain_id().await.unwrap(), - ExecutionEncoding::Legacy, + ExecutionEncoding::New )); let starknet_core_contract_client: StarknetCoreContractClient = diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo index c89eeed2..7f1d1bf2 100644 --- a/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo @@ -1,6 +1,11 @@ #[starknet::interface] pub trait IPiltover { - fn update_state(self: @TContractState); + fn update_state( + ref self: TContractState, + program_output: Span, + onchain_data_hash: felt252, + onchain_data_size: u256 + ); } #[starknet::contract] @@ -12,6 +17,11 @@ mod Piltover { #[abi(embed_v0)] impl IPiltoverImpl of super::IPiltover { - fn update_state(self: @ContractState) {} + fn update_state( + ref self: ContractState, + program_output: Span, + onchain_data_hash: felt252, + onchain_data_size: u256 + ) {} } } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 4cacc425..669974d8 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -77,14 +77,7 @@ async fn setup() -> SingleOwnerAccount, LocalWallet let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")).unwrap(); let chain_id = provider.chain_id().await.unwrap(); - println!("address {:?}", env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")); - let mut account = SingleOwnerAccount::new( - provider, - signer, - address, - chain_id, - ExecutionEncoding::New, - ); + let mut account = SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New); // `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest // block. Optionally change the target block to pending with the following line: @@ -123,11 +116,7 @@ async fn test_deployment(#[future] setup: SingleOwnerAccount Date: Fri, 27 Sep 2024 17:08:04 +0530 Subject: [PATCH 010/104] add madara update state test --- Cargo.lock | 4 +- crates/settlement-clients/ethereum/src/lib.rs | 11 +- .../settlement-client-interface/src/lib.rs | 2 +- crates/settlement-clients/starknet/src/lib.rs | 8 +- .../src/tests/mock_contracts/src/lib.cairo | 13 +- .../starknet/src/tests/mod.rs | 3 +- .../starknet/src/tests/test.rs | 153 +++++++++++++----- 7 files changed, 136 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02b12d80..7cd0c7c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1093,7 +1093,7 @@ checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "appchain-core-contract-client" version = "0.1.0" -source = "git+https://github.com/byteZorvin/zaun?branch=type-update#fdfc6d4376f680a000fb0bd4b17a85207ad5fefd" +source = "git+https://github.com/byteZorvin/zaun?branch=type-update#36dc1fc5b2affaee69c669aac97a5062622b43b5" dependencies = [ "appchain-utils", "async-trait", @@ -1113,7 +1113,7 @@ dependencies = [ [[package]] name = "appchain-utils" version = "0.1.0" -source = "git+https://github.com/byteZorvin/zaun?branch=type-update#fdfc6d4376f680a000fb0bd4b17a85207ad5fefd" +source = "git+https://github.com/byteZorvin/zaun?branch=type-update#36dc1fc5b2affaee69c669aac97a5062622b43b5" dependencies = [ "async-trait", "color-eyre", diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index d8843498..ae3c303d 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -28,7 +28,7 @@ use mockall::{automock, predicate::*}; use alloy::providers::ProviderBuilder; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; #[cfg(not(feature = "testing"))] -use settlement_client_interface::{SettlementClient, SettlementConfig, SettlementVerificationStatus}; +use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; #[cfg(feature = "testing")] use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; #[cfg(feature = "testing")] @@ -164,11 +164,16 @@ impl SettlementClient for EthereumSettlementClient { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: usize, + onchain_data_size: [u128; 2], ) -> Result { let program_output: Vec = vec_u8_32_to_vec_u256(program_output.as_slice())?; let onchain_data_hash: U256 = slice_u8_to_u256(&onchain_data_hash)?; - let onchain_data_size: U256 = onchain_data_size.try_into()?; + let mut bytes = [0u8; 32]; + + bytes[0..16].copy_from_slice(&onchain_data_size[0].to_le_bytes()); + bytes[16..32].copy_from_slice(&onchain_data_size[1].to_le_bytes()); + + let onchain_data_size = U256::from_le_bytes(bytes); let tx_receipt = self.core_contract_client.update_state(program_output, onchain_data_hash, onchain_data_size).await?; Ok(format!("0x{:x}", tx_receipt.transaction_hash)) diff --git a/crates/settlement-clients/settlement-client-interface/src/lib.rs b/crates/settlement-clients/settlement-client-interface/src/lib.rs index 88ae00d0..d239c4fb 100644 --- a/crates/settlement-clients/settlement-client-interface/src/lib.rs +++ b/crates/settlement-clients/settlement-client-interface/src/lib.rs @@ -25,7 +25,7 @@ pub trait SettlementClient: Send + Sync { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: usize, + onchain_data_size: [u128; 2], ) -> Result; /// Should be used to update state on contract and publish the blob on ethereum. diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 95cd5485..7d0a3fb0 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -12,7 +12,7 @@ use color_eyre::Result; use lazy_static::lazy_static; use mockall::{automock, predicate::*}; use starknet::accounts::ConnectedAccount; -use starknet::core::types::TransactionExecutionStatus; +use starknet::core::types::{TransactionExecutionStatus, U256}; use starknet::providers::Provider; use starknet::{ accounts::{ExecutionEncoding, SingleOwnerAccount}, @@ -117,15 +117,15 @@ impl SettlementClient for StarknetSettlementClient { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: usize, + onchain_data_size: [u128; 2], ) -> Result { let program_output = slice_slice_u8_to_vec_field(program_output.as_slice()); let onchain_data_hash = slice_u8_to_field(&onchain_data_hash); - let onchain_data_size = Felt::from(onchain_data_size); let core_contract: &CoreContract = self.starknet_core_contract_client.as_ref(); + let onchain_data_size = U256::from_words(onchain_data_size[0], onchain_data_size[1]); let invoke_result = core_contract.update_state(program_output, onchain_data_hash, onchain_data_size).await?; - Ok(format!("0x{:x}", invoke_result.transaction_hash)) + Ok(invoke_result.transaction_hash.to_hex_string()) } /// Should verify the inclusion of a tx in the settlement layer diff --git a/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo index 7f1d1bf2..43577b0a 100644 --- a/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo +++ b/crates/settlement-clients/starknet/src/tests/mock_contracts/src/lib.cairo @@ -6,13 +6,16 @@ pub trait IPiltover { onchain_data_hash: felt252, onchain_data_size: u256 ); + + fn get_is_updated(self: @TContractState, onchain_data_hash: felt252) -> bool; } #[starknet::contract] mod Piltover { + use starknet::storage::Map; #[storage] struct Storage { - balance: felt252, + is_updated: Map, } #[abi(embed_v0)] @@ -22,6 +25,12 @@ mod Piltover { program_output: Span, onchain_data_hash: felt252, onchain_data_size: u256 - ) {} + ) { + self.is_updated.write(onchain_data_hash, true); + } + + fn get_is_updated(self: @ContractState, onchain_data_hash: felt252) -> bool { + self.is_updated.read(onchain_data_hash) + } } } diff --git a/crates/settlement-clients/starknet/src/tests/mod.rs b/crates/settlement-clients/starknet/src/tests/mod.rs index 35e469a2..5c2d0532 100644 --- a/crates/settlement-clients/starknet/src/tests/mod.rs +++ b/crates/settlement-clients/starknet/src/tests/mod.rs @@ -9,7 +9,7 @@ use std::{ collections::HashMap, future::Future, path::{Path, PathBuf}, - process::{Child, Command, Output, Stdio}, + process::{Child, Command, Output}, str::FromStr, time::Duration, }; @@ -183,7 +183,6 @@ impl MadaraCmdBuilder { "--rpc-port".into(), format!("{}", self.port.0), ])) - .stdout(Stdio::piped()) .spawn() .unwrap(); diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 669974d8..99c522ae 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -3,19 +3,21 @@ use crate::StarknetSettlementClient; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; use starknet::{ - accounts::{Account, ExecutionEncoding, SingleOwnerAccount}, + accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount}, contract::ContractFactory, core::types::{ contract::{CompiledClass, SierraClass}, - BlockId, BlockTag, DeclareTransactionResult, Felt, + BlockId, BlockTag, DeclareTransactionResult, Felt, FunctionCall, InvokeTransactionResult, StarknetError, + TransactionExecutionStatus, TransactionStatus, }, - macros::felt, - providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, Url}, + macros::{felt, selector}, + providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, ProviderError, Url}, signers::{LocalWallet, SigningKey}, }; use std::env; use std::path::PathBuf; use std::sync::Arc; +use std::time::Duration; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; @@ -35,7 +37,6 @@ pub async fn spin_up_madara() -> MadaraCmd { env::set_current_dir(&project_root).expect("Failed to set working directory"); - let _ = env_logger::builder().is_test(true).try_init(); let mut node = MadaraCmdBuilder::new() .args([ "--network", @@ -47,25 +48,69 @@ pub async fn spin_up_madara() -> MadaraCmd { "--devnet", "--preset=test", "--no-l1-sync", + "--rpc-cors", + "all", ]) .run(); + println!("check here"); node.wait_for_ready().await; + println!("check here 2"); node } -// #[fixture] -// async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { +#[allow(unused)] +async fn wait_for_tx_success( + account: &SingleOwnerAccount, LocalWallet>, + transaction_hash: Felt, + duration: Duration, +) -> bool { + let mut attempt = 0; + loop { + attempt += 1; + let reciept = match account.provider().get_transaction_status(transaction_hash).await { + Ok(reciept) => reciept, + Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => { + tokio::time::sleep(duration).await; + continue; + } + _ => panic!("Unknown error"), + }; + + match reciept { + TransactionStatus::Received => (), + TransactionStatus::Rejected => return false, + TransactionStatus::AcceptedOnL2(status) => match status { + TransactionExecutionStatus::Succeeded => return true, + TransactionExecutionStatus::Reverted => return false, + }, + TransactionStatus::AcceptedOnL1(status) => match status { + TransactionExecutionStatus::Succeeded => return true, + TransactionExecutionStatus::Reverted => return false, + }, + } + + if attempt >= 5 { + return false; + } + + // This is done, since currently madara does not increment nonce for pending transactions + tokio::time::sleep(duration).await; + } +} + #[fixture] -async fn setup() -> SingleOwnerAccount, LocalWallet> { - // let madara_process = spin_up_madara().await; - // println!("RPC url {:?}", madara_process.rpc_url); - dotenvy::from_filename_override(".env").expect("Failed to load the .env file"); +async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { + let _ = env_logger::builder().is_test(true).try_init(); + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + + let madara_process = spin_up_madara().await; + env::set_var("STARKNET_RPC_URL", madara_process.rpc_url.to_string()); + println!("RPC url {:?}", madara_process.rpc_url); let env_settings = EnvSettingsProvider::default(); let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); println!("RPC url {:?}", rpc_url); // let endpoint = madara_process.rpc_url.join("/health").unwrap(); - // let endpoint = rpc_url.join("/health").unwrap(); // let response = reqwest::get(endpoint.clone()).await.expect("Failed to connect to Provider"); // assert!(response.status().is_success(), "Failed to connect to Provider"); @@ -82,19 +127,18 @@ async fn setup() -> SingleOwnerAccount, LocalWallet // `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest // block. Optionally change the target block to pending with the following line: account.set_block_id(BlockId::Tag(BlockTag::Pending)); - // (account, madara_process) - account + (account, madara_process) } #[rstest] #[tokio::test] -// async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { -async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { - // let (account, madara_process) = setup.await; - let account = setup.await; +async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { + // async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { + let (account, _) = setup.await; + // let account = setup.await; // println!("the db being used is {:?}", madara_process.tempdir); - let account = Arc::new(account); + // let account = Arc::new(account); // NOTE: you will need to declare this class first let sierra_class: SierraClass = serde_json::from_reader( @@ -121,50 +165,71 @@ async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { - dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); - // let (account, madara_process) = setup.await; - let account = setup.await; - - // println!("the db being used is {:?}", madara_process.tempdir); +async fn test_settle(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { + let (account, _madara_process) = setup.await; let account = Arc::new(account); // NOTE: you will need to declare this class first let sierra_class: SierraClass = serde_json::from_reader( std::fs::File::open("/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.contract_class.json").unwrap(), ) - .unwrap(); + .expect("Failed to parse SierraClass"); let compiled_class: CompiledClass = serde_json::from_reader( std::fs::File::open("/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev/mock_contracts_Piltover.compiled_contract_class.json").unwrap(), ) - .unwrap(); + .expect("Failed to parse CompiledClass"); + + let flattened_class = sierra_class.clone().flatten().unwrap(); + let compiled_class_hash = compiled_class.class_hash().unwrap(); - // let flattened_class = sierra_class.clone().flatten().unwrap(); - // let compiled_class_hash = compiled_class.class_hash().unwrap(); - // let DeclareTransactionResult { transaction_hash: _, class_hash } = - // account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); - // assert!(flattened_class.class_hash() == class_hash, "Class hash declared is not same"); + let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = + account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); + println!("declare tx hash {:?}", declare_tx_hash); - // This is done, since currently madara does not increment nonce for pending transactions - // tokio::time::sleep(tokio::time::Duration::from_secs(4)).await; + let is_success = wait_for_tx_success(&account, declare_tx_hash, Duration::from_secs(2)).await; + assert!(is_success, "Declare trasactiion failed"); - // let contract_factory = ContractFactory::new(flattened_class.class_hash(), account); - // let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); - // let deployed_address = deploy_v1.deployed_address(); + let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); + let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); + let deployed_address = deploy_v1.deployed_address(); - let deployed_address = "0x067b25d85c42bae8f3fe833ab5ff97368e1c39019d34f02906e1cc6280f80e50"; - env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address); - // env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); - // deploy_v1.send().await.expect("Unable to deploy contract"); + env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); + let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = + deploy_v1.send().await.expect("Unable to deploy contract"); - // This is done, since currently madara does not increment nonce for pending transactions - tokio::time::sleep(tokio::time::Duration::from_secs(4)).await; + let is_success = wait_for_tx_success(&account, deploy_tx_hash, Duration::from_secs(2)).await; + assert!(is_success, "Deploy trasaction failed"); let env_settings = EnvSettingsProvider {}; let settlement_client = StarknetSettlementClient::new_with_settings(&env_settings).await; let onchain_data_hash = [1; 32]; let mut program_output = Vec::with_capacity(32); program_output.fill(onchain_data_hash); - settlement_client.update_state_calldata(program_output, onchain_data_hash, 1).await.unwrap(); + let update_state_tx_hash = settlement_client + .update_state_calldata(program_output, onchain_data_hash, [1, 1]) + .await + .expect("Sending Update state"); + + let is_success = wait_for_tx_success( + &account, + Felt::from_hex(&update_state_tx_hash).expect("Incorrect transaction hash"), + Duration::from_secs(2), + ) + .await; + assert!(is_success, "Update state transaction failed/reverted"); + + let call_result = account + .provider() + .call( + FunctionCall { + contract_address: deployed_address, + entry_point_selector: selector!("get_is_updated"), + calldata: vec![Felt::from_bytes_be_slice(&onchain_data_hash)], + }, + BlockId::Tag(BlockTag::Latest), + ) + .await + .expect("failed to call the contract"); + assert!(call_result[0] == true.into(), "Should be updated"); } From d6b5e67c184ed91f9430a8a29ab1a5fe8422eef3 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 27 Sep 2024 18:07:45 +0530 Subject: [PATCH 011/104] use relative path --- .../starknet/src/tests/test.rs | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 99c522ae..6bcd967d 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -15,6 +15,7 @@ use starknet::{ signers::{LocalWallet, SigningKey}, }; use std::env; +use std::path::Path; use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -52,9 +53,7 @@ pub async fn spin_up_madara() -> MadaraCmd { "all", ]) .run(); - println!("check here"); node.wait_for_ready().await; - println!("check here 2"); node } @@ -109,10 +108,6 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle let env_settings = EnvSettingsProvider::default(); let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); - println!("RPC url {:?}", rpc_url); - // let endpoint = madara_process.rpc_url.join("/health").unwrap(); - // let response = reqwest::get(endpoint.clone()).await.expect("Failed to connect to Provider"); - // assert!(response.status().is_success(), "Failed to connect to Provider"); // let provider = JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:9944").unwrap())); let provider: JsonRpcClient = JsonRpcClient::new(HttpTransport::new(rpc_url)); @@ -137,17 +132,14 @@ async fn test_deployment(#[future] setup: (SingleOwnerAccount Date: Sat, 28 Sep 2024 12:06:53 +0530 Subject: [PATCH 012/104] add ci for settlement client --- .env.example | 10 ++++- .env.test | 1 + .github/workflows/pull-request.yml | 5 +++ .github/workflows/starknet-test.yml | 43 ++++++++++++++++++ .../starknet/src/tests/test.rs | 44 +++++++++++-------- 5 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/starknet-test.yml diff --git a/.env.example b/.env.example index dd0eafa3..d0aa131c 100644 --- a/.env.example +++ b/.env.example @@ -47,4 +47,12 @@ MADARA_RPC_URL= MEMORY_PAGES_CONTRACT_ADDRESS= PRIVATE_KEY= ETHEREUM_PRIVATE_KEY= -STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS= \ No newline at end of file +STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS= + + + +##### STARKNET SETTLEMENT TEST ##### +STARKNET_PRIVATE_KEY= +STARKNET_PUBLIC_KEY= +STARKNET_RPC_URL= +MADARA_BINARY_PATH= \ No newline at end of file diff --git a/.env.test b/.env.test index e09d69d4..38e1d2d4 100644 --- a/.env.test +++ b/.env.test @@ -68,3 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 +MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/" \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 073c3121..756b4080 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -30,3 +30,8 @@ jobs: name: E2E test uses: ./.github/workflows/e2e-test.yml secrets: inherit + + starknet-test: + name: Starknet test + uses: ./.github/workflows/starknet-test.yml + secrets: inherit diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml new file mode 100644 index 00000000..e2385755 --- /dev/null +++ b/.github/workflows/starknet-test.yml @@ -0,0 +1,43 @@ +name: Starknet test + +on: + workflow_call: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout first repository + uses: actions/checkout@v3 + with: + repository: madara-alliance/madara # Replace with your first repository + ref: main # Replace with your branch name + path: madara + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Build + run: | + cd repo1 + cargo build --release + + - name: Checkout second repository + uses: actions/checkout@v3 + with: + repository: madara-alliance/madara-orchestrator # Replace with your second repository + path: orchestrator + + - name: Run Starknet tests + run: | + cd orchestrator + cargo test -p starknet-settlement-client --nocapture \ No newline at end of file diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 6bcd967d..b4175ca5 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -24,19 +24,19 @@ use utils::settings::Settings; #[allow(unused)] pub async fn spin_up_madara() -> MadaraCmd { - env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/")) - .expect("Failed to set working directory"); - let output = std::process::Command::new("cargo") - .arg("locate-project") - .arg("--workspace") - .arg("--message-format=plain") - .output() - .expect("Failed to execute command"); + env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); - let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); - let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); + // let output = std::process::Command::new("cargo") + // .arg("locate-project") + // .arg("--workspace") + // .arg("--message-format=plain") + // .output() + // .expect("Failed to execute command"); - env::set_current_dir(&project_root).expect("Failed to set working directory"); + // let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); + // let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); + + // env::set_current_dir(&project_root).expect("Failed to set working directory"); let mut node = MadaraCmdBuilder::new() .args([ @@ -51,6 +51,9 @@ pub async fn spin_up_madara() -> MadaraCmd { "--no-l1-sync", "--rpc-cors", "all", + "--chain-config-override", + "--block-time", + "1", ]) .run(); node.wait_for_ready().await; @@ -132,16 +135,19 @@ async fn test_deployment(#[future] setup: (SingleOwnerAccount Date: Sat, 28 Sep 2024 12:35:21 +0530 Subject: [PATCH 013/104] fix workflow debug --- .github/workflows/starknet-test.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index e2385755..08142a20 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -1,8 +1,12 @@ name: Starknet test on: - workflow_call: - workflow_dispatch: + pull_request: + branches: + - main + - dependency-bump + workflow_call: + workflow_dispatch: env: CARGO_TERM_COLOR: always @@ -12,6 +16,7 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout first repository uses: actions/checkout@v3 with: From 1d590cf295cae923b6dec05db8d9a2683799aaee Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 12:45:06 +0530 Subject: [PATCH 014/104] fix workflow debug --- .github/workflows/starknet-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 08142a20..c804d5f0 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -33,7 +33,7 @@ jobs: - name: Build run: | - cd repo1 + cd madara cargo build --release - name: Checkout second repository From 4ebfb4e7687a2b9d4aa8955f525e7cd42efb8c7a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 13:33:38 +0530 Subject: [PATCH 015/104] add scarb build --- .github/workflows/starknet-test.yml | 19 ++++++++++--- crates/settlement-clients/starknet/src/lib.rs | 2 +- .../tests/mock_contracts}/.tool-versions | 0 .../starknet/src/tests/mod.rs | 13 ++------- .../starknet/src/tests/test.rs | 28 ++++++++++++------- 5 files changed, 36 insertions(+), 26 deletions(-) rename crates/settlement-clients/starknet/{ => src/tests/mock_contracts}/.tool-versions (100%) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index c804d5f0..6a5ee588 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout first repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: madara-alliance/madara # Replace with your first repository ref: main # Replace with your branch name @@ -31,17 +31,28 @@ jobs: toolchain: stable override: true - - name: Build + - name: Build Madara run: | cd madara - cargo build --release + cargo build - name: Checkout second repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: madara-alliance/madara-orchestrator # Replace with your second repository path: orchestrator + + + - run: + cd crates/settlement-clients/starknet/src/tests/mock_contracts + - uses: asdf-vm/actions/install@v3 + - run: + scarb fmt --check + scarb build + cd - + + - name: Run Starknet tests run: | cd orchestrator diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 7d0a3fb0..73d9ebd0 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -70,7 +70,7 @@ impl StarknetSettlementClient { signer.clone(), signer_address, provider.chain_id().await.unwrap(), - ExecutionEncoding::New + ExecutionEncoding::New, )); let starknet_core_contract_client: StarknetCoreContractClient = diff --git a/crates/settlement-clients/starknet/.tool-versions b/crates/settlement-clients/starknet/src/tests/mock_contracts/.tool-versions similarity index 100% rename from crates/settlement-clients/starknet/.tool-versions rename to crates/settlement-clients/starknet/src/tests/mock_contracts/.tool-versions diff --git a/crates/settlement-clients/starknet/src/tests/mod.rs b/crates/settlement-clients/starknet/src/tests/mod.rs index 5c2d0532..e62d15e4 100644 --- a/crates/settlement-clients/starknet/src/tests/mod.rs +++ b/crates/settlement-clients/starknet/src/tests/mod.rs @@ -9,7 +9,7 @@ use std::{ collections::HashMap, future::Future, path::{Path, PathBuf}, - process::{Child, Command, Output}, + process::{Child, Command, Output, Stdio}, str::FromStr, time::Duration, }; @@ -183,6 +183,7 @@ impl MadaraCmdBuilder { "--rpc-port".into(), format!("{}", self.port.0), ])) + .stdout(Stdio::piped()) .spawn() .unwrap(); @@ -217,16 +218,6 @@ pub fn set_workdir() { env::set_current_dir(&project_root).expect("Failed to set working directory"); } -#[rstest] -fn madara_help_shows(_set_workdir: ()) { - let _ = env_logger::builder().is_test(true).try_init(); - let output = MadaraCmdBuilder::new().args(["--help"]).run().wait_with_output(); - assert!(output.status.success()); - - let stdout = String::from_utf8(output.stdout).unwrap(); - assert!(stdout.contains("Madara: High performance Starknet sequencer/full-node"), "stdout: {stdout}"); -} - #[rstest] #[tokio::test] async fn madara_can_sync_a_few_blocks(_set_workdir: ()) { diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index b4175ca5..0a6868c6 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -16,7 +16,6 @@ use starknet::{ }; use std::env; use std::path::Path; -use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; use utils::settings::env::EnvSettingsProvider; @@ -131,9 +130,8 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle #[rstest] #[tokio::test] async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { - // async fn test_deployment(#[future] setup: SingleOwnerAccount, LocalWallet>) { - let (account, _) = setup.await; - // let account = setup.await; + let (account, _madara_process) = setup.await; + let account = Arc::new(account); let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); @@ -151,14 +149,24 @@ async fn test_deployment(#[future] setup: (SingleOwnerAccount Date: Sat, 28 Sep 2024 14:31:20 +0530 Subject: [PATCH 016/104] ignore flaky test --- .../starknet/src/tests/mod.rs | 16 +++------------- .../starknet/src/tests/test.rs | 19 ++----------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/mod.rs b/crates/settlement-clients/starknet/src/tests/mod.rs index e62d15e4..f5097df4 100644 --- a/crates/settlement-clients/starknet/src/tests/mod.rs +++ b/crates/settlement-clients/starknet/src/tests/mod.rs @@ -203,21 +203,11 @@ use std::env; #[fixture] pub fn set_workdir() { - env::set_current_dir(PathBuf::from("/Users/bytezorvin/work/karnot/madara/")) - .expect("Failed to set working directory"); - let output = std::process::Command::new("cargo") - .arg("locate-project") - .arg("--workspace") - .arg("--message-format=plain") - .output() - .expect("Failed to execute command"); - - let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); - let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); - - env::set_current_dir(&project_root).expect("Failed to set working directory"); + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); } +#[ignore] #[rstest] #[tokio::test] async fn madara_can_sync_a_few_blocks(_set_workdir: ()) { diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 0a6868c6..f8cf1c44 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -21,29 +21,15 @@ use std::time::Duration; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; -#[allow(unused)] pub async fn spin_up_madara() -> MadaraCmd { + println!("Spinning up madara"); env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); - - // let output = std::process::Command::new("cargo") - // .arg("locate-project") - // .arg("--workspace") - // .arg("--message-format=plain") - // .output() - // .expect("Failed to execute command"); - - // let cargo_toml_path = String::from_utf8(output.stdout).expect("Invalid UTF-8"); - // let project_root = PathBuf::from(cargo_toml_path.trim()).parent().unwrap().to_path_buf(); - - // env::set_current_dir(&project_root).expect("Failed to set working directory"); - + println!("Current working directory: {:?}", env::current_dir().unwrap()); let mut node = MadaraCmdBuilder::new() .args([ "--network", "devnet", "--no-sync-polling", - "--n-blocks-to-sync", - "20", "--authority", "--devnet", "--preset=test", @@ -59,7 +45,6 @@ pub async fn spin_up_madara() -> MadaraCmd { node } -#[allow(unused)] async fn wait_for_tx_success( account: &SingleOwnerAccount, LocalWallet>, transaction_hash: Felt, From 2a074d0f7d374060c2afd3a81be88cde1e3cf26f Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 14:36:49 +0530 Subject: [PATCH 017/104] fix threads issue --- .github/workflows/starknet-test.yml | 2 +- crates/settlement-clients/starknet/src/tests/test.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 6a5ee588..9282de54 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -56,4 +56,4 @@ jobs: - name: Run Starknet tests run: | cd orchestrator - cargo test -p starknet-settlement-client --nocapture \ No newline at end of file + cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 \ No newline at end of file diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index f8cf1c44..08e7e076 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -53,6 +53,9 @@ async fn wait_for_tx_success( let mut attempt = 0; loop { attempt += 1; + if attempt >= 5 { + return false; + } let reciept = match account.provider().get_transaction_status(transaction_hash).await { Ok(reciept) => reciept, Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => { @@ -74,11 +77,6 @@ async fn wait_for_tx_success( TransactionExecutionStatus::Reverted => return false, }, } - - if attempt >= 5 { - return false; - } - // This is done, since currently madara does not increment nonce for pending transactions tokio::time::sleep(duration).await; } From d2c5729aa497c98f52a03a553e1b9d57ed4704fc Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 15:12:15 +0530 Subject: [PATCH 018/104] add scarb build for madara --- .github/workflows/starknet-test.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 9282de54..da5d424e 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -31,6 +31,12 @@ jobs: toolchain: stable override: true + - name: Setup Scarb + run: | + cd madara/cairo + uses: asdf-vm/actions/install@v3 + cd - + - name: Build Madara run: | cd madara @@ -40,14 +46,13 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara-orchestrator # Replace with your second repository - path: orchestrator + path: madara-orchestrator - - - run: - cd crates/settlement-clients/starknet/src/tests/mock_contracts - - uses: asdf-vm/actions/install@v3 - - run: + - name: Build Mock Contracts using Scarb + run: | + cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts + uses: asdf-vm/actions/install@v3 scarb fmt --check scarb build cd - @@ -55,5 +60,5 @@ jobs: - name: Run Starknet tests run: | - cd orchestrator - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 \ No newline at end of file + cd madara-orchestrator + cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From c575e7bd784eeef86e9c24dedd7a5dcd74f6c109 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 15:19:01 +0530 Subject: [PATCH 019/104] check if tool version present --- .github/workflows/starknet-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index da5d424e..e36dce82 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -34,7 +34,8 @@ jobs: - name: Setup Scarb run: | cd madara/cairo - uses: asdf-vm/actions/install@v3 + ls -la + asdf-vm/actions/install@v3 cd - - name: Build Madara From ac4cda5d28560ea1344c5107a5b2ab97db740444 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 15:37:39 +0530 Subject: [PATCH 020/104] fix workflow debug --- .github/workflows/starknet-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index e36dce82..65c27c5c 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -35,7 +35,9 @@ jobs: run: | cd madara/cairo ls -la + cat .tool-versions asdf-vm/actions/install@v3 + asdf install scarb 2.8.2 cd - - name: Build Madara From fc7be882899a34ff8f24fb761a1150791a14ea06 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 15:54:09 +0530 Subject: [PATCH 021/104] fix workflwo --- .github/workflows/starknet-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 65c27c5c..ab9d6ba8 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -36,9 +36,9 @@ jobs: cd madara/cairo ls -la cat .tool-versions - asdf-vm/actions/install@v3 - asdf install scarb 2.8.2 - cd - + + - uses: asdf-vm/actions/install@v3 + - run: cd - - name: Build Madara run: | From b8eab20428e89246dc5cf99cde17d113b1d7eb03 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 16:22:31 +0530 Subject: [PATCH 022/104] fix directory --- .github/workflows/starknet-test.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index ab9d6ba8..b93b5b4e 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -31,14 +31,14 @@ jobs: toolchain: stable override: true - - name: Setup Scarb - run: | - cd madara/cairo - ls -la - cat .tool-versions - - - uses: asdf-vm/actions/install@v3 - - run: cd - + - name: Install asdf and dependencies + uses: asdf-vm/actions/install@v3 + with: + before_install: | + cd madara/cairo + pwd + ls -la + cat .tool-versions - name: Build Madara run: | @@ -55,12 +55,10 @@ jobs: - name: Build Mock Contracts using Scarb run: | cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts - uses: asdf-vm/actions/install@v3 scarb fmt --check scarb build cd - - - name: Run Starknet tests run: | cd madara-orchestrator From 7daf808752c6b9b982d885a864e2d37a9309173e Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 16:59:49 +0530 Subject: [PATCH 023/104] should fix it --- .github/workflows/starknet-test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index b93b5b4e..a30d38d8 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -32,13 +32,13 @@ jobs: override: true - name: Install asdf and dependencies - uses: asdf-vm/actions/install@v3 - with: - before_install: | - cd madara/cairo - pwd - ls -la - cat .tool-versions + run: | + git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 + echo -e ' + . $HOME/.asdf/asdf.sh' >> ~/.bashrc && echo -e ' + . $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc + source ~/.bashrc + asdf install scarb 2.8.2 - name: Build Madara run: | From 8fb24507e9494e224bd2387ae8b5edcf70efad5a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:07:40 +0530 Subject: [PATCH 024/104] fix bash command --- .github/workflows/starknet-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index a30d38d8..2897b70d 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -35,8 +35,7 @@ jobs: run: | git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 echo -e ' - . $HOME/.asdf/asdf.sh' >> ~/.bashrc && echo -e ' - . $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc + . $HOME/.asdf/asdf.sh' >> ~/.bashrc source ~/.bashrc asdf install scarb 2.8.2 From a2b536eae4eb36126347e6c7a2c474c4e4fe12e7 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:07:45 +0530 Subject: [PATCH 025/104] fix bash command From 0d0fefe3cbe3c56029ee676f6a545016b4a71f16 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:10:32 +0530 Subject: [PATCH 026/104] make scarb installation separate step --- .github/workflows/starknet-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 2897b70d..482717e1 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -37,7 +37,11 @@ jobs: echo -e ' . $HOME/.asdf/asdf.sh' >> ~/.bashrc source ~/.bashrc + + - name: Install Scarb + run: | asdf install scarb 2.8.2 + asdf global scarb 2.8.2 - name: Build Madara run: | From 99dd1ddffd2070d5ca452ea4ca564756f6300971 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:13:20 +0530 Subject: [PATCH 027/104] use swm action --- .github/workflows/starknet-test.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 482717e1..e13b5dd9 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -31,17 +31,9 @@ jobs: toolchain: stable override: true - - name: Install asdf and dependencies - run: | - git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 - echo -e ' - . $HOME/.asdf/asdf.sh' >> ~/.bashrc - source ~/.bashrc - - - name: Install Scarb - run: | - asdf install scarb 2.8.2 - asdf global scarb 2.8.2 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.8.2" - name: Build Madara run: | From 56c4144da0d39de67a4da46414dc8574b5e63393 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:39:01 +0530 Subject: [PATCH 028/104] fix ci path --- .env.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 38e1d2d4..f4161793 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/" \ No newline at end of file +MADARA_BINARY_PATH="/home/runner/madara/" \ No newline at end of file From 66ebcd5a3b46fa47a9438e6f36be8f0f4101e28a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 17:49:44 +0530 Subject: [PATCH 029/104] lint fixed --- .github/workflows/starknet-test.yml | 86 +++++++++---------- crates/settlement-clients/starknet/Cargo.toml | 10 +-- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index e13b5dd9..48e8795c 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -2,7 +2,7 @@ name: Starknet test on: pull_request: - branches: + branches: - main - dependency-bump workflow_call: @@ -14,47 +14,45 @@ env: jobs: build-and-test: runs-on: ubuntu-latest - - steps: - - name: Checkout first repository - uses: actions/checkout@v4 - with: - repository: madara-alliance/madara # Replace with your first repository - ref: main # Replace with your branch name - path: madara - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - uses: software-mansion/setup-scarb@v1 - with: - scarb-version: "2.8.2" - - - name: Build Madara - run: | - cd madara - cargo build - - - name: Checkout second repository - uses: actions/checkout@v4 - with: - repository: madara-alliance/madara-orchestrator # Replace with your second repository - path: madara-orchestrator - - - - name: Build Mock Contracts using Scarb - run: | - cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts - scarb fmt --check - scarb build - cd - - - - name: Run Starknet tests - run: | - cd madara-orchestrator - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 + steps: + - name: Checkout first repository + uses: actions/checkout@v4 + with: + repository: madara-alliance/madara # Replace with your first repository + ref: main # Replace with your branch name + path: madara + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.8.2" + + - name: Build Madara + run: | + cd madara + cargo build + + - name: Checkout second repository + uses: actions/checkout@v4 + with: + repository: madara-alliance/madara-orchestrator # Replace with your second repository + path: madara-orchestrator + + - name: Build Mock Contracts using Scarb + run: | + cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts + scarb fmt --check + scarb build + cd - + + - name: Run Starknet tests + run: | + cd madara-orchestrator + cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index d0a40cb0..ecdae5a1 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -4,9 +4,13 @@ version.workspace = true edition.workspace = true [dependencies] +anyhow = "1.0.89" +appchain-core-contract-client = { workspace = true } async-trait = { workspace = true } c-kzg = { workspace = true } color-eyre = { workspace = true } +dotenvy.workspace = true +env_logger = "0.11.5" lazy_static = { workspace = true } mockall = { workspace = true } reqwest = { workspace = true } @@ -14,14 +18,10 @@ rstest = { workspace = true } serde = { workspace = true } settlement-client-interface = { workspace = true } starknet = { workspace = true } +tempfile.workspace = true tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } -appchain-core-contract-client = { workspace = true } -tempfile.workspace = true -anyhow = "1.0.89" -env_logger = "0.11.5" -dotenvy.workspace = true [dev-dependencies] async-std = { version = "1.13.0", features = ["attributes"] } From 09e82b6d04a453b9986cf81a455b1d6b6a36e4d0 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 18:29:47 +0530 Subject: [PATCH 030/104] fix env path for tests --- .env.test | 2 +- .github/workflows/starknet-test.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env.test b/.env.test index f4161793..dd5b6a76 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/madara/" \ No newline at end of file +MADARA_BINARY_PATH="/home/runner/madara-orchestrator/" diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 48e8795c..c7a51d15 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -50,9 +50,10 @@ jobs: cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts scarb fmt --check scarb build - cd - - name: Run Starknet tests run: | + pwd + tree -L 1 cd madara-orchestrator cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From fc44027ad3d8e2d81e88d0c534dfb48266dcb28d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 18:33:15 +0530 Subject: [PATCH 031/104] fix lint --- .github/workflows/starknet-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index c7a51d15..a1b5fcdb 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -49,7 +49,7 @@ jobs: run: | cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts scarb fmt --check - scarb build + scarb build - name: Run Starknet tests run: | From d539edb5adf1b14a93b92a25e19d747667a39077 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 18:59:48 +0530 Subject: [PATCH 032/104] remove extra path --- .github/workflows/starknet-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index a1b5fcdb..226c07a8 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -36,6 +36,8 @@ jobs: - name: Build Madara run: | + pwd + tree -L 1 cd madara cargo build @@ -43,7 +45,6 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara-orchestrator # Replace with your second repository - path: madara-orchestrator - name: Build Mock Contracts using Scarb run: | From 16f934d48d176d7173b8c28589e82fbb179d8f22 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 19:16:31 +0530 Subject: [PATCH 033/104] try checking structure --- .env.test | 2 +- .github/workflows/starknet-test.yml | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.env.test b/.env.test index dd5b6a76..c739a151 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/madara-orchestrator/" +MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara/" \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 226c07a8..29b5fd32 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -16,12 +16,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout first repository + - name: Checkout Madara uses: actions/checkout@v4 with: repository: madara-alliance/madara # Replace with your first repository ref: main # Replace with your branch name - path: madara - name: Setup Rust uses: actions-rs/toolchain@v1 @@ -37,11 +36,11 @@ jobs: - name: Build Madara run: | pwd - tree -L 1 + tree -L 3 cd madara cargo build - - name: Checkout second repository + - name: Checkout Madara Orchestrator uses: actions/checkout@v4 with: repository: madara-alliance/madara-orchestrator # Replace with your second repository @@ -49,12 +48,14 @@ jobs: - name: Build Mock Contracts using Scarb run: | cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts + tree -L 3 scarb fmt --check scarb build - name: Run Starknet tests + working-directory: madara-orchestrator run: | pwd - tree -L 1 + tree -L 3 cd madara-orchestrator cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From df4e9558b69fc2b6dd2a9be6d42c3a9557183120 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 19:27:09 +0530 Subject: [PATCH 034/104] check --- .github/workflows/starknet-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 29b5fd32..27119acc 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -21,6 +21,7 @@ jobs: with: repository: madara-alliance/madara # Replace with your first repository ref: main # Replace with your branch name + path: madara_path - name: Setup Rust uses: actions-rs/toolchain@v1 From 1a14f38f3b92158ad9d5e29e74214cf2c3925b8c Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 19:30:17 +0530 Subject: [PATCH 035/104] fix env path --- .env.test | 2 +- .github/workflows/starknet-test.yml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.env.test b/.env.test index c739a151..e20196f1 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara/" \ No newline at end of file +MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara-orchestrator/madara/" \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 27119acc..0b6ce39a 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -21,7 +21,7 @@ jobs: with: repository: madara-alliance/madara # Replace with your first repository ref: main # Replace with your branch name - path: madara_path + path: madara - name: Setup Rust uses: actions-rs/toolchain@v1 @@ -36,8 +36,6 @@ jobs: - name: Build Madara run: | - pwd - tree -L 3 cd madara cargo build @@ -48,8 +46,9 @@ jobs: - name: Build Mock Contracts using Scarb run: | - cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts + pwd tree -L 3 + cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts scarb fmt --check scarb build From 328fa0c55c71b87af30c04036e81bcb4942cdffa Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 28 Sep 2024 19:43:29 +0530 Subject: [PATCH 036/104] fix the directory --- .github/workflows/starknet-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 0b6ce39a..aaa48e81 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -48,7 +48,7 @@ jobs: run: | pwd tree -L 3 - cd madara-orchestrator/crates/settlement-clients/starknet/src/tests/mock_contracts + cd crates/settlement-clients/starknet/src/tests/mock_contracts scarb fmt --check scarb build From c49cb70d1506432fadacbf4bf0423e3c1360bd43 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 18:25:35 +0530 Subject: [PATCH 037/104] try go into --- .env.test | 2 +- .github/workflows/starknet-test.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env.test b/.env.test index e20196f1..c739a151 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara-orchestrator/madara/" \ No newline at end of file +MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara/" \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index aaa48e81..2193fc04 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -36,8 +36,9 @@ jobs: - name: Build Madara run: | + pwd cd madara - cargo build + pwd - name: Checkout Madara Orchestrator uses: actions/checkout@v4 From 2a2a1dd455c1ea2b7b8c1207b0bce5ea62b6eb8e Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 18:36:43 +0530 Subject: [PATCH 038/104] fix path --- .github/workflows/starknet-test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 2193fc04..674d2104 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -35,10 +35,10 @@ jobs: scarb-version: "2.8.2" - name: Build Madara + working-directory: madara run: | pwd - cd madara - pwd + cargo build - name: Checkout Madara Orchestrator uses: actions/checkout@v4 @@ -57,6 +57,7 @@ jobs: working-directory: madara-orchestrator run: | pwd + cd ../.. tree -L 3 - cd madara-orchestrator + cd - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From c8c9a53fcceefd1d19472de8257eae46408e6af0 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 18:53:42 +0530 Subject: [PATCH 039/104] remove working directory --- .github/workflows/starknet-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 674d2104..10cacaa5 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -38,7 +38,6 @@ jobs: working-directory: madara run: | pwd - cargo build - name: Checkout Madara Orchestrator uses: actions/checkout@v4 @@ -54,7 +53,6 @@ jobs: scarb build - name: Run Starknet tests - working-directory: madara-orchestrator run: | pwd cd ../.. From 4753c2c87ce9ed2c0ceb3bebc7cd6aaf43e66b07 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 18:59:05 +0530 Subject: [PATCH 040/104] final fix --- .env.test | 2 +- .github/workflows/starknet-test.yml | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.env.test b/.env.test index c739a151..e20196f1 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara/" \ No newline at end of file +MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara-orchestrator/madara/" \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 10cacaa5..23c62bda 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -37,7 +37,7 @@ jobs: - name: Build Madara working-directory: madara run: | - pwd + cargo build - name: Checkout Madara Orchestrator uses: actions/checkout@v4 @@ -46,16 +46,10 @@ jobs: - name: Build Mock Contracts using Scarb run: | - pwd - tree -L 3 cd crates/settlement-clients/starknet/src/tests/mock_contracts scarb fmt --check scarb build - name: Run Starknet tests run: | - pwd - cd ../.. - tree -L 3 - cd - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From 76c3f59322f2303ce6aa697b3ea906a4475c9bca Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 19:02:59 +0530 Subject: [PATCH 041/104] fix: gets triggered multiple times --- .github/workflows/starknet-test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 23c62bda..9307ae2f 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -1,10 +1,6 @@ name: Starknet test on: - pull_request: - branches: - - main - - dependency-bump workflow_call: workflow_dispatch: From 08261c448140347cf2dc69544b3f0eb700bbf0b6 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 19:39:49 +0530 Subject: [PATCH 042/104] fix path --- .env.test | 2 +- .github/workflows/starknet-test.yml | 30 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.env.test b/.env.test index e20196f1..fe48f734 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/home/runner/work/madara-orchestrator/madara-orchestrator/madara/" \ No newline at end of file +MADARA_BINARY_PATH="Replace with path to madara repoistory" \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index 9307ae2f..fa3e79af 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -12,13 +12,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout Madara - uses: actions/checkout@v4 - with: - repository: madara-alliance/madara # Replace with your first repository - ref: main # Replace with your branch name - path: madara - - name: Setup Rust uses: actions-rs/toolchain@v1 with: @@ -30,11 +23,6 @@ jobs: with: scarb-version: "2.8.2" - - name: Build Madara - working-directory: madara - run: | - cargo build - - name: Checkout Madara Orchestrator uses: actions/checkout@v4 with: @@ -46,6 +34,22 @@ jobs: scarb fmt --check scarb build + - name: Checkout Madara + uses: actions/checkout@v4 + with: + repository: madara-alliance/madara # Replace with your first repository + ref: main # Replace with your branch name + path: madara + + - name: Build Madara + working-directory: madara + run: | + cargo build + current_path=$(pwd) + echo -e " + MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test + + - name: Run Starknet tests run: | - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 + cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 \ No newline at end of file From 577b32734e65f9d0d82650352a72b175e454845d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sun, 29 Sep 2024 20:00:09 +0530 Subject: [PATCH 043/104] fix prettier --- .github/workflows/starknet-test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml index fa3e79af..92baeaa2 100644 --- a/.github/workflows/starknet-test.yml +++ b/.github/workflows/starknet-test.yml @@ -40,7 +40,7 @@ jobs: repository: madara-alliance/madara # Replace with your first repository ref: main # Replace with your branch name path: madara - + - name: Build Madara working-directory: madara run: | @@ -48,8 +48,7 @@ jobs: current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test - - name: Run Starknet tests run: | - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 \ No newline at end of file + cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From e6eaf2e4ff0387828b5d09eed8b2f323ea7b9184 Mon Sep 17 00:00:00 2001 From: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:53:00 +0530 Subject: [PATCH 044/104] change calldata type to (#133) --- Cargo.lock | 1 + Cargo.toml | 1 + crates/settlement-clients/ethereum/src/lib.rs | 9 ++------- .../settlement-client-interface/src/lib.rs | 2 +- crates/settlement-clients/starknet/Cargo.toml | 1 + crates/settlement-clients/starknet/src/lib.rs | 5 +++-- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7cd0c7c2..0bef26cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9015,6 +9015,7 @@ dependencies = [ "async-trait", "c-kzg", "color-eyre", + "crypto-bigint 0.5.5", "dotenvy", "env_logger", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index b2136a05..92bed5fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,6 +78,7 @@ itertools = "0.13.0" mockall = "0.13.0" testcontainers = "0.18.0" appchain-core-contract-client = { git = "https://github.com/byteZorvin/zaun", branch = "type-update" } +crypto-bigint = { version = "0.5.5" } # Cairo VM cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [ diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index ae3c303d..86d8f73e 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -164,16 +164,11 @@ impl SettlementClient for EthereumSettlementClient { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: [u128; 2], + onchain_data_size: [u8; 32], ) -> Result { let program_output: Vec = vec_u8_32_to_vec_u256(program_output.as_slice())?; let onchain_data_hash: U256 = slice_u8_to_u256(&onchain_data_hash)?; - let mut bytes = [0u8; 32]; - - bytes[0..16].copy_from_slice(&onchain_data_size[0].to_le_bytes()); - bytes[16..32].copy_from_slice(&onchain_data_size[1].to_le_bytes()); - - let onchain_data_size = U256::from_le_bytes(bytes); + let onchain_data_size = U256::from_be_bytes(onchain_data_size); let tx_receipt = self.core_contract_client.update_state(program_output, onchain_data_hash, onchain_data_size).await?; Ok(format!("0x{:x}", tx_receipt.transaction_hash)) diff --git a/crates/settlement-clients/settlement-client-interface/src/lib.rs b/crates/settlement-clients/settlement-client-interface/src/lib.rs index d239c4fb..be30cf33 100644 --- a/crates/settlement-clients/settlement-client-interface/src/lib.rs +++ b/crates/settlement-clients/settlement-client-interface/src/lib.rs @@ -25,7 +25,7 @@ pub trait SettlementClient: Send + Sync { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: [u128; 2], + onchain_data_size: [u8; 32], ) -> Result; /// Should be used to update state on contract and publish the blob on ethereum. diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index ecdae5a1..c2ea38b2 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -22,6 +22,7 @@ tempfile.workspace = true tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } +crypto-bigint = { workspace = true } [dev-dependencies] async-std = { version = "1.13.0", features = ["attributes"] } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 73d9ebd0..8e43bc22 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -9,6 +9,7 @@ use appchain_core_contract_client::interfaces::core_contract::CoreContract; use async_trait::async_trait; use color_eyre::eyre::{eyre, Ok}; use color_eyre::Result; +use crypto_bigint::Encoding; use lazy_static::lazy_static; use mockall::{automock, predicate::*}; use starknet::accounts::ConnectedAccount; @@ -117,12 +118,12 @@ impl SettlementClient for StarknetSettlementClient { &self, program_output: Vec<[u8; 32]>, onchain_data_hash: [u8; 32], - onchain_data_size: [u128; 2], + onchain_data_size: [u8; 32], ) -> Result { let program_output = slice_slice_u8_to_vec_field(program_output.as_slice()); let onchain_data_hash = slice_u8_to_field(&onchain_data_hash); let core_contract: &CoreContract = self.starknet_core_contract_client.as_ref(); - let onchain_data_size = U256::from_words(onchain_data_size[0], onchain_data_size[1]); + let onchain_data_size = crypto_bigint::U256::from_be_bytes(onchain_data_size).into(); let invoke_result = core_contract.update_state(program_output, onchain_data_hash, onchain_data_size).await?; Ok(invoke_result.transaction_hash.to_hex_string()) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 08e7e076..8a21439c 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -199,7 +199,7 @@ async fn test_settle(#[future] setup: (SingleOwnerAccount Date: Mon, 30 Sep 2024 12:58:34 +0530 Subject: [PATCH 045/104] update workflow --- .env.test | 2 +- .github/workflows/coverage.yml | 25 +++++++++++++ .github/workflows/pull-request.yml | 7 +--- .github/workflows/starknet-test.yml | 54 ----------------------------- 4 files changed, 27 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/starknet-test.yml diff --git a/.env.test b/.env.test index fe48f734..0e4c08df 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="Replace with path to madara repoistory" \ No newline at end of file +MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 63e0adb5..43e15687 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -61,6 +61,31 @@ jobs: - name: Install nextest uses: taiki-e/install-action@nextest + + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.8.2" + + - name: Build Mock Contracts using Scarb + run: | + cd crates/settlement-clients/starknet/src/tests/mock_contracts + scarb fmt --check + scarb build + + - name: Checkout Madara + uses: actions/checkout@v4 + with: + repository: madara-alliance/madara # Replace with your first repository + ref: main # Replace with your branch name + path: madara + + - name: Build Madara + working-directory: madara + run: | + cargo build + current_path=$(pwd) + echo -e " + MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test - name: Getting neccesary files for testing run: | diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 756b4080..c32b6da0 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -29,9 +29,4 @@ jobs: e2e-test: name: E2E test uses: ./.github/workflows/e2e-test.yml - secrets: inherit - - starknet-test: - name: Starknet test - uses: ./.github/workflows/starknet-test.yml - secrets: inherit + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/starknet-test.yml b/.github/workflows/starknet-test.yml deleted file mode 100644 index 92baeaa2..00000000 --- a/.github/workflows/starknet-test.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Starknet test - -on: - workflow_call: - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - uses: software-mansion/setup-scarb@v1 - with: - scarb-version: "2.8.2" - - - name: Checkout Madara Orchestrator - uses: actions/checkout@v4 - with: - repository: madara-alliance/madara-orchestrator # Replace with your second repository - - - name: Build Mock Contracts using Scarb - run: | - cd crates/settlement-clients/starknet/src/tests/mock_contracts - scarb fmt --check - scarb build - - - name: Checkout Madara - uses: actions/checkout@v4 - with: - repository: madara-alliance/madara # Replace with your first repository - ref: main # Replace with your branch name - path: madara - - - name: Build Madara - working-directory: madara - run: | - cargo build - current_path=$(pwd) - echo -e " - MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test - - - name: Run Starknet tests - run: | - cargo test -p starknet-settlement-client -- --nocapture --test-threads=1 From dc22f6ed84c8b6e6d7dca71d6f43741bbadcade3 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Mon, 30 Sep 2024 13:09:16 +0530 Subject: [PATCH 046/104] fix lints --- .github/workflows/coverage.yml | 2 +- .github/workflows/pull-request.yml | 2 +- crates/settlement-clients/starknet/Cargo.toml | 2 +- crates/settlement-clients/starknet/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 43e15687..cac81c8c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -61,7 +61,7 @@ jobs: - name: Install nextest uses: taiki-e/install-action@nextest - + - uses: software-mansion/setup-scarb@v1 with: scarb-version: "2.8.2" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c32b6da0..073c3121 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -29,4 +29,4 @@ jobs: e2e-test: name: E2E test uses: ./.github/workflows/e2e-test.yml - secrets: inherit \ No newline at end of file + secrets: inherit diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index c2ea38b2..a1b100f7 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -9,6 +9,7 @@ appchain-core-contract-client = { workspace = true } async-trait = { workspace = true } c-kzg = { workspace = true } color-eyre = { workspace = true } +crypto-bigint = { workspace = true } dotenvy.workspace = true env_logger = "0.11.5" lazy_static = { workspace = true } @@ -22,7 +23,6 @@ tempfile.workspace = true tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } -crypto-bigint = { workspace = true } [dev-dependencies] async-std = { version = "1.13.0", features = ["attributes"] } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 8e43bc22..62f0daa8 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -13,7 +13,7 @@ use crypto_bigint::Encoding; use lazy_static::lazy_static; use mockall::{automock, predicate::*}; use starknet::accounts::ConnectedAccount; -use starknet::core::types::{TransactionExecutionStatus, U256}; +use starknet::core::types::TransactionExecutionStatus; use starknet::providers::Provider; use starknet::{ accounts::{ExecutionEncoding, SingleOwnerAccount}, From 9a075cd7aa7973ec212ec59883f981b6e650ebf8 Mon Sep 17 00:00:00 2001 From: Mehul Chauhan Date: Mon, 30 Sep 2024 14:35:58 +0530 Subject: [PATCH 047/104] Update crates/settlement-clients/starknet/src/tests/test.rs Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> --- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 8a21439c..5b949a24 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -45,7 +45,7 @@ pub async fn spin_up_madara() -> MadaraCmd { node } -async fn wait_for_tx_success( +async fn wait_for_tx( account: &SingleOwnerAccount, LocalWallet>, transaction_hash: Felt, duration: Duration, From 58d007ff9a6894115d0cbbb0896adc0598ea6ba6 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Mon, 30 Sep 2024 15:19:27 +0530 Subject: [PATCH 048/104] resolve comments --- .env.test | 2 +- .gitignore | 1 - Cargo.lock | 3 +- crates/settlement-clients/ethereum/src/lib.rs | 3 - crates/settlement-clients/starknet/Cargo.toml | 1 - .../starknet/src/tests/mod.rs | 239 +----------------- .../starknet/src/tests/setup.rs | 167 ++++++++++++ .../starknet/src/tests/test.rs | 15 +- 8 files changed, 177 insertions(+), 254 deletions(-) create mode 100644 crates/settlement-clients/starknet/src/tests/setup.rs diff --git a/.env.test b/.env.test index 0e4c08df..c09446ac 100644 --- a/.env.test +++ b/.env.test @@ -68,4 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 STARKNET_RPC_URL=http://localhost:9944 -MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/" +MADARA_BINARY_PATH="/path/to/madara" diff --git a/.gitignore b/.gitignore index b296e1f2..f0cfd7ce 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ *.code-workspace .vscode -db/ lcov.info diff --git a/Cargo.lock b/Cargo.lock index 0bef26cc..c5966292 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5757,7 +5757,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -9017,7 +9017,6 @@ dependencies = [ "color-eyre", "crypto-bigint 0.5.5", "dotenvy", - "env_logger", "lazy_static", "mockall", "reqwest 0.12.7", diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 86d8f73e..bac11c46 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -27,9 +27,6 @@ use mockall::{automock, predicate::*}; use alloy::providers::ProviderBuilder; use conversion::{get_input_data_for_eip_4844, prepare_sidecar}; -#[cfg(not(feature = "testing"))] -use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; -#[cfg(feature = "testing")] use settlement_client_interface::{SettlementClient, SettlementVerificationStatus}; #[cfg(feature = "testing")] use url::Url; diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index a1b100f7..a1def74e 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -11,7 +11,6 @@ c-kzg = { workspace = true } color-eyre = { workspace = true } crypto-bigint = { workspace = true } dotenvy.workspace = true -env_logger = "0.11.5" lazy_static = { workspace = true } mockall = { workspace = true } reqwest = { workspace = true } diff --git a/crates/settlement-clients/starknet/src/tests/mod.rs b/crates/settlement-clients/starknet/src/tests/mod.rs index f5097df4..f67283f2 100644 --- a/crates/settlement-clients/starknet/src/tests/mod.rs +++ b/crates/settlement-clients/starknet/src/tests/mod.rs @@ -1,239 +1,2 @@ +pub mod setup; mod test; - -use anyhow::bail; -use rstest::rstest; -use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, Url}; -use std::ops::Range; -use std::sync::Mutex; -use std::{ - collections::HashMap, - future::Future, - path::{Path, PathBuf}, - process::{Child, Command, Output, Stdio}, - str::FromStr, - time::Duration, -}; -use tempfile::TempDir; - -pub struct MadaraCmd { - process: Option, - ready: bool, - json_rpc: Option>, - rpc_url: Url, - tempdir: TempDir, - _port: MadaraPortNum, -} - -async fn wait_for_cond>>(mut cond: impl FnMut() -> F, duration: Duration) { - let mut attempt = 0; - loop { - let Err(err) = cond().await else { - break; - }; - - attempt += 1; - if attempt >= 10 { - panic!("No answer from the node after {attempt} attempts: {:#}", err) - } - - tokio::time::sleep(duration).await; - } -} - -impl MadaraCmd { - pub fn wait_with_output(mut self) -> Output { - self.process.take().unwrap().wait_with_output().unwrap() - } - - pub fn json_rpc(&mut self) -> &JsonRpcClient { - self.json_rpc.get_or_insert_with(|| JsonRpcClient::new(HttpTransport::new(self.rpc_url.clone()))) - } - - pub fn db_dir(&self) -> &Path { - self.tempdir.path() - } - - pub async fn wait_for_ready(&mut self) -> &mut Self { - let endpoint = self.rpc_url.join("/health").unwrap(); - wait_for_cond( - || async { - let res = reqwest::get(endpoint.clone()).await?; - res.error_for_status()?; - anyhow::Ok(()) - }, - Duration::from_millis(1000), - ) - .await; - self.ready = true; - self - } - - pub async fn wait_for_sync_to(&mut self, block_n: u64) -> &mut Self { - let rpc = self.json_rpc(); - wait_for_cond( - || async { - match rpc.block_hash_and_number().await { - Ok(got) => { - if got.block_number < block_n { - bail!("got block_n {}, expected {block_n}", got.block_number); - } - anyhow::Ok(()) - } - Err(err) => bail!(err), - } - }, - Duration::from_millis(5000), - ) - .await; - self - } -} - -impl Drop for MadaraCmd { - fn drop(&mut self) { - let Some(mut child) = self.process.take() else { return }; - let kill = || { - let mut kill = Command::new("kill").args(["-s", "TERM", &child.id().to_string()]).spawn()?; - kill.wait()?; - anyhow::Ok(()) - }; - if let Err(_err) = kill() { - child.kill().unwrap() - } - child.wait().unwrap(); - } -} - -// this really should use unix sockets, sad - -const PORT_RANGE: Range = 19944..20000; - -struct AvailablePorts> { - to_reuse: Vec, - next: I, -} - -lazy_static::lazy_static! { - static ref AVAILABLE_PORTS: Mutex>> = Mutex::new(AvailablePorts { to_reuse: vec![], next: PORT_RANGE }); -} - -pub struct MadaraPortNum(pub u16); -impl Drop for MadaraPortNum { - fn drop(&mut self) { - let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); - guard.to_reuse.push(self.0); - } -} - -pub fn get_port() -> MadaraPortNum { - let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); - if let Some(el) = guard.to_reuse.pop() { - return MadaraPortNum(el); - } - MadaraPortNum(guard.next.next().expect("no more port to use")) -} - -pub struct MadaraCmdBuilder { - args: Vec, - env: HashMap, - tempdir: TempDir, - port: MadaraPortNum, -} - -impl Default for MadaraCmdBuilder { - fn default() -> Self { - Self::new() - } -} - -impl MadaraCmdBuilder { - pub fn new() -> Self { - Self { - args: Default::default(), - env: Default::default(), - tempdir: TempDir::with_prefix("madara-test").unwrap(), - port: get_port(), - } - } - - pub fn args(mut self, args: impl IntoIterator>) -> Self { - self.args = args.into_iter().map(Into::into).collect(); - self - } - - pub fn env(mut self, env: impl IntoIterator, impl Into)>) -> Self { - self.env = env.into_iter().map(|(k, v)| (k.into(), v.into())).collect(); - self - } - - pub fn run(self) -> MadaraCmd { - let target_bin = option_env!("COVERAGE_BIN").unwrap_or("./target/debug/madara"); - let target_bin = PathBuf::from_str(target_bin).expect("target bin is not a path"); - if !target_bin.exists() { - panic!("No binary to run: {:?}", target_bin) - } - - let process = Command::new(target_bin) - .envs(self.env) - .args(self.args.into_iter().chain([ - "--telemetry-disabled".into(), // important: disable telemetry!! - "--no-prometheus".into(), - "--base-path".into(), - format!("{}", self.tempdir.as_ref().display()), - "--rpc-port".into(), - format!("{}", self.port.0), - ])) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); - - MadaraCmd { - process: Some(process), - ready: false, - json_rpc: None, - rpc_url: Url::parse(&format!("http://127.0.0.1:{}/", self.port.0)).unwrap(), - tempdir: self.tempdir, - _port: self.port, - } - } -} - -use rstest::fixture; -use std::env; - -#[fixture] -pub fn set_workdir() { - dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); - env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); -} - -#[ignore] -#[rstest] -#[tokio::test] -async fn madara_can_sync_a_few_blocks(_set_workdir: ()) { - use starknet::core::types::{BlockHashAndNumber, Felt}; - - let _ = env_logger::builder().is_test(true).try_init(); - let mut node = MadaraCmdBuilder::new() - .args([ - "--network", - "sepolia", - "--no-sync-polling", - "--n-blocks-to-sync", - "20", - "--no-l1-sync", - "--preset=sepolia", - ]) - .run(); - node.wait_for_ready().await; - node.wait_for_sync_to(19).await; - - assert_eq!( - node.json_rpc().block_hash_and_number().await.unwrap(), - BlockHashAndNumber { - // https://sepolia.voyager.online/block/19 - block_hash: Felt::from_hex_unchecked("0x4177d1ba942a4ab94f86a476c06f0f9e02363ad410cdf177c54064788c9bcb5"), - block_number: 19 - } - ); -} diff --git a/crates/settlement-clients/starknet/src/tests/setup.rs b/crates/settlement-clients/starknet/src/tests/setup.rs new file mode 100644 index 00000000..cd4f7702 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/setup.rs @@ -0,0 +1,167 @@ +use std::ops::Range; +use std::sync::Mutex; +use std::{ + collections::HashMap, + future::Future, + path::{Path, PathBuf}, + process::{Child, Command, Stdio}, + str::FromStr, + time::Duration, +}; +use tempfile::TempDir; +use url::Url; + +// This code has been take from [here](https://github.com/madara-alliance/madara/blob/main/crates/tests/src/lib.rs) +// and modified to fit the needs of this project. +pub struct MadaraCmd { + pub process: Option, + pub ready: bool, + pub rpc_url: Url, + pub tempdir: TempDir, + pub _port: MadaraPortNum, +} + +async fn wait_for_cond>>(mut cond: impl FnMut() -> F, duration: Duration) { + let mut attempt = 0; + loop { + let Err(err) = cond().await else { + break; + }; + + attempt += 1; + if attempt >= 10 { + panic!("No answer from the node after {attempt} attempts: {:#}", err) + } + + tokio::time::sleep(duration).await; + } +} + +impl MadaraCmd { + pub fn db_dir(&self) -> &Path { + self.tempdir.path() + } + + pub async fn wait_for_ready(&mut self) -> &mut Self { + let endpoint = self.rpc_url.join("/health").unwrap(); + wait_for_cond( + || async { + let res = reqwest::get(endpoint.clone()).await?; + res.error_for_status()?; + anyhow::Ok(()) + }, + Duration::from_millis(1000), + ) + .await; + self.ready = true; + self + } +} + +impl Drop for MadaraCmd { + fn drop(&mut self) { + let Some(mut child) = self.process.take() else { return }; + let kill = || { + let mut kill = Command::new("kill").args(["-s", "TERM", &child.id().to_string()]).spawn()?; + kill.wait()?; + anyhow::Ok(()) + }; + if let Err(_err) = kill() { + child.kill().unwrap() + } + child.wait().unwrap(); + } +} + +// this really should use unix sockets, sad + +const PORT_RANGE: Range = 19944..20000; + +struct AvailablePorts> { + to_reuse: Vec, + next: I, +} + +lazy_static::lazy_static! { + static ref AVAILABLE_PORTS: Mutex>> = Mutex::new(AvailablePorts { to_reuse: vec![], next: PORT_RANGE }); +} + +pub struct MadaraPortNum(pub u16); +impl Drop for MadaraPortNum { + fn drop(&mut self) { + let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); + guard.to_reuse.push(self.0); + } +} + +pub fn get_port() -> MadaraPortNum { + let mut guard = AVAILABLE_PORTS.lock().expect("poisoned lock"); + if let Some(el) = guard.to_reuse.pop() { + return MadaraPortNum(el); + } + MadaraPortNum(guard.next.next().expect("no more port to use")) +} + +pub struct MadaraCmdBuilder { + args: Vec, + env: HashMap, + tempdir: TempDir, + port: MadaraPortNum, +} + +impl Default for MadaraCmdBuilder { + fn default() -> Self { + Self::new() + } +} + +impl MadaraCmdBuilder { + pub fn new() -> Self { + Self { + args: Default::default(), + env: Default::default(), + tempdir: TempDir::with_prefix("madara-test").unwrap(), + port: get_port(), + } + } + + pub fn args(mut self, args: impl IntoIterator>) -> Self { + self.args = args.into_iter().map(Into::into).collect(); + self + } + + pub fn env(mut self, env: impl IntoIterator, impl Into)>) -> Self { + self.env = env.into_iter().map(|(k, v)| (k.into(), v.into())).collect(); + self + } + + pub fn run(self) -> MadaraCmd { + let target_bin = option_env!("COVERAGE_BIN").unwrap_or("./target/debug/madara"); + let target_bin = PathBuf::from_str(target_bin).expect("target bin is not a path"); + if !target_bin.exists() { + panic!("No binary to run: {:?}", target_bin) + } + + let process = Command::new(target_bin) + .envs(self.env) + .args(self.args.into_iter().chain([ + "--telemetry-disabled".into(), // important: disable telemetry!! + "--no-prometheus".into(), + "--base-path".into(), + format!("{}", self.tempdir.as_ref().display()), + "--rpc-port".into(), + format!("{}", self.port.0), + ])) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + + MadaraCmd { + process: Some(process), + ready: false, + rpc_url: Url::parse(&format!("http://127.0.0.1:{}/", self.port.0)).unwrap(), + tempdir: self.tempdir, + _port: self.port, + } + } +} diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 5b949a24..8c3b6c1e 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,4 +1,4 @@ -use super::{MadaraCmd, MadaraCmdBuilder}; +use super::setup::{MadaraCmd, MadaraCmdBuilder}; use crate::StarknetSettlementClient; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; @@ -22,7 +22,6 @@ use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; pub async fn spin_up_madara() -> MadaraCmd { - println!("Spinning up madara"); env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); println!("Current working directory: {:?}", env::current_dir().unwrap()); let mut node = MadaraCmdBuilder::new() @@ -84,7 +83,7 @@ async fn wait_for_tx( #[fixture] async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { - let _ = env_logger::builder().is_test(true).try_init(); + // let _ = env_logger::builder().is_test(true).try_init(); dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); let madara_process = spin_up_madara().await; @@ -137,7 +136,7 @@ async fn test_deployment(#[future] setup: (SingleOwnerAccount Date: Tue, 1 Oct 2024 08:53:26 +0530 Subject: [PATCH 049/104] fix e2e test flow --- Cargo.lock | 1 + crates/settlement-clients/starknet/Cargo.toml | 1 + crates/settlement-clients/starknet/src/tests/test.rs | 2 +- e2e-tests/tests.rs | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5966292..db883978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9018,6 +9018,7 @@ dependencies = [ "crypto-bigint 0.5.5", "dotenvy", "lazy_static", + "log", "mockall", "reqwest 0.12.7", "rstest 0.22.0", diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index a1def74e..48b84a52 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -22,6 +22,7 @@ tempfile.workspace = true tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } +log = { workspace = true } [dev-dependencies] async-std = { version = "1.13.0", features = ["attributes"] } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 8c3b6c1e..7e55c0bb 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -22,6 +22,7 @@ use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; pub async fn spin_up_madara() -> MadaraCmd { + log::trace!("Spinning up Madara"); env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); println!("Current working directory: {:?}", env::current_dir().unwrap()); let mut node = MadaraCmdBuilder::new() @@ -83,7 +84,6 @@ async fn wait_for_tx( #[fixture] async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { - // let _ = env_logger::builder().is_test(true).try_init(); dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); let madara_process = spin_up_madara().await; diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 3c4f198b..16a43821 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -326,7 +326,7 @@ pub async fn mock_starknet_get_nonce(starknet_client: &mut StarknetClient, l2_bl let vec: Vec = serde_json::from_str(&contents).unwrap(); for ele in vec { - let address = Felt::from_hex(&ele.address).unwrap(); + let address = Felt::from_dec_str(&ele.address).expect("Failed to convert to felt"); let hex_field_element = vec_u8_to_hex_string(&address.to_bytes_be()); let response = json!({ "id": 640641,"jsonrpc":"2.0","result": ele.nonce }); From d62935451ff24ebde49197f9550268cb89a54886 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 09:05:22 +0530 Subject: [PATCH 050/104] fix toml lint --- crates/settlement-clients/starknet/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/settlement-clients/starknet/Cargo.toml b/crates/settlement-clients/starknet/Cargo.toml index 48b84a52..e701955e 100644 --- a/crates/settlement-clients/starknet/Cargo.toml +++ b/crates/settlement-clients/starknet/Cargo.toml @@ -12,6 +12,7 @@ color-eyre = { workspace = true } crypto-bigint = { workspace = true } dotenvy.workspace = true lazy_static = { workspace = true } +log = { workspace = true } mockall = { workspace = true } reqwest = { workspace = true } rstest = { workspace = true } @@ -22,7 +23,6 @@ tempfile.workspace = true tokio = { workspace = true } url = { workspace = true } utils = { workspace = true } -log = { workspace = true } [dev-dependencies] async-std = { version = "1.13.0", features = ["attributes"] } From 7dbeccbb6c2cc00c6468ec8cb3a973479cd94c40 Mon Sep 17 00:00:00 2001 From: Mehul Chauhan Date: Tue, 1 Oct 2024 09:22:46 +0530 Subject: [PATCH 051/104] Update crates/settlement-clients/starknet/src/tests/test.rs Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> --- crates/settlement-clients/starknet/src/tests/test.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 7e55c0bb..16c62bab 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -88,7 +88,6 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle let madara_process = spin_up_madara().await; env::set_var("STARKNET_RPC_URL", madara_process.rpc_url.to_string()); - println!("RPC url {:?}", madara_process.rpc_url); let env_settings = EnvSettingsProvider::default(); let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); From 1bbf8dc01686ef381cc4eca7797dc208e7a09185 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 09:23:40 +0530 Subject: [PATCH 052/104] changed envs --- .env.example | 3 +-- .env.test | 3 +-- crates/settlement-clients/starknet/src/lib.rs | 4 ++-- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index d0aa131c..c9850525 100644 --- a/.env.example +++ b/.env.example @@ -53,6 +53,5 @@ STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS= ##### STARKNET SETTLEMENT TEST ##### STARKNET_PRIVATE_KEY= -STARKNET_PUBLIC_KEY= +STARKNET_ACCOUNT_ADDRESS= STARKNET_RPC_URL= -MADARA_BINARY_PATH= \ No newline at end of file diff --git a/.env.test b/.env.test index c09446ac..26c82787 100644 --- a/.env.test +++ b/.env.test @@ -66,6 +66,5 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" ##### STARKNET SETTLEMENT TEST ##### STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 -STARKNET_PUBLIC_KEY=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 -STARKNET_RPC_URL=http://localhost:9944 +STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 MADARA_BINARY_PATH="/path/to/madara" diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 62f0daa8..539e9685 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -40,7 +40,7 @@ pub struct StarknetSettlementClient { pub tx_finality_retry_delay_in_seconds: u64, } -pub const ENV_PUBLIC_KEY: &str = "STARKNET_PUBLIC_KEY"; +pub const ENV_ACCOUNT_ADDRESS: &str = "STARKNET_ACCOUNT_ADDRESS"; pub const ENV_PRIVATE_KEY: &str = "STARKNET_PRIVATE_KEY"; const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; @@ -54,7 +54,7 @@ impl StarknetSettlementClient { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.rpc_url.clone()))); - let public_key = settings.get_settings_or_panic(ENV_PUBLIC_KEY); + let public_key = settings.get_settings_or_panic(ENV_ACCOUNT_ADDRESS); let signer_address = Felt::from_hex(&public_key).expect("invalid signer address"); // TODO: Very insecure way of building the signer. Needs to be adjusted. diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 7e55c0bb..1501e1e0 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -98,7 +98,7 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle let signer = LocalWallet::from(SigningKey::from_secret_scalar( Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).expect("Invalid private key"), )); - let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PUBLIC_KEY")).unwrap(); + let address = Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_ACCOUNT_ADDRESS")).unwrap(); let chain_id = provider.chain_id().await.unwrap(); let mut account = SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New); From 4ba8d6f932280194398dcaac5123dbb7ec9c10b4 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 12:34:48 +0530 Subject: [PATCH 053/104] add conversion function and test --- .env.example | 1 - .../starknet/src/conversion.rs | 23 +++++++++++++++++++ crates/settlement-clients/starknet/src/lib.rs | 8 ++++--- .../starknet/src/tests/test.rs | 19 ++++++--------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index c9850525..0154d41b 100644 --- a/.env.example +++ b/.env.example @@ -54,4 +54,3 @@ STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS= ##### STARKNET SETTLEMENT TEST ##### STARKNET_PRIVATE_KEY= STARKNET_ACCOUNT_ADDRESS= -STARKNET_RPC_URL= diff --git a/crates/settlement-clients/starknet/src/conversion.rs b/crates/settlement-clients/starknet/src/conversion.rs index 3c3f34fb..067dd4b3 100644 --- a/crates/settlement-clients/starknet/src/conversion.rs +++ b/crates/settlement-clients/starknet/src/conversion.rs @@ -7,3 +7,26 @@ pub(crate) fn slice_slice_u8_to_vec_field(slices: &[[u8; 32]]) -> Vec { pub(crate) fn slice_u8_to_field(slice: &[u8; 32]) -> Felt { Felt::from_bytes_be_slice(slice) } + +pub(crate) fn u64_from_felt(number: Felt) -> u64 { + let bytes = number.to_bytes_be(); + + for x in &bytes[0..24] { + assert!(*x == 0, "byte should be zero, cannot convert to Felt"); + } + u64::from_be_bytes(bytes[24..32].try_into().unwrap()) +} + +#[test] +fn test_u64_from_from_felt_ok() { + let number = 10.into(); + let converted = u64_from_felt(number); + assert!(converted == 10u64, "Should be able to convert"); +} + +#[test] +#[should_panic(expected = "byte should be zero, cannot convert to Felt")] +fn test_u64_from_from_felt_panic() { + let number = Felt::MAX; + u64_from_felt(number); +} diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 539e9685..8904e6ea 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -31,10 +31,12 @@ use settlement_client_interface::{SettlementClient, SettlementVerificationStatus use utils::settings::Settings; use crate::config::StarknetSettlementConfig; -use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field}; +use crate::conversion::{slice_slice_u8_to_vec_field, slice_u8_to_field, u64_from_felt}; + +pub type LocalWalletSignerMiddleware = Arc>, LocalWallet>>; pub struct StarknetSettlementClient { - pub account: Arc>, LocalWallet>>, + pub account: LocalWalletSignerMiddleware, pub starknet_core_contract_client: StarknetCoreContractClient, pub core_contract_address: Felt, pub tx_finality_retry_delay_in_seconds: u64, @@ -208,7 +210,7 @@ impl SettlementClient for StarknetSettlementClient { return Err(eyre!("Could not fetch last block number from core contract.")); } - Ok(u64::from_le_bytes(block_number[0].to_bytes_le()[0..8].try_into().unwrap())) + Ok(u64_from_felt(block_number[0])) } /// Returns the nonce for the wallet in use. diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 564c6140..cfbe7d4f 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,5 +1,5 @@ use super::setup::{MadaraCmd, MadaraCmdBuilder}; -use crate::StarknetSettlementClient; +use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; use starknet::{ @@ -45,11 +45,7 @@ pub async fn spin_up_madara() -> MadaraCmd { node } -async fn wait_for_tx( - account: &SingleOwnerAccount, LocalWallet>, - transaction_hash: Felt, - duration: Duration, -) -> bool { +async fn wait_for_tx(account: &LocalWalletSignerMiddleware, transaction_hash: Felt, duration: Duration) -> bool { let mut attempt = 0; loop { attempt += 1; @@ -83,7 +79,7 @@ async fn wait_for_tx( } #[fixture] -async fn setup() -> (SingleOwnerAccount, LocalWallet>, MadaraCmd) { +async fn setup() -> (LocalWalletSignerMiddleware, MadaraCmd) { dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); let madara_process = spin_up_madara().await; @@ -92,8 +88,7 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle let env_settings = EnvSettingsProvider::default(); let rpc_url = Url::parse(&env_settings.get_settings_or_panic("STARKNET_RPC_URL")).unwrap(); - // let provider = JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:9944").unwrap())); - let provider: JsonRpcClient = JsonRpcClient::new(HttpTransport::new(rpc_url)); + let provider = Arc::new(JsonRpcClient::new(HttpTransport::new(rpc_url))); let signer = LocalWallet::from(SigningKey::from_secret_scalar( Felt::from_hex(&env_settings.get_settings_or_panic("STARKNET_PRIVATE_KEY")).expect("Invalid private key"), )); @@ -105,12 +100,12 @@ async fn setup() -> (SingleOwnerAccount, LocalWalle // `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest // block. Optionally change the target block to pending with the following line: account.set_block_id(BlockId::Tag(BlockTag::Pending)); - (account, madara_process) + (Arc::new(account), madara_process) } #[rstest] #[tokio::test] -async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { +async fn test_deployment(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { let (account, _madara_process) = setup.await; let account = Arc::new(account); @@ -152,7 +147,7 @@ async fn test_deployment(#[future] setup: (SingleOwnerAccount, LocalWallet>, MadaraCmd)) { +async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { let (account, _madara_process) = setup.await; let account = Arc::new(account); From 1c399683355b55089914d3882741e35b899f739b Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 12:37:18 +0530 Subject: [PATCH 054/104] remove redundant test --- .../starknet/src/tests/test.rs | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index cfbe7d4f..417bfc1a 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -103,48 +103,6 @@ async fn setup() -> (LocalWalletSignerMiddleware, MadaraCmd) { (Arc::new(account), madara_process) } -#[rstest] -#[tokio::test] -async fn test_deployment(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { - let (account, _madara_process) = setup.await; - let account = Arc::new(account); - - let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); - let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); - let sierra_class: SierraClass = serde_json::from_reader( - std::fs::File::open(contract_path.join("mock_contracts_Piltover.contract_class.json")) - .expect("Could not open sierra class file"), - ) - .expect("Failed to parse SierraClass"); - - let compiled_class: CompiledClass = serde_json::from_reader( - std::fs::File::open(contract_path.join("mock_contracts_Piltover.compiled_contract_class.json")) - .expect("Could not open compiled class file"), - ) - .expect("Failed to parse CompiledClass"); - - let flattened_class = sierra_class.clone().flatten().unwrap(); - let compiled_class_hash = compiled_class.class_hash().unwrap(); - - let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = - account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); - println!("declare tx hash {:?}", declare_tx_hash); - - let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; - assert!(is_success, "Declare trasactiion failed"); - - let contract_factory = ContractFactory::new(flattened_class.class_hash(), account.clone()); - let deploy_v1 = contract_factory.deploy_v1(vec![], felt!("1122"), false); - let deployed_address = deploy_v1.deployed_address(); - - env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string()); - let InvokeTransactionResult { transaction_hash: deploy_tx_hash } = - deploy_v1.send().await.expect("Unable to deploy contract"); - - let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; - assert!(is_success, "Deploy trasaction failed"); -} - #[rstest] #[tokio::test] async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { From dd0a579738430e9ad452bfb0625f2f0d93c2dd5b Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 13:33:39 +0530 Subject: [PATCH 055/104] update workflow commit hash --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index cac81c8c..e8e6714a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -76,7 +76,7 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara # Replace with your first repository - ref: main # Replace with your branch name + ref: '0be628b9baef536a724c9b1f6cf4e76a4e25e4de' # Replace with your branch name path: madara - name: Build Madara From 975ea22d11ca0ce620eaa3dea336d036f59ff61b Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 14:21:03 +0530 Subject: [PATCH 056/104] change commit and add prettierignore --- .github/workflows/coverage.yml | 2 +- .prettierignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .prettierignore diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index e8e6714a..23174574 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -76,7 +76,7 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara # Replace with your first repository - ref: '0be628b9baef536a724c9b1f6cf4e76a4e25e4de' # Replace with your branch name + ref: "0be628b9baef536a724c9b1f6cf4e76a4e25e4de" # Replace with your branch name path: madara - name: Build Madara diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..2f7896d1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +target/ From 93a7aee3375bbec857c3a00b0c00a1d5df168d89 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Tue, 1 Oct 2024 15:11:13 +0530 Subject: [PATCH 057/104] nonce implementaion and optimise code --- crates/settlement-clients/starknet/src/lib.rs | 31 ++++++++----------- .../starknet/src/tests/test.rs | 1 - 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 8904e6ea..14f737f0 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -138,23 +138,18 @@ impl SettlementClient for StarknetSettlementClient { let execution_result = tx_receipt.receipt.execution_result(); let status = execution_result.status(); - if tx_receipt.block.is_pending() { - match status { - TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Pending), - TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( - "Pending tx {} has been reverted: {}", - tx_hash, - execution_result.revert_reason().unwrap() - ))), - } - } else { - match status { - TransactionExecutionStatus::Succeeded => Ok(SettlementVerificationStatus::Verified), - TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( - "Tx {} has been reverted: {}", - tx_hash, - execution_result.revert_reason().unwrap() - ))), + match status { + TransactionExecutionStatus::Reverted => Ok(SettlementVerificationStatus::Rejected(format!( + "Transaction {} has been reverted: {}", + tx_hash, + execution_result.revert_reason().unwrap() + ))), + TransactionExecutionStatus::Succeeded => { + if tx_receipt.block.is_pending() { + Ok(SettlementVerificationStatus::Pending) + } else { + Ok(SettlementVerificationStatus::Verified) + } } } } @@ -215,7 +210,7 @@ impl SettlementClient for StarknetSettlementClient { /// Returns the nonce for the wallet in use. async fn get_nonce(&self) -> Result { - todo!("Yet to impl nonce call for Starknet.") + Ok(u64_from_felt(self.account.get_nonce().await?)) } } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 417bfc1a..3d7d4754 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -107,7 +107,6 @@ async fn setup() -> (LocalWalletSignerMiddleware, MadaraCmd) { #[tokio::test] async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { let (account, _madara_process) = setup.await; - let account = Arc::new(account); let project_root = Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(3).unwrap(); let contract_path = project_root.join("crates/settlement-clients/starknet/src/tests/mock_contracts/target/dev"); From 3fd9dc2adf65f18f186ba671dd04ac0833a6b0a7 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 12:04:38 +0530 Subject: [PATCH 058/104] remove coverage bin env --- .../starknet/src/tests/setup.rs | 9 +++++---- .../starknet/src/tests/test.rs | 18 ++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/setup.rs b/crates/settlement-clients/starknet/src/tests/setup.rs index cd4f7702..efa05c30 100644 --- a/crates/settlement-clients/starknet/src/tests/setup.rs +++ b/crates/settlement-clients/starknet/src/tests/setup.rs @@ -1,11 +1,11 @@ +use std::env; use std::ops::Range; use std::sync::Mutex; use std::{ collections::HashMap, future::Future, path::{Path, PathBuf}, - process::{Child, Command, Stdio}, - str::FromStr, + process::{Child, Command}, time::Duration, }; use tempfile::TempDir; @@ -136,8 +136,9 @@ impl MadaraCmdBuilder { } pub fn run(self) -> MadaraCmd { - let target_bin = option_env!("COVERAGE_BIN").unwrap_or("./target/debug/madara"); - let target_bin = PathBuf::from_str(target_bin).expect("target bin is not a path"); + let target_bin = env::var("MADARA_BINARY_PATH").expect("failed to get binary path"); + let target_bin = PathBuf::from(target_bin); + if !target_bin.exists() { panic!("No binary to run: {:?}", target_bin) } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 3d7d4754..aa7cb253 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -21,24 +21,20 @@ use std::time::Duration; use utils::settings::env::EnvSettingsProvider; use utils::settings::Settings; +#[fixture] pub async fn spin_up_madara() -> MadaraCmd { + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); log::trace!("Spinning up Madara"); - env::set_current_dir(env::var("MADARA_BINARY_PATH").unwrap()).expect("Failed to set working directory"); - println!("Current working directory: {:?}", env::current_dir().unwrap()); let mut node = MadaraCmdBuilder::new() .args([ - "--network", - "devnet", "--no-sync-polling", - "--authority", "--devnet", - "--preset=test", + "--preset=devnet", "--no-l1-sync", "--rpc-cors", "all", "--chain-config-override", - "--block-time", - "1", + "block_time=1", ]) .run(); node.wait_for_ready().await; @@ -79,10 +75,8 @@ async fn wait_for_tx(account: &LocalWalletSignerMiddleware, transaction_hash: Fe } #[fixture] -async fn setup() -> (LocalWalletSignerMiddleware, MadaraCmd) { - dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); - - let madara_process = spin_up_madara().await; +async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddleware, MadaraCmd) { + let madara_process = spin_up_madara.await; env::set_var("STARKNET_RPC_URL", madara_process.rpc_url.to_string()); let env_settings = EnvSettingsProvider::default(); From 378849827ff4896efe5900f3b7979d3e8310ec50 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 12:09:21 +0530 Subject: [PATCH 059/104] changed to logs --- crates/settlement-clients/starknet/src/tests/setup.rs | 2 +- crates/settlement-clients/starknet/src/tests/test.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/setup.rs b/crates/settlement-clients/starknet/src/tests/setup.rs index efa05c30..d90a7333 100644 --- a/crates/settlement-clients/starknet/src/tests/setup.rs +++ b/crates/settlement-clients/starknet/src/tests/setup.rs @@ -5,7 +5,7 @@ use std::{ collections::HashMap, future::Future, path::{Path, PathBuf}, - process::{Child, Command}, + process::{Child, Command, Stdio}, time::Duration, }; use tempfile::TempDir; diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index aa7cb253..b42c2ed5 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -121,7 +121,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let DeclareTransactionResult { transaction_hash: declare_tx_hash, class_hash: _ } = account.declare_v2(Arc::new(flattened_class.clone()), compiled_class_hash).send().await.unwrap(); - println!("declare tx hash {:?}", declare_tx_hash); + log::debug!("declare tx hash {:?}", declare_tx_hash); let is_success = wait_for_tx(&account, declare_tx_hash, Duration::from_secs(2)).await; assert!(is_success, "Declare trasactiion failed"); @@ -147,7 +147,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) .await .expect("Sending Update state"); - println!("update state tx hash {:?}", update_state_tx_hash); + log::debug!("update state tx hash {:?}", update_state_tx_hash); let is_success = wait_for_tx( &account, From db2df7a68d147fef0f3ccab32575a137e8199d9f Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 17:00:37 +0530 Subject: [PATCH 060/104] added preset file --- .github/workflows/coverage.yml | 8 +++++ .../starknet/src/tests/preset.yml | 34 +++++++++++++++++++ .../starknet/src/tests/test.rs | 4 +-- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 crates/settlement-clients/starknet/src/tests/preset.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 23174574..55f64b9b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -91,6 +91,14 @@ jobs: run: | wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip + - name: Making proper presets + run: | + cd madara/crates/primitives/chain_config/resources/ + export current_path=$(path) + cd - + yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .key + ".json"))' crates/settlement-clients/starknet/src/tests/preset.yml + yq '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml + - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} diff --git a/crates/settlement-clients/starknet/src/tests/preset.yml b/crates/settlement-clients/starknet/src/tests/preset.yml new file mode 100644 index 00000000..dd26723a --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/preset.yml @@ -0,0 +1,34 @@ +chain_name: "Madara" +chain_id: "MADARA_DEVNET" +native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" +parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" +versioned_constants: + "0.13.0": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json" + "0.13.1": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json" + "0.13.1.1": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json" + "0.13.2": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json" +latest_protocol_version: "0.13.2" +block_time: "1s" +pending_block_update_time: 200ms +execution_batch_size: 16 +bouncer_config: + block_max_capacity: + builtin_count: + add_mod: 18446744073709551615 + bitwise: 18446744073709551615 + ecdsa: 18446744073709551615 + ec_op: 18446744073709551615 + keccak: 18446744073709551615 + mul_mod: 18446744073709551615 + pedersen: 18446744073709551615 + poseidon: 18446744073709551615 + range_check: 18446744073709551615 + range_check96: 18446744073709551615 + gas: 5000000 + message_segment_length: 18446744073709551615 + n_events: 18446744073709551615 + n_steps: 40000000 + state_diff_size: 131072 +sequencer_address: "0x123" +max_nonce_for_validation_skip: 2 +eth_core_contract_address: "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057" diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index b42c2ed5..90a5d440 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -29,12 +29,10 @@ pub async fn spin_up_madara() -> MadaraCmd { .args([ "--no-sync-polling", "--devnet", - "--preset=devnet", "--no-l1-sync", + "--chain-config-path=/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/preset.yml", "--rpc-cors", "all", - "--chain-config-override", - "block_time=1", ]) .run(); node.wait_for_ready().await; From 0a577928256923682c8dc299228d2dfeb7bb8c72 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 17:43:02 +0530 Subject: [PATCH 061/104] update versioned constants path --- crates/settlement-clients/starknet/src/tests/preset.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/preset.yml b/crates/settlement-clients/starknet/src/tests/preset.yml index dd26723a..65f92706 100644 --- a/crates/settlement-clients/starknet/src/tests/preset.yml +++ b/crates/settlement-clients/starknet/src/tests/preset.yml @@ -3,10 +3,10 @@ chain_id: "MADARA_DEVNET" native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" versioned_constants: - "0.13.0": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json" - "0.13.1": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json" - "0.13.1.1": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json" - "0.13.2": "../../../../orchestrator/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json" + "0.13.0": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json" + "0.13.1": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json" + "0.13.1.1": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json" + "0.13.2": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json" latest_protocol_version: "0.13.2" block_time: "1s" pending_block_update_time: 200ms From f9203e5283eebe47b44cd0c1ffd793b83d5aef35 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 18:00:51 +0530 Subject: [PATCH 062/104] fix current_path --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 55f64b9b..dff6ce13 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -94,7 +94,7 @@ jobs: - name: Making proper presets run: | cd madara/crates/primitives/chain_config/resources/ - export current_path=$(path) + export current_path=$(pwd) cd - yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .key + ".json"))' crates/settlement-clients/starknet/src/tests/preset.yml yq '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml From 767d76677cc2e2c9a5bb683634c1939e0ed8b660 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 18:14:49 +0530 Subject: [PATCH 063/104] should do inplace replacement --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dff6ce13..09122fb5 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -97,7 +97,7 @@ jobs: export current_path=$(pwd) cd - yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .key + ".json"))' crates/settlement-clients/starknet/src/tests/preset.yml - yq '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml + yq -i '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml - name: Run llvm-cov tests env: From 81ab43e0694c83e49049202ce504820c64c0fe8e Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 18:27:35 +0530 Subject: [PATCH 064/104] fix base path --- .github/workflows/coverage.yml | 5 ++--- crates/settlement-clients/starknet/src/tests/preset.yml | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 09122fb5..8f9b6582 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -82,7 +82,6 @@ jobs: - name: Build Madara working-directory: madara run: | - cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test @@ -93,10 +92,10 @@ jobs: - name: Making proper presets run: | - cd madara/crates/primitives/chain_config/resources/ + cd madara/ export current_path=$(pwd) cd - - yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .key + ".json"))' crates/settlement-clients/starknet/src/tests/preset.yml + yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .value))' crates/settlement-clients/starknet/src/tests/preset.yml yq -i '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml - name: Run llvm-cov tests diff --git a/crates/settlement-clients/starknet/src/tests/preset.yml b/crates/settlement-clients/starknet/src/tests/preset.yml index 65f92706..2555cd91 100644 --- a/crates/settlement-clients/starknet/src/tests/preset.yml +++ b/crates/settlement-clients/starknet/src/tests/preset.yml @@ -3,10 +3,10 @@ chain_id: "MADARA_DEVNET" native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" versioned_constants: - "0.13.0": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json" - "0.13.1": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json" - "0.13.1.1": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json" - "0.13.2": "crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json" + "0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json" + "0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json" + "0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json" + "0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json" latest_protocol_version: "0.13.2" block_time: "1s" pending_block_update_time: 200ms From 781ae30df536ac550b01d861d7368a1a65c9d583 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 18:34:06 +0530 Subject: [PATCH 065/104] fix final coverage workflow --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 8f9b6582..eb1a4148 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -82,6 +82,7 @@ jobs: - name: Build Madara working-directory: madara run: | + cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test @@ -95,8 +96,7 @@ jobs: cd madara/ export current_path=$(pwd) cd - - yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + .value))' crates/settlement-clients/starknet/src/tests/preset.yml - yq -i '.versioned_constants[] |= sub("\.", "_") ' crates/settlement-clients/starknet/src/tests/preset.yml + yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' crates/settlement-clients/starknet/src/tests/preset.yml - name: Run llvm-cov tests env: From ed64847159633e9f98a812a7539db878d56ae728 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 18:38:21 +0530 Subject: [PATCH 066/104] update preset --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index eb1a4148..af3c802c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -91,7 +91,7 @@ jobs: run: | wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - - name: Making proper presets + - name: Make preset file run: | cd madara/ export current_path=$(pwd) From 51d03453c06b6548a515ad2a745a641c373ce6c7 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 19:11:33 +0530 Subject: [PATCH 067/104] change runner --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index af3c802c..30765ce7 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,7 +8,7 @@ on: jobs: coverage: - runs-on: ubuntu-latest + runs-on: karnot-arc-runner-set services: localstack: From 06089b9d82e01289e567ec9d6f59e3bf78b53189 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 19:24:24 +0530 Subject: [PATCH 068/104] install dependencies --- .github/workflows/coverage.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 30765ce7..bfe383c3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -30,7 +30,11 @@ jobs: # selecting a toolchain either by action or manual `rustup` calls should happen # before the plugin, as the cache uses the current rustc version as its cache key - - run: rustup show + - name: Install necessary deps + run: | + sudo apt update + sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From 8880c4e650cd8ba1c8cbef1afa7de8b843e3bad6 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 19:26:07 +0530 Subject: [PATCH 069/104] run linter --- .env.test | 2 ++ .github/workflows/coverage.yml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 26c82787..01a69f64 100644 --- a/.env.test +++ b/.env.test @@ -68,3 +68,5 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 MADARA_BINARY_PATH="/path/to/madara" +MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/target/debug/madara" + diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bfe383c3..8139497a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,7 +35,6 @@ jobs: sudo apt update sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git - - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: From 29645dbc5f050a0086c36845b735227299df6b62 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 19:26:53 +0530 Subject: [PATCH 070/104] remove path --- .env.test | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.test b/.env.test index 01a69f64..c9f4783b 100644 --- a/.env.test +++ b/.env.test @@ -68,5 +68,4 @@ ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io" STARKNET_PRIVATE_KEY=0x76f2ccdb23f29bc7b69278e947c01c6160a31cf02c19d06d0f6e5ab1d768b86 STARKNET_ACCOUNT_ADDRESS=0x3bb306a004034dba19e6cf7b161e7a4fef64bc1078419e8ad1876192f0b8cd1 MADARA_BINARY_PATH="/path/to/madara" -MADARA_BINARY_PATH="/Users/bytezorvin/work/karnot/madara/target/debug/madara" From 5c8941ea84c1e80d72a1e04fb449f8010e3cd47d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 19:28:08 +0530 Subject: [PATCH 071/104] reword --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 8139497a..a23f77e0 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -30,7 +30,7 @@ jobs: # selecting a toolchain either by action or manual `rustup` calls should happen # before the plugin, as the cache uses the current rustc version as its cache key - - name: Install necessary deps + - name: Install necessary dependencies run: | sudo apt update sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git From 5ca8d3adf5a5deb197a426a933f0dd0644b658c9 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 20:28:56 +0530 Subject: [PATCH 072/104] change default rust --- .github/workflows/coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index a23f77e0..bdbc40de 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -41,6 +41,7 @@ jobs: profile: minimal toolchain: stable override: true + default: true - name: Rust Cache uses: Swatinem/rust-cache@v2 From 31faee0d705284082b395390aa9d777794d2ca65 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 20:38:54 +0530 Subject: [PATCH 073/104] rerun --- .github/workflows/coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bdbc40de..4b3dfa07 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -66,7 +66,8 @@ jobs: - name: Install nextest uses: taiki-e/install-action@nextest - - uses: software-mansion/setup-scarb@v1 + - name: Setup scarb + uses: software-mansion/setup-scarb@v1 with: scarb-version: "2.8.2" From 144ac3172c7c86068ce19f7641d2befe1a036d9f Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 20:49:03 +0530 Subject: [PATCH 074/104] install libclang --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4b3dfa07..b4343dbe 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -33,7 +33,7 @@ jobs: - name: Install necessary dependencies run: | sudo apt update - sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git + sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From 86190f9481368bd2f97d89095c4b420a30c316d8 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 21:03:17 +0530 Subject: [PATCH 075/104] install more dependencies --- .github/workflows/coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b4343dbe..4620e383 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -33,7 +33,8 @@ jobs: - name: Install necessary dependencies run: | sudo apt update - sudo apt install -y gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev + sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From ee0a88f888247bdb9a01e3f664ebcbef717c5c4f Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 21:23:56 +0530 Subject: [PATCH 076/104] install yq --- .github/workflows/coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4620e383..dd7ed3ae 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,7 +34,8 @@ jobs: run: | sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - + wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\ + chmod +x /usr/bin/yq - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From b2e156266feb4725a38e44a2329587a7fbe8acbe Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 21:32:35 +0530 Subject: [PATCH 077/104] install via snap --- .github/workflows/coverage.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dd7ed3ae..15af3bc1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,8 +34,7 @@ jobs: run: | sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\ - chmod +x /usr/bin/yq + snap install yq - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From 8bc8e0353c57d66be2bcd34e4fe3b0d8131cac95 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Thu, 3 Oct 2024 21:35:43 +0530 Subject: [PATCH 078/104] install snap first --- .github/workflows/coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 15af3bc1..fece6cd4 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,6 +34,7 @@ jobs: run: | sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev + sudo apt-get install snapd snap install yq - name: Install Rust toolchain From f9fe926a56264495780a720907f6b08cb236bfb3 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 00:46:28 +0530 Subject: [PATCH 079/104] add y flag --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fece6cd4..9f22d12d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,8 +34,8 @@ jobs: run: | sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - sudo apt-get install snapd - snap install yq + sudo apt-get -y install snapd + snap install -y yq - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From 06f23ec2a63be145a867048a88efd33b6e6ce33a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 00:51:04 +0530 Subject: [PATCH 080/104] no y flag --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9f22d12d..19b270f7 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,7 +35,7 @@ jobs: sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev sudo apt-get -y install snapd - snap install -y yq + snap install yq - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From ed0d2045f176310d60ecab86eebfaaa4fa978840 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 00:56:40 +0530 Subject: [PATCH 081/104] enable snapd service --- .github/workflows/coverage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 19b270f7..11f0ca8e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,6 +35,9 @@ jobs: sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev sudo apt-get -y install snapd + sudo systemctl unmask snapd.service + sudo systemctl enable snapd.service + sudo systemctl start snapd.service snap install yq - name: Install Rust toolchain From 2fca4d1cad80e23518c4eb46187cf5b52aa07630 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 01:11:47 +0530 Subject: [PATCH 082/104] use gh action for yq --- .github/workflows/coverage.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 11f0ca8e..7ce5015a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,11 +34,6 @@ jobs: run: | sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - sudo apt-get -y install snapd - sudo systemctl unmask snapd.service - sudo systemctl enable snapd.service - sudo systemctl start snapd.service - snap install yq - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -102,11 +97,10 @@ jobs: wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - name: Make preset file - run: | - cd madara/ - export current_path=$(pwd) - cd - - yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' crates/settlement-clients/starknet/src/tests/preset.yml + working_dir: madara + uses: mikefarah/yq@master + with: + cmd: export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml - name: Run llvm-cov tests env: From 73c92218dff287db5b314443b294bbaa4cc6a3c5 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 01:12:48 +0530 Subject: [PATCH 083/104] yq action --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 7ce5015a..9ba5c1e5 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -96,7 +96,7 @@ jobs: run: | wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - - name: Make preset file + - name: Make preset file with yq action working_dir: madara uses: mikefarah/yq@master with: From bdeedbff83dabf5f54755d250cdaed5dced43f7c Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 01:21:04 +0530 Subject: [PATCH 084/104] remove working-directory --- .github/workflows/coverage.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9ba5c1e5..12af0912 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -97,10 +97,9 @@ jobs: wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - name: Make preset file with yq action - working_dir: madara uses: mikefarah/yq@master with: - cmd: export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml + cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml - name: Run llvm-cov tests env: From 85d711eaa6ffdb9df2814f9b21ff690828d8b63a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 14:29:06 +0530 Subject: [PATCH 085/104] check env variable --- .github/workflows/coverage.yml | 3 +-- crates/orchestrator/src/tests/config.rs | 8 ++++++-- crates/orchestrator/src/tests/data_storage/mod.rs | 14 ++++++++++---- .../src/tests/jobs/state_update_job/mod.rs | 10 ++++++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 12af0912..32b43c3d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -87,7 +87,6 @@ jobs: - name: Build Madara working-directory: madara run: | - cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test @@ -104,7 +103,7 @@ jobs: - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests + run: RUST_LOG=debug RUST_BACKTRACE=1 cargo test test_put_and_get_data_s3 --workspace --exclude=e2e-tests - name: Coveralls uses: coverallsapp/github-action@v2 diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 10085d1b..aa408d99 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -16,6 +16,7 @@ use crate::data_storage::MockDataStorage; use crate::database::{Database, MockDatabase}; use crate::queue::{MockQueueProvider, QueueProvider}; use crate::tests::common::{create_sns_arn, create_sqs_queues, drop_database}; +use std::env; use utils::settings::env::EnvSettingsProvider; // Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html @@ -157,8 +158,11 @@ impl TestConfigBuilder { } pub async fn build(self) -> TestConfigBuilderReturns { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env.test file"); - + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); + dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env.test file"); + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); let settings_provider = EnvSettingsProvider {}; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&settings_provider).await))); diff --git a/crates/orchestrator/src/tests/data_storage/mod.rs b/crates/orchestrator/src/tests/data_storage/mod.rs index a041d18f..684a3578 100644 --- a/crates/orchestrator/src/tests/data_storage/mod.rs +++ b/crates/orchestrator/src/tests/data_storage/mod.rs @@ -1,8 +1,8 @@ -use bytes::Bytes; -use serde_json::json; - use crate::tests::config::{ConfigType, TestConfigBuilder}; +use bytes::Bytes; use rstest::rstest; +use serde_json::json; +use std::env; /// This test checks the ability to put and get data from AWS S3 using `AWSS3`. /// It puts JSON data into a test bucket and retrieves it, verifying the data @@ -13,7 +13,13 @@ use rstest::rstest; async fn test_put_and_get_data_s3() -> color_eyre::Result<()> { let services = TestConfigBuilder::new().configure_storage_client(ConfigType::Actual).build().await; - dotenvy::from_filename("../.env.test")?; + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); + + dotenvy::from_filename_override("../.env.test")?; + + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); let s3_client = services.config.storage(); diff --git a/crates/orchestrator/src/tests/jobs/state_update_job/mod.rs b/crates/orchestrator/src/tests/jobs/state_update_job/mod.rs index ebb27f76..7186c6a8 100644 --- a/crates/orchestrator/src/tests/jobs/state_update_job/mod.rs +++ b/crates/orchestrator/src/tests/jobs/state_update_job/mod.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use std::fs; use std::path::PathBuf; +use std::{env, fs}; use assert_matches::assert_matches; use bytes::Bytes; @@ -61,7 +61,13 @@ async fn test_process_job_works( use crate::tests::config::ConfigType; - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); + + dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env file"); + + let aws_region = env::var("AWS_REGION").unwrap(); + println!("AWS_REGION: {}", aws_region); // Mocking the settlement client. let mut settlement_client = MockSettlementClient::new(); From a1ec248f3399565814e25aad85354557606e164d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 14:42:53 +0530 Subject: [PATCH 086/104] fix ci --- .github/workflows/coverage.yml | 3 ++- crates/orchestrator/src/tests/config.rs | 6 +----- crates/orchestrator/src/tests/data_storage/mod.rs | 7 ------- crates/prover-services/sharp-service/tests/lib.rs | 4 ++-- crates/settlement-clients/ethereum/src/tests/mod.rs | 2 +- e2e-tests/tests.rs | 2 +- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 32b43c3d..12af0912 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -87,6 +87,7 @@ jobs: - name: Build Madara working-directory: madara run: | + cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test @@ -103,7 +104,7 @@ jobs: - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - run: RUST_LOG=debug RUST_BACKTRACE=1 cargo test test_put_and_get_data_s3 --workspace --exclude=e2e-tests + run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests - name: Coveralls uses: coverallsapp/github-action@v2 diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index aa408d99..96122e99 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -16,7 +16,6 @@ use crate::data_storage::MockDataStorage; use crate::database::{Database, MockDatabase}; use crate::queue::{MockQueueProvider, QueueProvider}; use crate::tests::common::{create_sns_arn, create_sqs_queues, drop_database}; -use std::env; use utils::settings::env::EnvSettingsProvider; // Inspiration : https://rust-unofficial.github.io/patterns/patterns/creational/builder.html @@ -158,11 +157,8 @@ impl TestConfigBuilder { } pub async fn build(self) -> TestConfigBuilderReturns { - let aws_region = env::var("AWS_REGION").unwrap(); - println!("AWS_REGION: {}", aws_region); dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env.test file"); - let aws_region = env::var("AWS_REGION").unwrap(); - println!("AWS_REGION: {}", aws_region); + let settings_provider = EnvSettingsProvider {}; let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(&settings_provider).await))); diff --git a/crates/orchestrator/src/tests/data_storage/mod.rs b/crates/orchestrator/src/tests/data_storage/mod.rs index 684a3578..ff8a9663 100644 --- a/crates/orchestrator/src/tests/data_storage/mod.rs +++ b/crates/orchestrator/src/tests/data_storage/mod.rs @@ -2,7 +2,6 @@ use crate::tests::config::{ConfigType, TestConfigBuilder}; use bytes::Bytes; use rstest::rstest; use serde_json::json; -use std::env; /// This test checks the ability to put and get data from AWS S3 using `AWSS3`. /// It puts JSON data into a test bucket and retrieves it, verifying the data @@ -13,14 +12,8 @@ use std::env; async fn test_put_and_get_data_s3() -> color_eyre::Result<()> { let services = TestConfigBuilder::new().configure_storage_client(ConfigType::Actual).build().await; - let aws_region = env::var("AWS_REGION").unwrap(); - println!("AWS_REGION: {}", aws_region); - dotenvy::from_filename_override("../.env.test")?; - let aws_region = env::var("AWS_REGION").unwrap(); - println!("AWS_REGION: {}", aws_region); - let s3_client = services.config.storage(); let mock_data = json!( diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 0171af93..89e87d72 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -16,7 +16,7 @@ mod constants; #[rstest] #[tokio::test] async fn prover_client_submit_task_works() { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); + dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env file"); let server = MockServer::start(); let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); @@ -55,7 +55,7 @@ async fn prover_client_submit_task_works() { #[case(CairoJobStatus::ONCHAIN)] #[tokio::test] async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { - dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); + dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env file"); let server = MockServer::start(); let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 41b33a1e..693430b6 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -86,7 +86,7 @@ impl EthereumTestBuilder { pub async fn build(&self) -> EthereumTest { // Load ENV vars - dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + dotenvy::from_filename_override(&*ENV_FILE_PATH).expect("Could not load .env.test file."); // Setup Anvil let anvil = match self.fork_block { diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 16a43821..836d0f20 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -122,7 +122,7 @@ impl Setup { async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. - dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); let mut setup_config = Setup::new().await; // Setup S3 From af28cb2a7eeb2e31e05e3cea68c2888261574b7c Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 14:50:38 +0530 Subject: [PATCH 087/104] remove override in e2e --- e2e-tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 836d0f20..16a43821 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -122,7 +122,7 @@ impl Setup { async fn test_orchestrator_workflow(#[case] l2_block_number: String) { // Fetching the env vars from the test env file as these will be used in // setting up of the test and during orchestrator run too. - dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); let mut setup_config = Setup::new().await; // Setup S3 From cfd2389d257c40ea100628704f3b115c304d7c5b Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 15:07:14 +0530 Subject: [PATCH 088/104] dotenvy::from_filename --- .github/workflows/coverage.yml | 1 - crates/prover-services/sharp-service/tests/lib.rs | 4 ++-- crates/settlement-clients/ethereum/src/tests/mod.rs | 2 +- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 12af0912..a4bf04d1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -87,7 +87,6 @@ jobs: - name: Build Madara working-directory: madara run: | - cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 89e87d72..0171af93 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -16,7 +16,7 @@ mod constants; #[rstest] #[tokio::test] async fn prover_client_submit_task_works() { - dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env file"); + dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let server = MockServer::start(); let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); @@ -55,7 +55,7 @@ async fn prover_client_submit_task_works() { #[case(CairoJobStatus::ONCHAIN)] #[tokio::test] async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { - dotenvy::from_filename_override("../.env.test").expect("Failed to load the .env file"); + dotenvy::from_filename("../.env.test").expect("Failed to load the .env file"); let server = MockServer::start(); let sharp_service = SharpProverService::with_test_settings(&EnvSettingsProvider {}, server.port()); diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 693430b6..41b33a1e 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -86,7 +86,7 @@ impl EthereumTestBuilder { pub async fn build(&self) -> EthereumTest { // Load ENV vars - dotenvy::from_filename_override(&*ENV_FILE_PATH).expect("Could not load .env.test file."); + dotenvy::from_filename(&*ENV_FILE_PATH).expect("Could not load .env.test file."); // Setup Anvil let anvil = match self.fork_block { diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 90a5d440..e2f9af15 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -23,7 +23,7 @@ use utils::settings::Settings; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { - dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); + dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); log::trace!("Spinning up Madara"); let mut node = MadaraCmdBuilder::new() .args([ From 393d41735dfdfe7416e6d7b3a9a5ddd84fc351ce Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 15:41:42 +0530 Subject: [PATCH 089/104] should also build --- .github/workflows/coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index a4bf04d1..bb7a6b57 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -87,6 +87,7 @@ jobs: - name: Build Madara working-directory: madara run: | + cargo build current_path=$(pwd) echo -e " MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test @@ -103,7 +104,7 @@ jobs: - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests + run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast - name: Coveralls uses: coverallsapp/github-action@v2 From 3e8f48571f090ba4193c299bd1114a0f6ed18a7c Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 16:13:35 +0530 Subject: [PATCH 090/104] env override --- .github/workflows/coverage.yml | 128 ++++++++++++++++----------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bb7a6b57..1739a3aa 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,47 +35,47 @@ jobs: sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - default: true - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - - - name: Check Anvil Installation - run: | - if command -v anvil &> /dev/null - then - echo "Anvil is installed. Version information:" - anvil --version - else - echo "Anvil is not installed or not in PATH" - exit 1 - fi - - - name: Install cargo-llvm-cov & nextest - uses: taiki-e/install-action@cargo-llvm-cov - - - name: Install nextest - uses: taiki-e/install-action@nextest - - - name: Setup scarb - uses: software-mansion/setup-scarb@v1 - with: - scarb-version: "2.8.2" - - - name: Build Mock Contracts using Scarb - run: | - cd crates/settlement-clients/starknet/src/tests/mock_contracts - scarb fmt --check - scarb build + # - name: Install Rust toolchain + # uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + # default: true + + # - name: Rust Cache + # uses: Swatinem/rust-cache@v2 + + # - name: Install Foundry + # uses: foundry-rs/foundry-toolchain@v1 + + # - name: Check Anvil Installation + # run: | + # if command -v anvil &> /dev/null + # then + # echo "Anvil is installed. Version information:" + # anvil --version + # else + # echo "Anvil is not installed or not in PATH" + # exit 1 + # fi + + # - name: Install cargo-llvm-cov & nextest + # uses: taiki-e/install-action@cargo-llvm-cov + + # - name: Install nextest + # uses: taiki-e/install-action@nextest + + # - name: Setup scarb + # uses: software-mansion/setup-scarb@v1 + # with: + # scarb-version: "2.8.2" + + # - name: Build Mock Contracts using Scarb + # run: | + # cd crates/settlement-clients/starknet/src/tests/mock_contracts + # scarb fmt --check + # scarb build - name: Checkout Madara uses: actions/checkout@v4 @@ -87,27 +87,27 @@ jobs: - name: Build Madara working-directory: madara run: | - cargo build - current_path=$(pwd) + # cargo build echo -e " - MADARA_BINARY_PATH=\"$current_path\"" >> ../.env.test - - - name: Getting neccesary files for testing - run: | - wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - - - name: Make preset file with yq action - uses: mikefarah/yq@master - with: - cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml - - - name: Run llvm-cov tests - env: - ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast - - - name: Coveralls - uses: coverallsapp/github-action@v2 - with: - files: lcov.info - debug: true + MADARA_BINARY_PATH=\"$(pwd)/target/debug/madara\"" >> ../.env.test + cat ../.env.test + + # - name: Getting neccesary files for testing + # run: | + # wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip + + # - name: Make preset file with yq action + # uses: mikefarah/yq@master + # with: + # cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml + + # - name: Run llvm-cov tests + # env: + # ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} + # run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast + + # - name: Coveralls + # uses: coverallsapp/github-action@v2 + # with: + # files: lcov.info + # debug: true From 7b9acfa84ec8bd6f3822797e5a5c7f4bca207b0b Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 16:15:58 +0530 Subject: [PATCH 091/104] ignore flaky test --- crates/prover-services/sharp-service/tests/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index 0171af93..62f8c635 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -52,6 +52,7 @@ async fn prover_client_submit_task_works() { #[case(CairoJobStatus::IN_PROGRESS)] #[case(CairoJobStatus::NOT_CREATED)] #[case(CairoJobStatus::PROCESSED)] +#[ignore] #[case(CairoJobStatus::ONCHAIN)] #[tokio::test] async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobStatus) { From ec9c600ca4fbf9ff33ec4f0156db558b0300774e Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 16:19:10 +0530 Subject: [PATCH 092/104] restart ci --- .github/workflows/coverage.yml | 120 ++++++++++++++++----------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1739a3aa..407b8cac 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,47 +35,47 @@ jobs: sudo apt update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libclang-dev - # - name: Install Rust toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - # default: true - - # - name: Rust Cache - # uses: Swatinem/rust-cache@v2 - - # - name: Install Foundry - # uses: foundry-rs/foundry-toolchain@v1 - - # - name: Check Anvil Installation - # run: | - # if command -v anvil &> /dev/null - # then - # echo "Anvil is installed. Version information:" - # anvil --version - # else - # echo "Anvil is not installed or not in PATH" - # exit 1 - # fi - - # - name: Install cargo-llvm-cov & nextest - # uses: taiki-e/install-action@cargo-llvm-cov - - # - name: Install nextest - # uses: taiki-e/install-action@nextest - - # - name: Setup scarb - # uses: software-mansion/setup-scarb@v1 - # with: - # scarb-version: "2.8.2" - - # - name: Build Mock Contracts using Scarb - # run: | - # cd crates/settlement-clients/starknet/src/tests/mock_contracts - # scarb fmt --check - # scarb build + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + default: true + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + + - name: Check Anvil Installation + run: | + if command -v anvil &> /dev/null + then + echo "Anvil is installed. Version information:" + anvil --version + else + echo "Anvil is not installed or not in PATH" + exit 1 + fi + + - name: Install cargo-llvm-cov & nextest + uses: taiki-e/install-action@cargo-llvm-cov + + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Setup scarb + uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.8.2" + + - name: Build Mock Contracts using Scarb + run: | + cd crates/settlement-clients/starknet/src/tests/mock_contracts + scarb fmt --check + scarb build - name: Checkout Madara uses: actions/checkout@v4 @@ -92,22 +92,22 @@ jobs: MADARA_BINARY_PATH=\"$(pwd)/target/debug/madara\"" >> ../.env.test cat ../.env.test - # - name: Getting neccesary files for testing - # run: | - # wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - - # - name: Make preset file with yq action - # uses: mikefarah/yq@master - # with: - # cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml - - # - name: Run llvm-cov tests - # env: - # ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - # run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast - - # - name: Coveralls - # uses: coverallsapp/github-action@v2 - # with: - # files: lcov.info - # debug: true + - name: Getting neccesary files for testing + run: | + wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip + + - name: Make preset file with yq action + uses: mikefarah/yq@master + with: + cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml + + - name: Run llvm-cov tests + env: + ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} + run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast + + - name: Coveralls + uses: coverallsapp/github-action@v2 + with: + files: lcov.info + debug: true From 8c2848fe982b11d38f26b59f3b87cd886feb52bb Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 16:23:11 +0530 Subject: [PATCH 093/104] enable cargo build --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 407b8cac..93be08fe 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -87,7 +87,7 @@ jobs: - name: Build Madara working-directory: madara run: | - # cargo build + cargo build echo -e " MADARA_BINARY_PATH=\"$(pwd)/target/debug/madara\"" >> ../.env.test cat ../.env.test From 029b27f447314eba329a42a3e57b0c940309fa20 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 16:50:17 +0530 Subject: [PATCH 094/104] override in starknet client --- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index e2f9af15..90a5d440 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -23,7 +23,7 @@ use utils::settings::Settings; #[fixture] pub async fn spin_up_madara() -> MadaraCmd { - dotenvy::from_filename(".env.test").expect("Failed to load the .env file"); + dotenvy::from_filename_override(".env.test").expect("Failed to load the .env file"); log::trace!("Spinning up Madara"); let mut node = MadaraCmdBuilder::new() .args([ From dd96afec64d4b5aadc4ae448166a79222fa6690a Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 17:18:05 +0530 Subject: [PATCH 095/104] only starknet --- .github/workflows/coverage.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 93be08fe..9e42f756 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -104,7 +104,10 @@ jobs: - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast + # run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast + run: | + cat crates/settlement-clients/starknet/src/tests/preset.yml + RUST_LOG=trace cargo test -p starknet-settlement-client -- --test-threads=1 --no-fail-fast - name: Coveralls uses: coverallsapp/github-action@v2 From be9ee7707fd146a1a16b0b0236cf0c7f42705dcf Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 17:48:00 +0530 Subject: [PATCH 096/104] retry running --- crates/settlement-clients/starknet/src/tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 90a5d440..38628622 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -30,7 +30,7 @@ pub async fn spin_up_madara() -> MadaraCmd { "--no-sync-polling", "--devnet", "--no-l1-sync", - "--chain-config-path=/Users/bytezorvin/work/karnot/orchestrator/crates/settlement-clients/starknet/src/tests/preset.yml", + "--chain-config-path=./crates/settlement-clients/starknet/src/tests/preset.yml", "--rpc-cors", "all", ]) From cb68ba01b1ae25d41a4a475033fe043103eb6b50 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 18:20:13 +0530 Subject: [PATCH 097/104] test settle should work --- .github/workflows/coverage.yml | 11 +- .../starknet/src/tests/preset.yml | 8 +- .../resources/versioned_constants_13_0.json | 509 ++++++++++++++++ .../resources/versioned_constants_13_1.json | 555 +++++++++++++++++ .../resources/versioned_constants_13_1_1.json | 554 +++++++++++++++++ .../resources/versioned_constants_13_2.json | 563 ++++++++++++++++++ .../starknet/src/tests/test.rs | 2 +- 7 files changed, 2190 insertions(+), 12 deletions(-) create mode 100644 crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json create mode 100644 crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json create mode 100644 crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json create mode 100644 crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9e42f756..fd434797 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -88,19 +88,16 @@ jobs: working-directory: madara run: | cargo build + mv target/debug/madara ../madara-binary + cd .. echo -e " - MADARA_BINARY_PATH=\"$(pwd)/target/debug/madara\"" >> ../.env.test - cat ../.env.test + MADARA_BINARY_PATH=\"$(pwd)/madara-binary\"" >> .env.test + cat .env.test - name: Getting neccesary files for testing run: | wget -P ./crates/prover-services/sharp-service/tests/artifacts https://madara-orchestrator-sharp-pie.s3.amazonaws.com/238996-SN.zip - - name: Make preset file with yq action - uses: mikefarah/yq@master - with: - cmd: cd madara && export current_path=$(pwd) && yq -i '.versioned_constants |= with_entries(.value = (env(current_path) + "/" + .value))' ../crates/settlement-clients/starknet/src/tests/preset.yml - - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} diff --git a/crates/settlement-clients/starknet/src/tests/preset.yml b/crates/settlement-clients/starknet/src/tests/preset.yml index 2555cd91..058d37f5 100644 --- a/crates/settlement-clients/starknet/src/tests/preset.yml +++ b/crates/settlement-clients/starknet/src/tests/preset.yml @@ -3,10 +3,10 @@ chain_id: "MADARA_DEVNET" native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" versioned_constants: - "0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json" - "0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json" - "0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json" - "0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json" + "0.13.0": "./src/tests/resources/versioned_constants_13_0.json" + "0.13.1": "./src/tests/resources/versioned_constants_13_1.json" + "0.13.1.1": "./src/tests/resources/versioned_constants_13_1_1.json" + "0.13.2": "./src/tests/resources/versioned_constants_13_2.json" latest_protocol_version: "0.13.2" block_time: "1s" pending_block_update_time: 200ms diff --git a/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json new file mode 100644 index 00000000..da8bc502 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_0.json @@ -0,0 +1,509 @@ +{ + "gateway": { + "max_calldata_length": 4000, + "max_contract_bytecode_size": 61440 + }, + "invoke_tx_max_n_steps": 3000000, + "max_recursion_depth": 50, + "segment_arena_cells": true, + "os_constants": { + "nop_entry_point_offset": -1, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "entry_point_type_constructor": 2, + "l1_handler_version": 0, + "sierra_array_len_bound": 4294967296, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "default_entry_point_selector": 0, + "block_hash_contract_address": 1, + "stored_block_hash_buffer": 10, + "step_gas_cost": 100, + "range_check_gas_cost": 70, + "memory_hole_gas_cost": 10, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "call_contract_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10, + "entry_point_gas_cost": 1 + }, + "deploy_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 200, + "entry_point_gas_cost": 1 + }, + "get_block_hash_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "get_execution_info_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "replace_class_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_read_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_write_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "emit_event_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "send_message_to_l1_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "secp256k1_add_gas_cost": { + "step_gas_cost": 406, + "range_check_gas_cost": 29 + }, + "secp256k1_get_point_from_x_gas_cost": { + "step_gas_cost": 391, + "range_check_gas_cost": 30, + "memory_hole_gas_cost": 20 + }, + "secp256k1_get_xy_gas_cost": { + "step_gas_cost": 239, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256k1_mul_gas_cost": { + "step_gas_cost": 76401, + "range_check_gas_cost": 7045 + }, + "secp256k1_new_gas_cost": { + "step_gas_cost": 475, + "range_check_gas_cost": 35, + "memory_hole_gas_cost": 40 + }, + "secp256r1_add_gas_cost": { + "step_gas_cost": 589, + "range_check_gas_cost": 57 + }, + "secp256r1_get_point_from_x_gas_cost": { + "step_gas_cost": 510, + "range_check_gas_cost": 44, + "memory_hole_gas_cost": 20 + }, + "secp256r1_get_xy_gas_cost": { + "step_gas_cost": 241, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256r1_mul_gas_cost": { + "step_gas_cost": 125240, + "range_check_gas_cost": 13961 + }, + "secp256r1_new_gas_cost": { + "step_gas_cost": 594, + "range_check_gas_cost": 49, + "memory_hole_gas_cost": 40 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, + "error_block_number_out_of_range": "Block number out of range", + "error_out_of_gas": "Out of gas", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "validated": "VALID", + "l1_gas": "L1_GAS", + "l2_gas": "L2_GAS", + "l1_gas_index": 0, + "l2_gas_index": 1 + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0, + "n_steps": 691 + }, + "DelegateCall": { + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0, + "n_steps": 713 + }, + "DelegateL1Handler": { + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0, + "n_steps": 692 + }, + "Deploy": { + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 18 + }, + "n_memory_holes": 0, + "n_steps": 944 + }, + "EmitEvent": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 19 + }, + "GetBlockHash": { + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0, + "n_steps": 74 + }, + "GetBlockNumber": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 40 + }, + "GetBlockTimestamp": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 38 + }, + "GetCallerAddress": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 32 + }, + "GetContractAddress": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 36 + }, + "GetExecutionInfo": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 29 + }, + "GetSequencerAddress": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 34 + }, + "GetTxInfo": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 29 + }, + "GetTxSignature": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 44 + }, + "Keccak": { + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0, + "n_steps": 381 + }, + "LibraryCall": { + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0, + "n_steps": 680 + }, + "LibraryCallL1Handler": { + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0, + "n_steps": 659 + }, + "ReplaceClass": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 73 + }, + "Secp256k1Add": { + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0, + "n_steps": 406 + }, + "Secp256k1GetPointFromX": { + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 20, + "n_steps": 391 + }, + "Secp256k1GetXy": { + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 40, + "n_steps": 239 + }, + "Secp256k1Mul": { + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0, + "n_steps": 76401 + }, + "Secp256k1New": { + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 40, + "n_steps": 475 + }, + "Secp256r1Add": { + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0, + "n_steps": 589 + }, + "Secp256r1GetPointFromX": { + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 20, + "n_steps": 510 + }, + "Secp256r1GetXy": { + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 40, + "n_steps": 241 + }, + "Secp256r1Mul": { + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0, + "n_steps": 125240 + }, + "Secp256r1New": { + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 40, + "n_steps": 594 + }, + "SendMessageToL1": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 84 + }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, + "StorageRead": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 44 + }, + "StorageWrite": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 46 + } + }, + "execute_txs_inner": { + "Declare": { + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 15, + "range_check_builtin": 63 + }, + "n_memory_holes": 0, + "n_steps": 2711 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 15, + "range_check_builtin": 63 + }, + "n_memory_holes": 0, + "n_steps": 2711 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0, + "n_steps": 3628 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0, + "n_steps": 3628 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 80 + }, + "n_memory_holes": 0, + "n_steps": 3382 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 80 + }, + "n_memory_holes": 0, + "n_steps": 3382 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0, + "n_steps": 1069 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0, + "n_steps": 1069 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "add_mod_builtin": [0, 1], + "bitwise_builtin": [32, 100], + "ec_op_builtin": [512, 100], + "ecdsa_builtin": [1024, 100], + "keccak_builtin": [1024, 100], + "mul_mod_builtin": [0, 1], + "n_steps": [5, 1000], + "output_builtin": [0, 1], + "pedersen_builtin": [16, 100], + "poseidon_builtin": [16, 100], + "range_check_builtin": [8, 100], + "range_check96_builtin": [0, 1] + } +} diff --git a/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json new file mode 100644 index 00000000..e4068473 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1.json @@ -0,0 +1,555 @@ +{ + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, + "max_n_emitted_events": 1000 + }, + "gateway": { + "max_calldata_length": 4000, + "max_contract_bytecode_size": 81920 + }, + "invoke_tx_max_n_steps": 4000000, + "l2_resource_gas_costs": { + "gas_per_data_felt": [128, 1000], + "event_key_factor": [2, 1], + "gas_per_code_byte": [875, 1000] + }, + "max_recursion_depth": 50, + "segment_arena_cells": true, + "os_constants": { + "nop_entry_point_offset": -1, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "entry_point_type_constructor": 2, + "l1_handler_version": 0, + "sierra_array_len_bound": 4294967296, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "default_entry_point_selector": 0, + "block_hash_contract_address": 1, + "stored_block_hash_buffer": 10, + "step_gas_cost": 100, + "range_check_gas_cost": 70, + "memory_hole_gas_cost": 10, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "call_contract_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10, + "entry_point_gas_cost": 1 + }, + "deploy_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 200, + "entry_point_gas_cost": 1 + }, + "get_block_hash_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "get_execution_info_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "replace_class_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_read_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_write_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "emit_event_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "send_message_to_l1_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "secp256k1_add_gas_cost": { + "step_gas_cost": 406, + "range_check_gas_cost": 29 + }, + "secp256k1_get_point_from_x_gas_cost": { + "step_gas_cost": 391, + "range_check_gas_cost": 30, + "memory_hole_gas_cost": 20 + }, + "secp256k1_get_xy_gas_cost": { + "step_gas_cost": 239, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256k1_mul_gas_cost": { + "step_gas_cost": 76501, + "range_check_gas_cost": 7045, + "memory_hole_gas_cost": 2 + }, + "secp256k1_new_gas_cost": { + "step_gas_cost": 475, + "range_check_gas_cost": 35, + "memory_hole_gas_cost": 40 + }, + "secp256r1_add_gas_cost": { + "step_gas_cost": 589, + "range_check_gas_cost": 57 + }, + "secp256r1_get_point_from_x_gas_cost": { + "step_gas_cost": 510, + "range_check_gas_cost": 44, + "memory_hole_gas_cost": 20 + }, + "secp256r1_get_xy_gas_cost": { + "step_gas_cost": 241, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256r1_mul_gas_cost": { + "step_gas_cost": 125340, + "range_check_gas_cost": 13961, + "memory_hole_gas_cost": 2 + }, + "secp256r1_new_gas_cost": { + "step_gas_cost": 594, + "range_check_gas_cost": 49, + "memory_hole_gas_cost": 40 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, + "error_block_number_out_of_range": "Block number out of range", + "error_out_of_gas": "Out of gas", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "validated": "VALID", + "l1_gas": "L1_GAS", + "l2_gas": "L2_GAS", + "l1_gas_index": 0, + "l2_gas_index": 1, + "validate_rounding_consts": { + "validate_block_number_rounding": 100, + "validate_timestamp_rounding": 3600 + } + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "n_steps": 760, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "DelegateCall": { + "n_steps": 713, + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "DelegateL1Handler": { + "n_steps": 692, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "Deploy": { + "n_steps": 1012, + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "EmitEvent": { + "n_steps": 61, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetBlockHash": { + "n_steps": 104, + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0 + }, + "GetBlockNumber": { + "n_steps": 40, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetBlockTimestamp": { + "n_steps": 38, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetCallerAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetContractAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetExecutionInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetSequencerAddress": { + "n_steps": 34, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetTxInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetTxSignature": { + "n_steps": 44, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "Keccak": { + "n_steps": 381, + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0 + }, + "LibraryCall": { + "n_steps": 751, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "LibraryCallL1Handler": { + "n_steps": 659, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "ReplaceClass": { + "n_steps": 98, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Secp256k1Add": { + "n_steps": 408, + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetPointFromX": { + "n_steps": 393, + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetXy": { + "n_steps": 205, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256k1Mul": { + "n_steps": 76503, + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0 + }, + "Secp256k1New": { + "n_steps": 459, + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 0 + }, + "Secp256r1Add": { + "n_steps": 591, + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetPointFromX": { + "n_steps": 512, + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetXy": { + "n_steps": 207, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256r1Mul": { + "n_steps": 125342, + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0 + }, + "Secp256r1New": { + "n_steps": 578, + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 0 + }, + "SendMessageToL1": { + "n_steps": 139, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, + "StorageRead": { + "n_steps": 87, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageWrite": { + "n_steps": 89, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "execute_txs_inner": { + "Declare": { + "resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "add_mod_builtin": [0, 1], + "bitwise_builtin": [16, 100], + "ec_op_builtin": [256, 100], + "ecdsa_builtin": [512, 100], + "keccak_builtin": [512, 100], + "mul_mod_builtin": [0, 1], + "n_steps": [25, 10000], + "output_builtin": [0, 1], + "pedersen_builtin": [8, 100], + "poseidon_builtin": [8, 100], + "range_check_builtin": [4, 100], + "range_check96_builtin": [0, 1] + } +} diff --git a/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json new file mode 100644 index 00000000..fd317d73 --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_1_1.json @@ -0,0 +1,554 @@ +{ + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, + "max_n_emitted_events": 1000 + }, + "gateway": { + "max_calldata_length": 5000, + "max_contract_bytecode_size": 81920 + }, + "invoke_tx_max_n_steps": 4000000, + "l2_resource_gas_costs": { + "gas_per_data_felt": [128, 1000], + "event_key_factor": [2, 1], + "gas_per_code_byte": [32, 1000] + }, + "max_recursion_depth": 50, + "os_constants": { + "nop_entry_point_offset": -1, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "entry_point_type_constructor": 2, + "l1_handler_version": 0, + "sierra_array_len_bound": 4294967296, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "default_entry_point_selector": 0, + "block_hash_contract_address": 1, + "stored_block_hash_buffer": 10, + "step_gas_cost": 100, + "range_check_gas_cost": 70, + "memory_hole_gas_cost": 10, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "call_contract_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10, + "entry_point_gas_cost": 1 + }, + "deploy_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 200, + "entry_point_gas_cost": 1 + }, + "get_block_hash_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "get_execution_info_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "replace_class_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_read_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_write_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "emit_event_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "send_message_to_l1_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "secp256k1_add_gas_cost": { + "step_gas_cost": 406, + "range_check_gas_cost": 29 + }, + "secp256k1_get_point_from_x_gas_cost": { + "step_gas_cost": 391, + "range_check_gas_cost": 30, + "memory_hole_gas_cost": 20 + }, + "secp256k1_get_xy_gas_cost": { + "step_gas_cost": 239, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256k1_mul_gas_cost": { + "step_gas_cost": 76501, + "range_check_gas_cost": 7045, + "memory_hole_gas_cost": 2 + }, + "secp256k1_new_gas_cost": { + "step_gas_cost": 475, + "range_check_gas_cost": 35, + "memory_hole_gas_cost": 40 + }, + "secp256r1_add_gas_cost": { + "step_gas_cost": 589, + "range_check_gas_cost": 57 + }, + "secp256r1_get_point_from_x_gas_cost": { + "step_gas_cost": 510, + "range_check_gas_cost": 44, + "memory_hole_gas_cost": 20 + }, + "secp256r1_get_xy_gas_cost": { + "step_gas_cost": 241, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256r1_mul_gas_cost": { + "step_gas_cost": 125340, + "range_check_gas_cost": 13961, + "memory_hole_gas_cost": 2 + }, + "secp256r1_new_gas_cost": { + "step_gas_cost": 594, + "range_check_gas_cost": 49, + "memory_hole_gas_cost": 40 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, + "error_block_number_out_of_range": "Block number out of range", + "error_out_of_gas": "Out of gas", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "validated": "VALID", + "l1_gas": "L1_GAS", + "l2_gas": "L2_GAS", + "l1_gas_index": 0, + "l2_gas_index": 1, + "validate_rounding_consts": { + "validate_block_number_rounding": 100, + "validate_timestamp_rounding": 3600 + } + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "n_steps": 760, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "DelegateCall": { + "n_steps": 713, + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "DelegateL1Handler": { + "n_steps": 692, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "Deploy": { + "n_steps": 1012, + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "EmitEvent": { + "n_steps": 61, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetBlockHash": { + "n_steps": 104, + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0 + }, + "GetBlockNumber": { + "n_steps": 40, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetBlockTimestamp": { + "n_steps": 38, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetCallerAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetContractAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetExecutionInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetSequencerAddress": { + "n_steps": 34, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetTxInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetTxSignature": { + "n_steps": 44, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "Keccak": { + "n_steps": 381, + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0 + }, + "LibraryCall": { + "n_steps": 751, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "LibraryCallL1Handler": { + "n_steps": 659, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "ReplaceClass": { + "n_steps": 98, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Secp256k1Add": { + "n_steps": 408, + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetPointFromX": { + "n_steps": 393, + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetXy": { + "n_steps": 205, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256k1Mul": { + "n_steps": 76503, + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0 + }, + "Secp256k1New": { + "n_steps": 459, + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 0 + }, + "Secp256r1Add": { + "n_steps": 591, + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetPointFromX": { + "n_steps": 512, + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetXy": { + "n_steps": 207, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256r1Mul": { + "n_steps": 125342, + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0 + }, + "Secp256r1New": { + "n_steps": 578, + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 0 + }, + "SendMessageToL1": { + "n_steps": 139, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, + "StorageRead": { + "n_steps": 87, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageWrite": { + "n_steps": 89, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "execute_txs_inner": { + "Declare": { + "resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "add_mod_builtin": [0, 1], + "bitwise_builtin": [16, 100], + "ec_op_builtin": [256, 100], + "ecdsa_builtin": [512, 100], + "keccak_builtin": [512, 100], + "mul_mod_builtin": [0, 1], + "n_steps": [25, 10000], + "output_builtin": [0, 1], + "pedersen_builtin": [8, 100], + "poseidon_builtin": [8, 100], + "range_check_builtin": [4, 100], + "range_check96_builtin": [0, 1] + } +} diff --git a/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json new file mode 100644 index 00000000..4d3a9ceb --- /dev/null +++ b/crates/settlement-clients/starknet/src/tests/resources/versioned_constants_13_2.json @@ -0,0 +1,563 @@ +{ + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, + "max_n_emitted_events": 1000 + }, + "gateway": { + "max_calldata_length": 5000, + "max_contract_bytecode_size": 81920 + }, + "invoke_tx_max_n_steps": 10000000, + "l2_resource_gas_costs": { + "gas_per_data_felt": [128, 1000], + "event_key_factor": [2, 1], + "gas_per_code_byte": [875, 1000] + }, + "disable_cairo0_redeclaration": true, + "max_recursion_depth": 50, + "segment_arena_cells": false, + "os_constants": { + "block_hash_contract_address": 1, + "call_contract_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "default_entry_point_selector": 0, + "deploy_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 200, + "syscall_base_gas_cost": 1 + }, + "emit_event_gas_cost": { + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "entry_point_type_constructor": 2, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "error_block_number_out_of_range": "Block number out of range", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "error_out_of_gas": "Out of gas", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "get_block_hash_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "get_execution_info_gas_cost": { + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "l1_gas": "L1_GAS", + "l1_gas_index": 0, + "l1_handler_version": 0, + "l2_gas": "L2_GAS", + "l2_gas_index": 1, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "sha256_process_block_gas_cost": { + "step_gas_cost": 1852, + "range_check_gas_cost": 65, + "bitwise_builtin_gas_cost": 1115, + "syscall_base_gas_cost": 1 + }, + "memory_hole_gas_cost": 10, + "nop_entry_point_offset": -1, + "range_check_gas_cost": 70, + "bitwise_builtin_gas_cost": 594, + "replace_class_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "secp256k1_add_gas_cost": { + "range_check_gas_cost": 29, + "step_gas_cost": 406 + }, + "secp256k1_get_point_from_x_gas_cost": { + "memory_hole_gas_cost": 20, + "range_check_gas_cost": 30, + "step_gas_cost": 391 + }, + "secp256k1_get_xy_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 11, + "step_gas_cost": 239 + }, + "secp256k1_mul_gas_cost": { + "memory_hole_gas_cost": 2, + "range_check_gas_cost": 7045, + "step_gas_cost": 76501 + }, + "secp256k1_new_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 35, + "step_gas_cost": 475 + }, + "secp256r1_add_gas_cost": { + "range_check_gas_cost": 57, + "step_gas_cost": 589 + }, + "secp256r1_get_point_from_x_gas_cost": { + "memory_hole_gas_cost": 20, + "range_check_gas_cost": 44, + "step_gas_cost": 510 + }, + "secp256r1_get_xy_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 11, + "step_gas_cost": 241 + }, + "secp256r1_mul_gas_cost": { + "memory_hole_gas_cost": 2, + "range_check_gas_cost": 13961, + "step_gas_cost": 125340 + }, + "secp256r1_new_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 49, + "step_gas_cost": 594 + }, + "send_message_to_l1_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "sierra_array_len_bound": 4294967296, + "step_gas_cost": 100, + "storage_read_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "storage_write_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "stored_block_hash_buffer": 10, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_rounding_consts": { + "validate_block_number_rounding": 100, + "validate_timestamp_rounding": 3600 + }, + "validated": "VALID" + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "n_steps": 827, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "DelegateCall": { + "n_steps": 713, + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "DelegateL1Handler": { + "n_steps": 692, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "Deploy": { + "n_steps": 1097, + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 18 + }, + "n_memory_holes": 0 + }, + "EmitEvent": { + "n_steps": 61, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetBlockHash": { + "n_steps": 104, + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0 + }, + "GetBlockNumber": { + "n_steps": 40, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetBlockTimestamp": { + "n_steps": 38, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetCallerAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetContractAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetExecutionInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetSequencerAddress": { + "n_steps": 34, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetTxInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetTxSignature": { + "n_steps": 44, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "Keccak": { + "n_steps": 381, + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0 + }, + "LibraryCall": { + "n_steps": 818, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "LibraryCallL1Handler": { + "n_steps": 659, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "ReplaceClass": { + "n_steps": 98, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Secp256k1Add": { + "n_steps": 410, + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetPointFromX": { + "n_steps": 395, + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetXy": { + "n_steps": 207, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256k1Mul": { + "n_steps": 76505, + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0 + }, + "Secp256k1New": { + "n_steps": 461, + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 0 + }, + "Secp256r1Add": { + "n_steps": 593, + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetPointFromX": { + "n_steps": 514, + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetXy": { + "n_steps": 209, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256r1Mul": { + "n_steps": 125344, + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0 + }, + "Secp256r1New": { + "n_steps": 580, + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 0 + }, + "SendMessageToL1": { + "n_steps": 141, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Sha256ProcessBlock": { + "n_steps": 1855, + "builtin_instance_counter": { + "range_check_builtin": 65, + "bitwise_builtin": 1115 + }, + "n_memory_holes": 0 + }, + "StorageRead": { + "n_steps": 87, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageWrite": { + "n_steps": 89, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "execute_txs_inner": { + "Declare": { + "deprecated_resources": { + "constant": { + "n_steps": 2973, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 53 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 3079, + "builtin_instance_counter": { + "pedersen_builtin": 4, + "range_check_builtin": 58, + "poseidon_builtin": 10 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "deprecated_resources": { + "constant": { + "n_steps": 4015, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 72 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 4137, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 77, + "poseidon_builtin": 10 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "deprecated_resources": { + "constant": { + "n_steps": 3763, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 69 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 3904, + "builtin_instance_counter": { + "pedersen_builtin": 4, + "range_check_builtin": 74, + "poseidon_builtin": 11 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "deprecated_resources": { + "constant": { + "n_steps": 1233, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 16 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 113, + "builtin_instance_counter": { + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "add_mod_builtin": [4, 100], + "bitwise_builtin": [16, 100], + "ec_op_builtin": [256, 100], + "ecdsa_builtin": [512, 100], + "keccak_builtin": [512, 100], + "mul_mod_builtin": [4, 100], + "n_steps": [25, 10000], + "output_builtin": [0, 1], + "pedersen_builtin": [8, 100], + "poseidon_builtin": [8, 100], + "range_check_builtin": [4, 100], + "range_check96_builtin": [4, 100] + } +} diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 38628622..63113cf7 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -30,7 +30,7 @@ pub async fn spin_up_madara() -> MadaraCmd { "--no-sync-polling", "--devnet", "--no-l1-sync", - "--chain-config-path=./crates/settlement-clients/starknet/src/tests/preset.yml", + "--chain-config-path=./src/tests/preset.yml", "--rpc-cors", "all", ]) From 5dc682ba463a9175d120c6c08a3119912df274be Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 18:35:43 +0530 Subject: [PATCH 098/104] remove fail fast --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fd434797..1b845bce 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -104,7 +104,7 @@ jobs: # run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast run: | cat crates/settlement-clients/starknet/src/tests/preset.yml - RUST_LOG=trace cargo test -p starknet-settlement-client -- --test-threads=1 --no-fail-fast + RUST_LOG=trace cargo test -p starknet-settlement-client -- --test-threads=1 - name: Coveralls uses: coverallsapp/github-action@v2 From 7a9ca1a460774155d1c7aff72ac8400eaff15048 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 19:04:55 +0530 Subject: [PATCH 099/104] update blocktime --- crates/settlement-clients/starknet/src/tests/preset.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/settlement-clients/starknet/src/tests/preset.yml b/crates/settlement-clients/starknet/src/tests/preset.yml index 058d37f5..8b812a14 100644 --- a/crates/settlement-clients/starknet/src/tests/preset.yml +++ b/crates/settlement-clients/starknet/src/tests/preset.yml @@ -8,7 +8,7 @@ versioned_constants: "0.13.1.1": "./src/tests/resources/versioned_constants_13_1_1.json" "0.13.2": "./src/tests/resources/versioned_constants_13_2.json" latest_protocol_version: "0.13.2" -block_time: "1s" +block_time: "100ms" pending_block_update_time: 200ms execution_batch_size: 16 bouncer_config: From 3a80afa138b95517a76bbbf2eb31c28c4cb8416d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 19:36:11 +0530 Subject: [PATCH 100/104] change commit --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1b845bce..945c2eae 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -81,7 +81,7 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara # Replace with your first repository - ref: "0be628b9baef536a724c9b1f6cf4e76a4e25e4de" # Replace with your branch name + ref: "0c821aecd1cafc516d00548473fcaddaa4dc0ce4" # Replace with your branch name path: madara - name: Build Madara From 29a6cebef17fd197f9c4c1fa376aeb88a88043a9 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Fri, 4 Oct 2024 19:49:32 +0530 Subject: [PATCH 101/104] run all tests --- .github/workflows/coverage.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 945c2eae..10347dce 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -101,10 +101,7 @@ jobs: - name: Run llvm-cov tests env: ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }} - # run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast - run: | - cat crates/settlement-clients/starknet/src/tests/preset.yml - RUST_LOG=trace cargo test -p starknet-settlement-client -- --test-threads=1 + run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests --no-fail-fast - name: Coveralls uses: coverallsapp/github-action@v2 From cf5f53e807e8bf25752ad4ee992ff570eb0e0f56 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 5 Oct 2024 10:18:13 +0530 Subject: [PATCH 102/104] resolve comments --- .env.example | 2 +- .github/workflows/coverage.yml | 4 ++-- .../starknet/src/conversion.rs | 9 +++++---- crates/settlement-clients/starknet/src/lib.rs | 19 +++---------------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 0154d41b..77a9aba0 100644 --- a/.env.example +++ b/.env.example @@ -51,6 +51,6 @@ STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS= -##### STARKNET SETTLEMENT TEST ##### +##### STARKNET SETTLEMENT (L3s) ##### STARKNET_PRIVATE_KEY= STARKNET_ACCOUNT_ADDRESS= diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 10347dce..e6c2ec01 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -80,8 +80,8 @@ jobs: - name: Checkout Madara uses: actions/checkout@v4 with: - repository: madara-alliance/madara # Replace with your first repository - ref: "0c821aecd1cafc516d00548473fcaddaa4dc0ce4" # Replace with your branch name + repository: madara-alliance/madara + ref: "0c821aecd1cafc516d00548473fcaddaa4dc0ce4" path: madara - name: Build Madara diff --git a/crates/settlement-clients/starknet/src/conversion.rs b/crates/settlement-clients/starknet/src/conversion.rs index 067dd4b3..05be47d4 100644 --- a/crates/settlement-clients/starknet/src/conversion.rs +++ b/crates/settlement-clients/starknet/src/conversion.rs @@ -1,3 +1,4 @@ +use color_eyre::Result; use starknet::core::types::Felt; pub(crate) fn slice_slice_u8_to_vec_field(slices: &[[u8; 32]]) -> Vec { @@ -8,25 +9,25 @@ pub(crate) fn slice_u8_to_field(slice: &[u8; 32]) -> Felt { Felt::from_bytes_be_slice(slice) } -pub(crate) fn u64_from_felt(number: Felt) -> u64 { +pub(crate) fn u64_from_felt(number: Felt) -> Result { let bytes = number.to_bytes_be(); for x in &bytes[0..24] { assert!(*x == 0, "byte should be zero, cannot convert to Felt"); } - u64::from_be_bytes(bytes[24..32].try_into().unwrap()) + Ok(u64::from_be_bytes(bytes[24..32].try_into().unwrap())) } #[test] fn test_u64_from_from_felt_ok() { let number = 10.into(); let converted = u64_from_felt(number); - assert!(converted == 10u64, "Should be able to convert"); + assert!(converted.unwrap() == 10u64, "Should be able to convert"); } #[test] #[should_panic(expected = "byte should be zero, cannot convert to Felt")] fn test_u64_from_from_felt_panic() { let number = Felt::MAX; - u64_from_felt(number); + u64_from_felt(number).unwrap(); } diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 14f737f0..0a09f358 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -205,25 +205,12 @@ impl SettlementClient for StarknetSettlementClient { return Err(eyre!("Could not fetch last block number from core contract.")); } - Ok(u64_from_felt(block_number[0])) + Ok(u64_from_felt(block_number[0]).expect("Failed to convert to u64")) } /// Returns the nonce for the wallet in use. async fn get_nonce(&self) -> Result { - Ok(u64_from_felt(self.account.get_nonce().await?)) - } -} - -#[cfg(test)] -mod test { - - use starknet::core::types::Felt; - #[test] - fn test_felt_conversion() { - let number_in_felt = Felt::from_hex("0x8").unwrap(); - let number_final = u64::from_le_bytes(number_in_felt.to_bytes_le()[0..8].try_into().unwrap()); - println!("{number_in_felt} {number_final}"); - - assert!(number_final == 8, "Should be 8"); + let nonce = self.account.get_nonce().await?; + Ok(u64_from_felt(nonce).expect("Failed to convert to u64")) } } From aaad42543b2f38da56379806438e3e8bd7fe2747 Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 5 Oct 2024 14:49:11 +0530 Subject: [PATCH 103/104] added test for get nonce --- Cargo.lock | 2 +- .../starknet/src/conversion.rs | 11 ++- .../starknet/src/tests/setup.rs | 18 +++-- .../starknet/src/tests/test.rs | 74 +++++++++++-------- 4 files changed, 67 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db883978..0f201535 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5757,7 +5757,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] diff --git a/crates/settlement-clients/starknet/src/conversion.rs b/crates/settlement-clients/starknet/src/conversion.rs index 05be47d4..5324c01f 100644 --- a/crates/settlement-clients/starknet/src/conversion.rs +++ b/crates/settlement-clients/starknet/src/conversion.rs @@ -13,7 +13,9 @@ pub(crate) fn u64_from_felt(number: Felt) -> Result { let bytes = number.to_bytes_be(); for x in &bytes[0..24] { - assert!(*x == 0, "byte should be zero, cannot convert to Felt"); + if *x != 0 { + return Err(color_eyre::Report::msg("byte should be zero, cannot convert to Felt")); + } } Ok(u64::from_be_bytes(bytes[24..32].try_into().unwrap())) } @@ -26,8 +28,11 @@ fn test_u64_from_from_felt_ok() { } #[test] -#[should_panic(expected = "byte should be zero, cannot convert to Felt")] fn test_u64_from_from_felt_panic() { let number = Felt::MAX; - u64_from_felt(number).unwrap(); + let number = u64_from_felt(number); + match number { + Ok(n) => log::info!("Nonce value from get_nonce: {:?}", n), + Err(e) => log::error!("Error getting nonce: {:?}", e), + } } diff --git a/crates/settlement-clients/starknet/src/tests/setup.rs b/crates/settlement-clients/starknet/src/tests/setup.rs index d90a7333..e2b29cee 100644 --- a/crates/settlement-clients/starknet/src/tests/setup.rs +++ b/crates/settlement-clients/starknet/src/tests/setup.rs @@ -21,11 +21,18 @@ pub struct MadaraCmd { pub _port: MadaraPortNum, } -async fn wait_for_cond>>(mut cond: impl FnMut() -> F, duration: Duration) { +pub async fn wait_for_cond>>( + mut cond: impl FnMut() -> F, + duration: Duration, +) -> Result { let mut attempt = 0; loop { - let Err(err) = cond().await else { - break; + let err = match cond().await { + Ok(result) => return Ok(result), + Err(err) => { + // Empty block, no action needed + err + } }; attempt += 1; @@ -48,11 +55,12 @@ impl MadaraCmd { || async { let res = reqwest::get(endpoint.clone()).await?; res.error_for_status()?; - anyhow::Ok(()) + anyhow::Ok(true) }, Duration::from_millis(1000), ) - .await; + .await + .expect("Could not get health of Madara"); self.ready = true; self } diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 63113cf7..1098c4e6 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -1,4 +1,4 @@ -use super::setup::{MadaraCmd, MadaraCmdBuilder}; +use super::setup::{wait_for_cond, MadaraCmd, MadaraCmdBuilder}; use crate::{LocalWalletSignerMiddleware, StarknetSettlementClient}; use rstest::{fixture, rstest}; use settlement_client_interface::SettlementClient; @@ -40,35 +40,37 @@ pub async fn spin_up_madara() -> MadaraCmd { } async fn wait_for_tx(account: &LocalWalletSignerMiddleware, transaction_hash: Felt, duration: Duration) -> bool { - let mut attempt = 0; - loop { - attempt += 1; - if attempt >= 5 { - return false; - } - let reciept = match account.provider().get_transaction_status(transaction_hash).await { - Ok(reciept) => reciept, - Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => { - tokio::time::sleep(duration).await; - continue; + let result = wait_for_cond( + || async { + let receipt = match account.provider().get_transaction_status(transaction_hash).await { + Ok(receipt) => Ok(receipt), + Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound)) => { + Err(anyhow::anyhow!("Transaction not yet received")) + } + _ => Err(anyhow::anyhow!("Unknown error")), + }; + + match receipt { + Ok(TransactionStatus::Received) => Err(anyhow::anyhow!("Transaction not yet received")), + Ok(TransactionStatus::Rejected) => Ok(false), + Ok(TransactionStatus::AcceptedOnL2(status)) => match status { + TransactionExecutionStatus::Succeeded => Ok(true), + TransactionExecutionStatus::Reverted => Ok(false), + }, + Ok(TransactionStatus::AcceptedOnL1(status)) => match status { + TransactionExecutionStatus::Succeeded => Ok(true), + TransactionExecutionStatus::Reverted => Ok(false), + }, + Err(e) => Err(anyhow::anyhow!("Unknown error: {}", e)), } - _ => panic!("Unknown error"), - }; - - match reciept { - TransactionStatus::Received => (), - TransactionStatus::Rejected => return false, - TransactionStatus::AcceptedOnL2(status) => match status { - TransactionExecutionStatus::Succeeded => return true, - TransactionExecutionStatus::Reverted => return false, - }, - TransactionStatus::AcceptedOnL1(status) => match status { - TransactionExecutionStatus::Succeeded => return true, - TransactionExecutionStatus::Reverted => return false, - }, - } - // This is done, since currently madara does not increment nonce for pending transactions - tokio::time::sleep(duration).await; + }, + duration, + ) + .await; + match result { + Ok(true) => true, + Ok(false) => false, + Err(e) => panic!("Error while waiting for transaction: {}", e), } } @@ -169,3 +171,17 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) .expect("failed to call the contract"); assert!(call_result[0] == true.into(), "Should be updated"); } + +#[rstest] +#[tokio::test] +async fn test_get_nonce_works(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { + let (account, _madara_process) = setup.await; + log::info!("Test function started"); + let nonce = account.get_nonce().await; + match &nonce { + Ok(n) => log::info!("Nonce value from get_nonce: {:?}", n), + Err(e) => log::error!("Error getting nonce: {:?}", e), + } + assert!(nonce.is_ok(), "Failed to get nonce"); + log::info!("Test function completed"); +} From 4e685232469883aafa9691c621d2a022ab4c934d Mon Sep 17 00:00:00 2001 From: byteZorvin Date: Sat, 5 Oct 2024 15:19:53 +0530 Subject: [PATCH 104/104] remove log --- crates/settlement-clients/starknet/src/tests/test.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 1098c4e6..f7aa2880 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -176,12 +176,10 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) #[tokio::test] async fn test_get_nonce_works(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) { let (account, _madara_process) = setup.await; - log::info!("Test function started"); let nonce = account.get_nonce().await; match &nonce { Ok(n) => log::info!("Nonce value from get_nonce: {:?}", n), Err(e) => log::error!("Error getting nonce: {:?}", e), } assert!(nonce.is_ok(), "Failed to get nonce"); - log::info!("Test function completed"); }