From ce850c4fc3862690c22bbf2ae5e21c05305fa4c4 Mon Sep 17 00:00:00 2001 From: Crypto Nomad Date: Mon, 16 Mar 2026 11:11:55 +0000 Subject: [PATCH] fix(rpc): clone EthSigner trait objects with generic tx request (#23050) --- crates/rpc/rpc-eth-api/src/helpers/signer.rs | 44 +++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/signer.rs b/crates/rpc/rpc-eth-api/src/helpers/signer.rs index c54c8943c0..be04ecc278 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/signer.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/signer.rs @@ -31,4 +31,46 @@ pub trait EthSigner: Send + Sync + DynClone { fn sign_typed_data(&self, address: Address, payload: &TypedData) -> Result; } -dyn_clone::clone_trait_object!( EthSigner); +dyn_clone::clone_trait_object!( EthSigner); + +#[cfg(test)] +mod tests { + use super::*; + + #[derive(Clone)] + struct MockSigner; + + struct MockSignedTx; + struct MockTxReq; + + #[async_trait::async_trait] + impl EthSigner for MockSigner { + fn accounts(&self) -> Vec
{ + Vec::new() + } + + async fn sign(&self, _address: Address, _message: &[u8]) -> Result { + Err(SignError::NoAccount) + } + + async fn sign_transaction( + &self, + _request: MockTxReq, + _address: &Address, + ) -> Result { + Err(SignError::NoAccount) + } + + fn sign_typed_data(&self, _address: Address, _payload: &TypedData) -> Result { + Err(SignError::NoAccount) + } + } + + #[test] + fn clones_trait_object_with_custom_tx_request_type() { + let signer: Box> = Box::new(MockSigner); + let cloned: Box> = dyn_clone::clone_box(&*signer); + + assert!(cloned.accounts().is_empty()); + } +}