Skip to content

Commit

Permalink
chore: use alloy macroses
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Jan 2, 2025
1 parent b43ac37 commit 132b259
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 94 deletions.
65 changes: 26 additions & 39 deletions user-ops-indexer/user-ops-indexer-logic/src/indexer/base_indexer.rs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions user-ops-indexer/user-ops-indexer-logic/src/indexer/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,15 @@ pub fn decode_execute_call_data(call_data: &Bytes) -> (Option<Address>, Option<B
mod tests {
use crate::indexer::common::{decode_execute_call_data, extract_user_logs_boundaries};
use alloy::{
primitives::{Address, Bytes, LogData, U160},
primitives::{address, bytes, LogData},
rpc::types::Log,
};
use std::str::FromStr;

#[test]
fn test_extract_user_logs_boundaries() {
let entry_point = Address::from(U160::from(1));
let paymaster = Address::from(U160::from(2));
let other = Address::from(U160::from(3));
let entry_point = address!("0000000000000000000000000000000000000001");
let paymaster = address!("0000000000000000000000000000000000000002");
let other = address!("0000000000000000000000000000000000000003");
let logs = vec![
entry_point,
entry_point,
Expand Down Expand Up @@ -178,13 +177,13 @@ mod tests {

#[test]
fn test_decode_execute_call_data() {
let call_data = Bytes::from_str("0x5194544700000000000000000000000014778860e937f509e651192a90589de711fb88a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000001d993968fbd7669690384eab1b4d23aeb1132bf40000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000").unwrap();
let call_data = bytes!("5194544700000000000000000000000014778860e937f509e651192a90589de711fb88a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000001d993968fbd7669690384eab1b4d23aeb1132bf40000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000");
let (execute_target, execute_call_data) = decode_execute_call_data(&call_data);
assert_eq!(
execute_target,
Some(Address::from_str("0x14778860E937f509e651192a90589dE711Fb88a9").unwrap())
Some(address!("14778860E937f509e651192a90589dE711Fb88a9"))
);
assert_eq!(execute_call_data, Some(Bytes::from_str("0xa9059cbb0000000000000000000000001d993968fbd7669690384eab1b4d23aeb1132bf40000000000000000000000000000000000000000000000004563918244f40000").unwrap()));
assert_eq!(execute_call_data, Some(bytes!("a9059cbb0000000000000000000000001d993968fbd7669690384eab1b4d23aeb1132bf40000000000000000000000000000000000000000000000004563918244f40000")));
let (execute_target, execute_call_data) =
decode_execute_call_data(&execute_call_data.unwrap());
assert_eq!(execute_target, None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ fn flatten_geth_trace(root: CallFrame) -> Vec<CommonCallTrace> {
mod tests {
use crate::indexer::rpc_utils::{flatten_geth_trace, TraceType};
use alloy::{
primitives::{Address, Bytes},
primitives::{address, bytes},
rpc::types::trace::geth::CallFrame,
};
use std::str::FromStr;

#[test]
fn test_flatten_geth_trace() {
Expand All @@ -183,13 +182,13 @@ mod tests {
assert_eq!(res[1].typ, TraceType::Call);
assert_eq!(
res[1].from,
Address::from_str("0xcA11bde05977b3631167028862bE2a173976CA11").unwrap()
address!("cA11bde05977b3631167028862bE2a173976CA11")
);
assert_eq!(
res[1].to,
Some(Address::from_str("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789").unwrap())
Some(address!("5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"))
);
assert_eq!(res[1].input, Bytes::from_str("0x1fad948c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000004471500ac7147c158224fee67ac64227d3049de0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000008b9658b654efdfd69be5208e53342f5283f6486e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000000000000000000000000000000000000007a12000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000005a7817d80000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104519454470000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000000b21f56063860b6aa1b86191a9dec568bebfdec50000000000000000000000000000000000000000000000000000000000e4e1be0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400d5bda3b690c569c1c78a387ed6cf1a88ea7626000000000000000000000000000000000000000000000000000000000000000000000000000000000000004500000000c06e5c395501f2069dcbc9b05e75f9fd632765a99ebe8d2680862b95a3cfee5b581cfbbecc01c954b729c74b6b337e61fff043e1746f753d5a95913d8f13691d1b0000000000000000000000000000000000000000000000000000000000000000000000000000008b9658b654efdfd69be5208e53342f5283f6486e00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000000000000000000000000000000000000007a12000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000005a7817d80000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104519454470000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000004471500ac7147c158224fee67ac64227d3049de00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400d5bda3b690c569c1c78a387ed6cf1a88ea7626000000000000000000000000000000000000000000000000000000000000000000000000000000000000004500000000910c0077d5fba1f751d0ad9ae50d4595d9437fcbc8b7df19b3bdc97c59166df021a9bf7f913df6132acfa223bb9e4b26446461cfb99e837b86e5d070171a763c1c000000000000000000000000000000000000000000000000000000").unwrap());
assert_eq!(res[1].input, bytes!("1fad948c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000004471500ac7147c158224fee67ac64227d3049de0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000008b9658b654efdfd69be5208e53342f5283f6486e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000000000000000000000000000000000000007a12000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000005a7817d80000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104519454470000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000000b21f56063860b6aa1b86191a9dec568bebfdec50000000000000000000000000000000000000000000000000000000000e4e1be0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400d5bda3b690c569c1c78a387ed6cf1a88ea7626000000000000000000000000000000000000000000000000000000000000000000000000000000000000004500000000c06e5c395501f2069dcbc9b05e75f9fd632765a99ebe8d2680862b95a3cfee5b581cfbbecc01c954b729c74b6b337e61fff043e1746f753d5a95913d8f13691d1b0000000000000000000000000000000000000000000000000000000000000000000000000000008b9658b654efdfd69be5208e53342f5283f6486e00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000000000000000000000000000000000000007a12000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000005a7817d80000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104519454470000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000004471500ac7147c158224fee67ac64227d3049de00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400d5bda3b690c569c1c78a387ed6cf1a88ea7626000000000000000000000000000000000000000000000000000000000000000000000000000000000000004500000000910c0077d5fba1f751d0ad9ae50d4595d9437fcbc8b7df19b3bdc97c59166df021a9bf7f913df6132acfa223bb9e4b26446461cfb99e837b86e5d070171a763c1c000000000000000000000000000000000000000000000000000000"));

assert_eq!(
res.iter()
Expand Down
10 changes: 3 additions & 7 deletions user-ops-indexer/user-ops-indexer-logic/src/indexer/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::indexer::rpc_utils::TraceClient;
use alloy::primitives::Address;
use alloy::primitives::{address, Address};
use serde::Deserialize;
use serde_with::serde_as;
use std::time;
Expand Down Expand Up @@ -127,13 +127,9 @@ impl Default for EntrypointsSettings {
fn default() -> Self {
Self {
v06: true,
v06_entry_point: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
.parse()
.unwrap(),
v06_entry_point: address!("5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"),
v07: true,
v07_entry_point: "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
.parse()
.unwrap(),
v07_entry_point: address!("0000000071727De22E5E9d8BAf0edAc6f37da032"),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl IndexerV06 {
let (user_logs_start_index, user_logs_count) =
extract_user_logs_boundaries(logs, self.entry_point, paymaster);
Ok(UserOp {
hash: B256::from(user_op_event.userOpHash),
hash: user_op_event.userOpHash,
sender,
nonce: B256::from(user_op.user_op.nonce),
init_code: none_if_empty(user_op.user_op.initCode),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl IndexerV07 {
let (user_logs_start_index, user_logs_count) =
extract_user_logs_boundaries(logs, self.entry_point, paymaster);
Ok(UserOp {
hash: B256::from(user_op_event.userOpHash),
hash: user_op_event.userOpHash,
sender,
nonce: B256::from(user_op.user_op.nonce),
init_code: none_if_empty(user_op.user_op.initCode),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ FROM accounts_cte
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use alloy::primitives::{B256, U160, U256};
use alloy::primitives::{address, B256, U256};
use pretty_assertions::assert_eq;

#[tokio::test]
async fn find_account_by_address_ok() {
let db = get_shared_db().await;

let addr = Address::from(U160::from(0xffff));
let addr = address!("000000000000000000000000000000000000ffff");
let item = find_account_by_address(&db, addr).await.unwrap();
assert_eq!(item, None);

let addr = Address::from(U160::from(0x0102));
let addr = address!("0000000000000000000000000000000000000102");
let item = find_account_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Expand All @@ -125,13 +125,13 @@ mod tests {
})
);

let addr = Address::from(U160::from(0x3202));
let addr = address!("0000000000000000000000000000000000003202");
let item = find_account_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Some(Account {
address: addr,
factory: Some(Address::from(U160::from(0xf1))),
factory: Some(address!("00000000000000000000000000000000000000f1")),
creation_transaction_hash: Some(B256::from(U256::from(0x3204))),
creation_op_hash: Some(B256::from(U256::from(0x3201))),
creation_timestamp: Some("2024-01-01T00:01:00.000000Z".to_string()),
Expand All @@ -152,7 +152,7 @@ mod tests {
assert_eq!(items.len(), 40);
assert_eq!(next_page_token, None);

let factory = Some(Address::from(U160::from(0xf1)));
let factory = Some(address!("00000000000000000000000000000000000000f1"));
let (items, next_page_token) = list_accounts(&db, factory, None, 60).await.unwrap();
assert_eq!(items.len(), 10);
assert_eq!(next_page_token, None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ LIMIT $6"#,
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use alloy::primitives::U160;
use alloy::primitives::address;
use pretty_assertions::assert_eq;
use std::str::FromStr;

#[tokio::test]
async fn list_bundles_ok() {
Expand All @@ -73,9 +72,8 @@ mod tests {
assert_eq!(items.len(), 100);
assert_ne!(next_page_token, None);

let entrypoint =
Some(Address::from_str("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789").unwrap());
let bundler = Some(Address::from(U160::from(0x0105)));
let entrypoint = Some(address!("5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"));
let bundler = Some(address!("0000000000000000000000000000000000000105"));

let (items, next_page_token) = list_bundles(&db, None, entrypoint, None, 100)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ LIMIT $3"#,
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use alloy::primitives::U160;
use alloy::primitives::address;
use pretty_assertions::assert_eq;

#[tokio::test]
async fn find_bundler_by_address_ok() {
let db = get_shared_db().await;

let addr = Address::from(U160::from(0xffff));
let addr = address!("000000000000000000000000000000000000ffff");
let item = find_bundler_by_address(&db, addr).await.unwrap();
assert_eq!(item, None);

let addr = Address::from(U160::from(0x0105));
let addr = address!("0000000000000000000000000000000000000105");
let item = find_bundler_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Expand All @@ -100,7 +100,7 @@ mod tests {
})
);

let addr = Address::from(U160::from(0x0505));
let addr = address!("0000000000000000000000000000000000000505");
let item = find_bundler_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ pub async fn list_factories(
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use alloy::primitives::U160;
use alloy::primitives::address;
use pretty_assertions::assert_eq;

#[tokio::test]
async fn find_factory_by_address_ok() {
let db = get_shared_db().await;

let addr = Address::from(U160::from(0xf3));
let addr = address!("00000000000000000000000000000000000000f3");
let item = find_factory_by_address(&db, addr).await.unwrap();
assert_eq!(item, None);

let addr = Address::from(U160::from(0xf1));
let addr = address!("00000000000000000000000000000000000000f1");
let item = find_factory_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ pub async fn list_paymasters(
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use alloy::primitives::U160;
use alloy::primitives::address;
use pretty_assertions::assert_eq;

#[tokio::test]
async fn find_paymaster_by_address_ok() {
let db = get_shared_db().await;

let addr = Address::from(U160::from(0xe3));
let addr = address!("00000000000000000000000000000000000000e3");
let item = find_paymaster_by_address(&db, addr).await.unwrap();
assert_eq!(item, None);

let addr = Address::from(U160::from(0xe1));
let addr = address!("00000000000000000000000000000000000000e1");
let item = find_paymaster_by_address(&db, addr).await.unwrap();
assert_eq!(
item,
Expand Down
Loading

0 comments on commit 132b259

Please sign in to comment.