diff --git a/crates/contract/src/event.rs b/crates/contract/src/event.rs index 2ef17b34d7a..30928ed0658 100644 --- a/crates/contract/src/event.rs +++ b/crates/contract/src/event.rs @@ -281,10 +281,10 @@ mod tests { let all = event.query().await.unwrap(); assert_eq!(all.len(), 0); - #[cfg(feature = "ws")] + #[cfg(feature = "pubsub")] { - let provider = alloy_provider::ProviderBuilder::default() - .on_ws(anvil.ws_endpoint()) + let provider = alloy_provider::ProviderBuilder::new() + .on_builtin(&anvil.ws_endpoint()) .await .unwrap(); @@ -303,8 +303,8 @@ mod tests { stream_log.topics().first().unwrap().0 ); assert_eq!(stream_event, expected_event); - assert_eq!(stream_log.address, *contract.address()); - assert_eq!(stream_log.block_number, Some(U256::from(3))); + assert_eq!(stream_log.address(), *contract.address()); + assert_eq!(stream_log.block_number, Some(4)); // send the request to emit the wrong event contract diff --git a/crates/eips/src/eip1559/helpers.rs b/crates/eips/src/eip1559/helpers.rs index ef7ac11b09e..0a22091344f 100644 --- a/crates/eips/src/eip1559/helpers.rs +++ b/crates/eips/src/eip1559/helpers.rs @@ -101,70 +101,4 @@ mod tests { ); } } - - #[cfg(feature = "optimism")] - #[test] - fn calculate_optimism_base_fee_success() { - let base_fee = [ - 1000000000, 1000000000, 1000000000, 1072671875, 1059263476, 1049238967, 1049238967, 0, - 1, 2, - ]; - let gas_used = [ - 10000000, 10000000, 10000000, 9000000, 10001000, 0, 10000000, 10000000, 10000000, - 10000000, - ]; - let gas_limit = [ - 10000000, 12000000, 14000000, 10000000, 14000000, 2000000, 18000000, 18000000, - 18000000, 18000000, - ]; - let next_base_fee = [ - 1100000048, 1080000000, 1065714297, 1167067046, 1128881311, 1028254188, 1098203452, 1, - 2, 3, - ]; - - for i in 0..base_fee.len() { - assert_eq!( - next_base_fee[i], - calc_next_block_base_fee( - gas_used[i], - gas_limit[i], - base_fee[i], - crate::BaseFeeParams::optimism(), - ) - ); - } - } - - #[cfg(feature = "optimism")] - #[test] - fn calculate_optimism_goerli_base_fee_success() { - let base_fee = [ - 1000000000, 1000000000, 1000000000, 1072671875, 1059263476, 1049238967, 1049238967, 0, - 1, 2, - ]; - let gas_used = [ - 10000000, 10000000, 10000000, 9000000, 10001000, 0, 10000000, 10000000, 10000000, - 10000000, - ]; - let gas_limit = [ - 10000000, 12000000, 14000000, 10000000, 14000000, 2000000, 18000000, 18000000, - 18000000, 18000000, - ]; - let next_base_fee = [ - 1180000000, 1146666666, 1122857142, 1244299375, 1189416692, 1028254188, 1144836295, 1, - 2, 3, - ]; - - for i in 0..base_fee.len() { - assert_eq!( - next_base_fee[i], - calc_next_block_base_fee( - gas_used[i], - gas_limit[i], - base_fee[i], - crate::BaseFeeParams::optimism_goerli(), - ) - ); - } - } } diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index d6259ce2167..95b931610e9 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -1,5 +1,7 @@ //! [EIP-1898]: https://eips.ethereum.org/EIPS/eip-1898 +#![allow(unknown_lints, non_local_definitions)] + use alloy_primitives::{hex::FromHexError, ruint::ParseError, BlockHash, BlockNumber, B256, U64}; use alloy_rlp::{bytes, Decodable, Encodable, Error as RlpError}; use core::{ diff --git a/crates/eips/src/eip7002.rs b/crates/eips/src/eip7002.rs index da523349eb4..8b8792e438f 100644 --- a/crates/eips/src/eip7002.rs +++ b/crates/eips/src/eip7002.rs @@ -2,6 +2,8 @@ //! //! See also [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002): Execution layer triggerable withdrawals +#![allow(unknown_lints, non_local_definitions)] + use alloy_primitives::{address, bytes, Address, Bytes, FixedBytes}; use alloy_rlp::{RlpDecodable, RlpEncodable}; diff --git a/crates/network/Cargo.toml b/crates/network/Cargo.toml index ed09faa6d26..a751388c64e 100644 --- a/crates/network/Cargo.toml +++ b/crates/network/Cargo.toml @@ -20,6 +20,7 @@ alloy-rpc-types.workspace = true alloy-signer.workspace = true alloy-sol-types.workspace = true +auto_impl.workspace = true async-trait.workspace = true futures-utils-wasm.workspace = true thiserror.workspace = true diff --git a/crates/network/src/transaction/signer.rs b/crates/network/src/transaction/signer.rs index a9d70493697..ecce9d4c55b 100644 --- a/crates/network/src/transaction/signer.rs +++ b/crates/network/src/transaction/signer.rs @@ -2,6 +2,7 @@ use crate::{Network, TransactionBuilder}; use alloy_consensus::SignableTransaction; use alloy_primitives::Address; use async_trait::async_trait; +use auto_impl::auto_impl; use futures_utils_wasm::impl_future; /// A signer capable of signing any transaction for the given network. @@ -16,6 +17,7 @@ use futures_utils_wasm::impl_future; /// no specific signer address is specified. #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait NetworkSigner: std::fmt::Debug + Send + Sync { /// Get the default signer address. This address should be used /// in [`NetworkSigner::sign_transaction_from`] when no specific signer is @@ -72,6 +74,7 @@ pub trait NetworkSigner: std::fmt::Debug + Send + Sync { /// [`ChainId`]: alloy_primitives::ChainId #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait TxSigner { /// Get the address of the signer. fn address(&self) -> Address; @@ -98,6 +101,7 @@ pub trait TxSigner { /// /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 /// [`ChainId`]: alloy_primitives::ChainId +#[auto_impl(&, &mut, Box, Rc, Arc)] pub trait TxSignerSync { /// Get the address of the signer. fn address(&self) -> Address; diff --git a/crates/signer-trezor/Cargo.toml b/crates/signer-trezor/Cargo.toml index 2a9236eca6e..b47dbd92c78 100644 --- a/crates/signer-trezor/Cargo.toml +++ b/crates/signer-trezor/Cargo.toml @@ -17,7 +17,9 @@ alloy-network.workspace = true alloy-primitives.workspace = true alloy-signer.workspace = true -trezor-client = { version = "=0.1.3", default-features = false, features = ["ethereum"] } +trezor-client = { version = "=0.1.3", default-features = false, features = [ + "ethereum", +] } async-trait.workspace = true semver.workspace = true @@ -25,4 +27,5 @@ thiserror.workspace = true tracing.workspace = true [dev-dependencies] +alloy-rpc-types.workspace = true tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } diff --git a/crates/signer-trezor/src/signer.rs b/crates/signer-trezor/src/signer.rs index 382f2391629..38bf9bac501 100644 --- a/crates/signer-trezor/src/signer.rs +++ b/crates/signer-trezor/src/signer.rs @@ -280,7 +280,9 @@ fn signature_from_trezor(x: trezor_client::client::Signature) -> Result().unwrap()) - .gas(1000000) - .gas_price(400e9 as u64) - .nonce(5) - .data(data) - .value(ethers_core::utils::parse_ether(100).unwrap()) - .into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + let _tx = TransactionRequest::default() + .to(address!("2ed7afa17473e17ac59908f088b4371d28585476")) + .with_gas_limit(1000000) + .with_gas_price(400e9 as u128) + .with_nonce(5) + .with_input(data) + .with_value(U256::from(100e18 as u128)) + .build(&EthereumSigner::new(trezor)) + .await + .unwrap(); } #[tokio::test] #[ignore] - #[cfg(TODO)] // TODO: TypedTransaction async fn test_sign_big_data_tx() { - let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), 1).await.unwrap(); + let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), Some(1)).await.unwrap(); // invalid data let big_data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string()+ &"ff".repeat(1032*2) + "aa").unwrap(); - let tx_req = TransactionRequest::new() - .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::
().unwrap()) - .gas(1000000) - .gas_price(400e9 as u64) - .nonce(5) - .data(big_data) - .value(ethers_core::utils::parse_ether(100).unwrap()) - .into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + let _tx = TransactionRequest::default() + .to(address!("2ed7afa17473e17ac59908f088b4371d28585476")) + .with_gas_limit(1000000) + .with_gas_price(400e9 as u128) + .with_nonce(5) + .with_input(big_data) + .with_value(U256::from(100e18 as u128)) + .build(&EthereumSigner::new(trezor)) + .await + .unwrap(); } #[tokio::test] #[ignore] - #[cfg(TODO)] // TODO: TypedTransaction async fn test_sign_empty_txes() { - // Contract creation (empty `to`), requires data. - // To test without the data field, we need to specify a `to` address. - let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), 1, None).await.unwrap(); - { - let tx_req = Eip1559TransactionRequest::new() - .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::
().unwrap()) - .into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); - } - { - let tx_req = TransactionRequest::new() - .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::
().unwrap()) - .into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); - } + let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), Some(1)).await.unwrap(); + TransactionRequest::default() + .to(address!("2ed7afa17473e17ac59908f088b4371d28585476")) + .with_gas_price(1) + .build(&EthereumSigner::new(trezor)) + .await + .unwrap(); let data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(); // Contract creation (empty `to`, with data) should show on the trezor device as: // ` "0 Wei ETH // ` new contract?" - let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), 1).await.unwrap(); - { - let tx_req = Eip1559TransactionRequest::new().data(data.clone()).into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); - } + let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), Some(1)).await.unwrap(); { - let tx_req = TransactionRequest::new().data(data.clone()).into(); - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + let _tx = TransactionRequest::default() + .into_create() + .with_input(data) + .with_gas_price(1) + .build(&EthereumSigner::new(trezor)) + .await + .unwrap(); } } #[tokio::test] #[ignore] - #[cfg(TODO)] // TODO: TypedTransaction async fn test_sign_eip1559_tx() { - let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), 1).await.unwrap(); + let trezor = TrezorSigner::new(DerivationType::TrezorLive(0), Some(1)).await.unwrap(); // approve uni v2 router 0xff let data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(); let lst = AccessList(vec![ AccessListItem { - address: "0x8ba1f109551bd432803012645ac136ddd64dba72".parse().unwrap(), + address: address!("8ba1f109551bd432803012645ac136ddd64dba72"), storage_keys: vec![ - "0x0000000000000000000000000000000000000000000000000000000000000000" - .parse() - .unwrap(), - "0x0000000000000000000000000000000000000000000000000000000000000042" - .parse() - .unwrap(), + b256!("0000000000000000000000000000000000000000000000000000000000000000"), + b256!("0000000000000000000000000000000000000000000000000000000000000042"), ], }, AccessListItem { - address: "0x2ed7afa17473e17ac59908f088b4371d28585476".parse().unwrap(), + address: address!("2ed7afa17473e17ac59908f088b4371d28585476"), storage_keys: vec![ - "0x0000000000000000000000000000000000000000000000000000000000000000" - .parse() - .unwrap(), - "0x0000000000000000000000000000000000000000000000000000000000000042" - .parse() - .unwrap(), + b256!("0000000000000000000000000000000000000000000000000000000000000000"), + b256!("0000000000000000000000000000000000000000000000000000000000000042"), ], }, ]); - let tx_req = Eip1559TransactionRequest::new() - .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::
().unwrap()) - .gas(1000000) - .max_fee_per_gas(400e9 as u64) - .max_priority_fee_per_gas(400e9 as u64) - .nonce(5) - .data(data) - .access_list(lst) - .value(ethers_core::utils::parse_ether(100).unwrap()) - .into(); - - let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + let _tx = TransactionRequest::default() + .to(address!("2ed7afa17473e17ac59908f088b4371d28585476")) + .with_gas_limit(1000000) + .max_fee_per_gas(400e9 as u128) + .max_priority_fee_per_gas(400e9 as u128) + .with_nonce(5) + .with_input(data) + .with_access_list(lst) + .with_value(U256::from(100e18 as u128)) + .build(&EthereumSigner::new(trezor)) + .await + .unwrap(); } } diff --git a/crates/signer-wallet/Cargo.toml b/crates/signer-wallet/Cargo.toml index a0a371c662d..da6c1b210fd 100644 --- a/crates/signer-wallet/Cargo.toml +++ b/crates/signer-wallet/Cargo.toml @@ -33,14 +33,20 @@ coins-bip39 = { version = "0.8.7", default-features = false, features = [ ], optional = true } # yubi -yubihsm = { version = "0.42", features = ["secp256k1", "http", "usb"], optional = true } +yubihsm = { version = "0.42", features = [ + "secp256k1", + "http", + "usb", +], optional = true } [dev-dependencies] -serde.workspace = true +alloy-dyn-abi.workspace = true +alloy-sol-types.workspace = true alloy-consensus = { workspace = true, features = ["std"] } alloy-network.workspace = true assert_matches.workspace = true serde_json.workspace = true +serde.workspace = true tempfile.workspace = true tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } @@ -52,3 +58,5 @@ keystore = ["dep:eth-keystore", "dep:elliptic-curve"] mnemonic = ["dep:coins-bip32", "dep:coins-bip39"] mnemonic-all-languages = ["mnemonic", "coins-bip39?/all-langs"] yubihsm = ["dep:yubihsm", "dep:elliptic-curve"] + +eip712 = ["alloy-signer/eip712"] diff --git a/crates/signer-wallet/src/private_key.rs b/crates/signer-wallet/src/private_key.rs index 5a05d7ad308..ddb275b65aa 100644 --- a/crates/signer-wallet/src/private_key.rs +++ b/crates/signer-wallet/src/private_key.rs @@ -294,7 +294,7 @@ mod tests { let foo_bar = FooBar { foo: I256::try_from(10u64).unwrap(), bar: U256::from(20u64), - fizz: b"fizz".to_vec(), + fizz: b"fizz".to_vec().into(), buzz: keccak256("buzz"), far: "space".into(), out: Address::ZERO,