Skip to content

Commit

Permalink
update: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 20, 2024
1 parent a69d56d commit 422fd16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
25 changes: 12 additions & 13 deletions crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl EthereumSettlementClient {
#[cfg(test)]
pub fn with_test_settings(
provider: RootProvider<Http<Client>>,
core_contract_address: Option<Address>,
core_contract_address: Address,
rpc_url: Url,
impersonate_account: Option<Address>,
) -> Self {
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -297,9 +295,10 @@ mod test_config {
use alloy::network::TransactionBuilder;

pub async fn configure_transaction(
provider: Arc<RootProvider<Http<Client>>>,
// provider: Arc<RootProvider<Http<Client>>>,
tx_envelope: TxEnvelope,
impersonate_account: Option<Address>,
nonce: u64,
) -> TransactionRequest {
let mut txn_request: TransactionRequest = tx_envelope.into();

Expand All @@ -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::<u64>().unwrap();
// let nonce =
// provider.get_transaction_count(impersonate_account).await.unwrap().to_string().parse::<u64>().unwrap();
txn_request.set_nonce(nonce);
txn_request = txn_request.with_from(impersonate_account);
}
Expand Down
22 changes: 13 additions & 9 deletions crates/settlement-clients/ethereum/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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::<u64>()
.unwrap();
// Create a contract instance.
let contract = STARKNET_CORE_CONTRACT::new(*STARKNET_CORE_CONTRACT_ADDRESS, setup.provider.clone());

Expand Down Expand Up @@ -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,
);
Expand Down

0 comments on commit 422fd16

Please sign in to comment.