Skip to content

Commit

Permalink
update: dummy contract and impersonation tests ready
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 14, 2024
1 parent 83cf6e7 commit e2cbe99
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ MONGODB_CONNECTION_STRING="mongodb://localhost:27017"
# Ethereum Settlement
DEFAULT_SETTLEMENT_CLIENT_RPC="http://localhost:3000"
DEFAULT_L1_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
TEST_IMPERSONATE_OPERATOR=0
TEST_IMPERSONATE_OPERATOR="1"
TEST_DUMMY_CONTRACT_ADDRESS="0xE5b6F5e695BA6E4aeD92B68c4CC8Df1160D69A81"
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/settlement-clients/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
alloy = { workspace = true, features = ["full", "node-bindings" ] }
alloy-primitives = { version = "0.7.7", default-features = false }
async-trait = { workspace = true }
lazy_static = "1.4.0"
c-kzg = "1.0.0"
color-eyre = { workspace = true }
dotenv = "0.15"
Expand Down
37 changes: 18 additions & 19 deletions crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ use crate::conversion::{slice_slice_u8_to_vec_u256, slice_u8_to_u256};
pub mod clients;
pub mod config;
pub mod conversion;

#[cfg(test)]
lazy_static! {
static ref SHOULD_IMPERSONATE_ACCOUNT: bool = get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == "1".to_string();
static ref TEST_DUMMY_CONTRACT_ADDRESS: String = get_env_var_or_panic("TEST_DUMMY_CONTRACT_ADDRESS");
static ref ADDRESS_TO_IMPERSONATE: Address = Address::from_str("0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7").expect("Unable to parse address");
static ref TEST_NONCE: u64 = 666068;
}

#[cfg(test)]
mod tests;
pub mod types;
Expand Down Expand Up @@ -104,14 +113,14 @@ impl EthereumSettlementClient {
ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(settlement_cfg.rpc_url),
);

let core_contract_address = if get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == "0".to_string() {
get_env_var_or_panic("TEST_DUMMY_CONTRACT_ADDRESS")
let core_contract_address = if *SHOULD_IMPERSONATE_ACCOUNT {
&settlement_cfg.core_contract_address
} else {
settlement_cfg.core_contract_address
&*TEST_DUMMY_CONTRACT_ADDRESS
};

let core_contract_client = StarknetValidityContractClient::new(
Address::from_str(&core_contract_address).unwrap().0.into(),
Address::from_str(core_contract_address).unwrap().0.into(),
fill_provider,
);

Expand Down Expand Up @@ -186,6 +195,7 @@ impl SettlementClient for EthereumSettlementClient {
nonce: u64,
) -> Result<String> {
//TODO: better file management

let trusted_setup = KzgSettings::load_trusted_setup_file(Path::new("/Users/dexterhv/Work/Karnot/madara-alliance/madara-orchestrator/crates/settlement-clients/ethereum/src/trusted_setup.txt"))?;
let (sidecar_blobs, sidecar_commitments, sidecar_proofs) = prepare_sidecar(&state_diff, &trusted_setup).await?;
let sidecar = BlobTransactionSidecar::new(sidecar_blobs, sidecar_commitments, sidecar_proofs);
Expand Down Expand Up @@ -224,33 +234,22 @@ impl SettlementClient for EthereumSettlementClient {

let tx_sidecar = TxEip4844WithSidecar { tx: tx.clone(), sidecar: sidecar.clone() };

println!("CONTTRRAACCTTT {:?}", tx.to);
let mut variant = TxEip4844Variant::from(tx_sidecar);
let signature = self.wallet.default_signer().sign_transaction(&mut variant).await?;
let tx_signed = variant.into_signed(signature);
let tx_envelope: TxEnvelope = tx_signed.into();
// IMP: this conversion strips signature from the transaction
let mut txn_request: TransactionRequest = tx_envelope.into();

println!("CONTTRRAACCTTT #2 {:?}", tx.to);

if cfg!(test) && get_env_var_or_panic("TEST_IMPERSONATE_OPERATOR") == "1".to_string() {
txn_request.set_nonce(666068);
#[cfg(test)]
if *SHOULD_IMPERSONATE_ACCOUNT {
txn_request.set_nonce(*TEST_NONCE);
txn_request = txn_request.with_from(
Address::from_str("0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7")
.expect("Unable to impersonate operator."),
*ADDRESS_TO_IMPERSONATE
);
}

println!("CONTTRRAACCTTT #3 {:?}", tx.to);


// let encoded = tx_envelope.encoded_2718();
// let pending_tx = self.provider.send_raw_transaction(&encoded).await?;

let pending_transaction = self.provider.send_transaction(txn_request).await?;
println!("CONTTRRAACCTTT #4 {:?}", pending_transaction.tx_hash().to_string());

return Ok(pending_transaction.tx_hash().to_string());
}

Expand Down
Loading

0 comments on commit e2cbe99

Please sign in to comment.