From 422fd16dc906c97977c2250340341d62b900b9c1 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Tue, 20 Aug 2024 08:57:53 +0530 Subject: [PATCH] update: fixes --- crates/settlement-clients/ethereum/src/lib.rs | 25 +++++++++---------- .../ethereum/src/tests/mod.rs | 22 +++++++++------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 9726eed9..6fbc3c31 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -102,7 +102,7 @@ impl EthereumSettlementClient { #[cfg(test)] pub fn with_test_settings( provider: RootProvider>, - core_contract_address: Option
, + core_contract_address: Address, rpc_url: Url, impersonate_account: Option
, ) -> Self { @@ -114,13 +114,6 @@ impl EthereumSettlementClient { let fill_provider = Arc::new(ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url)); - let core_contract_address = if let Some(core_contract_address) = core_contract_address { - core_contract_address - } else { - // dummy address - Address::from_str("0x0").unwrap() - }; - let core_contract_client = StarknetValidityContractClient::new(core_contract_address, fill_provider); EthereumSettlementClient { @@ -249,8 +242,13 @@ impl SettlementClient for EthereumSettlementClient { let txn_request: TransactionRequest = tx_envelope.into(); #[cfg(test)] - let txn_request = - test_config::configure_transaction(self.provider.clone(), tx_envelope, self.impersonate_account).await; + let txn_request = test_config::configure_transaction( + // self.provider.clone(), + tx_envelope, + self.impersonate_account, + nonce, + ) + .await; let pending_transaction = self.provider.send_transaction(txn_request).await?; return Ok(pending_transaction.tx_hash().to_string()); @@ -297,9 +295,10 @@ mod test_config { use alloy::network::TransactionBuilder; pub async fn configure_transaction( - provider: Arc>>, + // provider: Arc>>, tx_envelope: TxEnvelope, impersonate_account: Option
, + nonce: u64, ) -> TransactionRequest { let mut txn_request: TransactionRequest = tx_envelope.into(); @@ -310,8 +309,8 @@ mod test_config { // - if "1" then : Testing via impersonating `Starknet Operator Address`. // Note : changing between "0" and "1" is handled automatically by each test function, `no` manual change in `env.test` is needed. if let Some(impersonate_account) = impersonate_account { - let nonce = - provider.get_transaction_count(impersonate_account).await.unwrap().to_string().parse::().unwrap(); + // let nonce = + // provider.get_transaction_count(impersonate_account).await.unwrap().to_string().parse::().unwrap(); txn_request.set_nonce(nonce); txn_request = txn_request.with_from(impersonate_account); } diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 8a8165ee..65694e46 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -136,12 +136,8 @@ async fn update_state_blob_with_dummy_contract_works() { // Deploying a dummy contract let contract = DummyCoreContract::deploy(&setup.provider).await.expect("Unable to deploy address"); - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( - setup.provider.clone(), - Some(*contract.address()), - setup.rpc_url, - None, - ); + let ethereum_settlement_client = + EthereumSettlementClient::with_test_settings(setup.provider.clone(), *contract.address(), setup.rpc_url, None); // Getting latest nonce after deployment let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); @@ -198,13 +194,21 @@ async fn update_state_blob_with_impersonation_works(#[case] fork_block_no: u64) .await; let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( setup.provider.clone(), - Some(*STARKNET_CORE_CONTRACT_ADDRESS), + *STARKNET_CORE_CONTRACT_ADDRESS, setup.rpc_url, Some(*STARKNET_OPERATOR_ADDRESS), ); - let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); + // let nonce = ethereum_settlement_client.get_nonce().await.expect("Unable to fetch nonce"); + let nonce = setup + .provider + .get_transaction_count(*STARKNET_OPERATOR_ADDRESS) + .await + .unwrap() + .to_string() + .parse::() + .unwrap(); // Create a contract instance. let contract = STARKNET_CORE_CONTRACT::new(*STARKNET_CORE_CONTRACT_ADDRESS, setup.provider.clone()); @@ -249,7 +253,7 @@ async fn get_last_settled_block_typical_works(#[case] fork_block_no: u64) { let setup = EthereumTestBuilder::new().with_fork_block(fork_block_no).build().await; let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( setup.provider.clone(), - Some(*STARKNET_CORE_CONTRACT_ADDRESS), + *STARKNET_CORE_CONTRACT_ADDRESS, setup.rpc_url, None, );