From c3528b78db973b41b4033b9cfdb61734d59515df Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 16 Oct 2021 18:45:42 +0200 Subject: [PATCH] fix: use syn::Index for tuple access (#515) * fix: use syn::Index for tuple access * rustfmt --- .../ethers-contract-derive/src/display.rs | 10 +++++++--- ethers-contract/src/multicall/mod.rs | 8 +++++--- ethers-contract/tests/common/derive.rs | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ethers-contract/ethers-contract-derive/src/display.rs b/ethers-contract/ethers-contract-derive/src/display.rs index 23ea5516..9576de19 100644 --- a/ethers-contract/ethers-contract-derive/src/display.rs +++ b/ethers-contract/ethers-contract-derive/src/display.rs @@ -1,9 +1,9 @@ //! Helper functions for deriving `Display` use proc_macro2::TokenStream; -use quote::{format_ident, quote}; +use quote::quote; use syn::spanned::Spanned as _; -use syn::{parse::Error, Data, DeriveInput, Fields}; +use syn::{parse::Error, Data, DeriveInput, Fields, Index}; use ethers_contract_abigen::ethers_core_crate; use ethers_core::abi::ParamType; @@ -40,7 +40,11 @@ pub(crate) fn derive_eth_display_impl(input: DeriveInput) -> Result { diff --git a/ethers-contract/src/multicall/mod.rs b/ethers-contract/src/multicall/mod.rs index 1b31252f..6ad48620 100644 --- a/ethers-contract/src/multicall/mod.rs +++ b/ethers-contract/src/multicall/mod.rs @@ -212,9 +212,11 @@ impl Multicall { /// If more than the maximum number of supported calls are added. The maximum /// limits is constrained due to tokenization/detokenization support for tuples pub fn add_call(&mut self, call: ContractCall) -> &mut Self { - if self.calls.len() >= 16 { - panic!("Cannot support more than {} calls", 16); - } + assert!( + !(self.calls.len() >= 16), + "Cannot support more than {} calls", + 16 + ); match (call.tx.to(), call.tx.data()) { (Some(NameOrAddress::Address(target)), Some(data)) => { diff --git a/ethers-contract/tests/common/derive.rs b/ethers-contract/tests/common/derive.rs index 7c05eacb..6d471522 100644 --- a/ethers-contract/tests/common/derive.rs +++ b/ethers-contract/tests/common/derive.rs @@ -371,3 +371,21 @@ fn eth_display_works() { assert_eq!(val, format!("{}", item)); } + +#[test] +fn eth_display_works_for_human_readable() { + ethers_contract::abigen!( + HevmConsole, + r#"[ + event log(string) + event log2(string x) + ]"#, + ); + + let log = LogFilter("abc".to_string()); + assert_eq!("abc".to_string(), format!("{}", log)); + let log = Log2Filter { + x: "abc".to_string(), + }; + assert_eq!("abc".to_string(), format!("{}", log)); +}