[go: nahoru, domu]

Skip to content

Commit

Permalink
fix(abigen): correctly calculate return derives (#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Feb 20, 2024
1 parent 2ce5014 commit f564a63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl Context {
);

let mut derives = self.expand_extra_derives();
let params = function.inputs.iter().map(|param| &param.kind);
let params = function.outputs.iter().map(|param| &param.kind);
util::derive_builtin_traits(params, &mut derives, true, true);

let ethers_contract = ethers_contract_crate();
Expand Down Expand Up @@ -637,8 +637,6 @@ fn expand_call_struct_variant_name(function: &Function, alias: Option<&MethodAli

#[cfg(test)]
mod tests {
use ethers_core::abi::ParamType;

use super::*;

fn expand_fn_outputs(outputs: &[Param]) -> Result<TokenStream> {
Expand Down
8 changes: 4 additions & 4 deletions ethers-contract/ethers-contract-abigen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ pub(crate) fn derive_builtin_traits<'a>(
mut derive_others: bool,
) {
for param in params {
derive_default &= can_derive_default(param);
derive_others &= can_derive_builtin_traits(param);
derive_default = derive_default && can_derive_default(param);
derive_others = derive_others && can_derive_builtin_traits(param);
}
extend_derives(stream, derive_default, derive_others);
}
Expand Down Expand Up @@ -255,8 +255,8 @@ fn _derive_builtin_traits_struct(

FieldType::Elementary(ty1) => {
debug_assert_eq!(ty, ty1);
*def &= can_derive_default(ty);
*others &= can_derive_builtin_traits(ty);
*def = *def && can_derive_default(ty);
*others = *others && can_derive_builtin_traits(ty);
}

FieldType::Mapping(_) => unreachable!(),
Expand Down
13 changes: 13 additions & 0 deletions ethers-contract/tests/it/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,16 @@ fn abigen_overloaded_methods2() {
assert_eq!(e3.3, vec![b1, b2]);
assert_eq!(e1_encoded.to_string(), "0x24856bc3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002abcd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002abcd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011200000000000000000000000000000000000000000000000000000000000000");
}

// https://github.com/foundry-rs/foundry/issues/7181
#[test]
fn abigen_default() {
// https://github.com/Layr-Labs/eigenlayer-middleware/blob/a79742bda7f967ce066df39b26f456afb61d6c28/test/utils/ProofParsing.sol#L132
abigen!(
ProofParsing,
r#"[
function getValidatorProof() public returns(bytes32[46] memory)
]"#
);
// GetValidatorProofReturn cannot be Default
}

0 comments on commit f564a63

Please sign in to comment.