From 5ba3be3190b29d206464b3d23ad549bf807862f0 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:42:14 +0200 Subject: [PATCH] fix(json-abi): accept nameless `Param`s (#526) * fix(json-abi): accept nameless `Param`s * chore: clippy --- .gitattributes | 1 - crates/dyn-abi/benches/abi.rs | 2 ++ crates/dyn-abi/benches/types.rs | 2 ++ crates/json-abi/benches/json_abi.rs | 2 ++ crates/json-abi/src/param.rs | 1 + crates/json-abi/tests/abi.rs | 2 +- crates/json-abi/tests/abi/NamelessParams.json | 1 + crates/json-abi/tests/abi/NamelessParams.sol | 11 +++++++++++ crates/primitives/benches/primitives.rs | 2 ++ crates/sol-types/src/types/data_type.rs | 8 ++++++++ 10 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 crates/json-abi/tests/abi/NamelessParams.json create mode 100644 crates/json-abi/tests/abi/NamelessParams.sol diff --git a/.gitattributes b/.gitattributes index fafdfa139..0c4bb0bdc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,2 @@ *.sol linguist-language=Solidity -**/tests/abi/* linguist-vendored **/tests/contracts/* linguist-vendored diff --git a/crates/dyn-abi/benches/abi.rs b/crates/dyn-abi/benches/abi.rs index 0e2568e9d..4e8c3b8de 100644 --- a/crates/dyn-abi/benches/abi.rs +++ b/crates/dyn-abi/benches/abi.rs @@ -1,3 +1,5 @@ +#![allow(clippy::incompatible_msrv)] + use alloy_dyn_abi::{DynSolType, DynSolValue}; use alloy_primitives::{hex, U256}; use alloy_sol_types::{sol, sol_data, SolType, SolValue}; diff --git a/crates/dyn-abi/benches/types.rs b/crates/dyn-abi/benches/types.rs index 97e8ea4fe..f40163956 100644 --- a/crates/dyn-abi/benches/types.rs +++ b/crates/dyn-abi/benches/types.rs @@ -1,3 +1,5 @@ +#![allow(clippy::incompatible_msrv)] + use alloy_dyn_abi::{DynSolType, ResolveSolType}; use alloy_sol_type_parser::TypeSpecifier; use criterion::{ diff --git a/crates/json-abi/benches/json_abi.rs b/crates/json-abi/benches/json_abi.rs index ff80deff5..642425b6a 100644 --- a/crates/json-abi/benches/json_abi.rs +++ b/crates/json-abi/benches/json_abi.rs @@ -1,3 +1,5 @@ +#![allow(clippy::incompatible_msrv)] + use criterion::{ criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; diff --git a/crates/json-abi/src/param.rs b/crates/json-abi/src/param.rs index 782005b9f..90b0d2792 100644 --- a/crates/json-abi/src/param.rs +++ b/crates/json-abi/src/param.rs @@ -521,6 +521,7 @@ impl EventParam { #[derive(Deserialize, Serialize)] struct BorrowedParam<'a> { + #[serde(default)] name: &'a str, #[serde(rename = "type")] ty: &'a str, diff --git a/crates/json-abi/tests/abi.rs b/crates/json-abi/tests/abi.rs index 42b94e653..88ab38ce0 100644 --- a/crates/json-abi/tests/abi.rs +++ b/crates/json-abi/tests/abi.rs @@ -90,7 +90,7 @@ fn to_sol_test(path: &str, abi: &JsonAbi, run_solc: bool) { if matches!( name, // https://github.com/alloy-rs/core/issues/349 - "ZeroXExchange" | "GaugeController" | "DoubleExponentInterestSetter" + "ZeroXExchange" | "GaugeController" | "DoubleExponentInterestSetter" | "NamelessParams" ) { return; } diff --git a/crates/json-abi/tests/abi/NamelessParams.json b/crates/json-abi/tests/abi/NamelessParams.json new file mode 100644 index 000000000..2d9ce2f1f --- /dev/null +++ b/crates/json-abi/tests/abi/NamelessParams.json @@ -0,0 +1 @@ +[{"type":"event","name":"Approval","inputs":[{"name":"owner","type":"address","indexed":true},{"name":"approved","type":"address","indexed":true},{"name":"tokenId","type":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"ApprovalForAll","inputs":[{"name":"owner","type":"address","indexed":true},{"name":"operator","type":"address","indexed":true},{"name":"approved","type":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"CancelLockupStream","inputs":[{"name":"streamId","type":"uint256","indexed":false},{"name":"sender","type":"address","indexed":true},{"name":"recipient","type":"address","indexed":true},{"name":"asset","type":"address","indexed":true},{"name":"senderAmount","type":"uint128","indexed":false},{"name":"recipientAmount","type":"uint128","indexed":false}],"anonymous":false},{"type":"event","name":"CreateLockupDynamicStream","inputs":[{"name":"streamId","type":"uint256","indexed":false},{"name":"funder","type":"address","indexed":false},{"name":"sender","type":"address","indexed":true},{"name":"recipient","type":"address","indexed":true},{"name":"amounts","type":"tuple","indexed":false,"components":[{"type":"uint128"},{"type":"uint128"},{"type":"uint128"}]},{"name":"asset","type":"address","indexed":true},{"name":"cancelable","type":"bool","indexed":false},{"name":"transferable","type":"bool","indexed":false},{"name":"segments","type":"tuple[]","indexed":false,"components":[{"type":"uint128"},{"type":"uint64"},{"type":"uint40"}]},{"name":"range","type":"tuple","indexed":false,"components":[{"type":"uint40"},{"type":"uint40"}]},{"name":"broker","type":"address","indexed":false}],"anonymous":false},{"type":"event","name":"CreateLockupLinearStream","inputs":[{"name":"streamId","type":"uint256","indexed":false},{"name":"funder","type":"address","indexed":false},{"name":"sender","type":"address","indexed":true},{"name":"recipient","type":"address","indexed":true},{"name":"amounts","type":"tuple","indexed":false,"components":[{"type":"uint128"},{"type":"uint128"},{"type":"uint128"}]},{"name":"asset","type":"address","indexed":true},{"name":"cancelable","type":"bool","indexed":false},{"name":"transferable","type":"bool","indexed":false},{"name":"range","type":"tuple","indexed":false,"components":[{"type":"uint40"},{"type":"uint40"},{"type":"uint40"}]},{"name":"broker","type":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RenounceLockupStream","inputs":[{"name":"streamId","type":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"name":"from","type":"address","indexed":true},{"name":"to","type":"address","indexed":true},{"name":"tokenId","type":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"TransferAdmin","inputs":[{"name":"oldAdmin","type":"address","indexed":true},{"name":"newAdmin","type":"address","indexed":true}],"anonymous":false},{"type":"event","name":"WithdrawFromLockupStream","inputs":[{"name":"streamId","type":"uint256","indexed":true},{"name":"to","type":"address","indexed":true},{"name":"asset","type":"address","indexed":true},{"name":"amount","type":"uint128","indexed":false}],"anonymous":false}] \ No newline at end of file diff --git a/crates/json-abi/tests/abi/NamelessParams.sol b/crates/json-abi/tests/abi/NamelessParams.sol new file mode 100644 index 000000000..757bcfd0a --- /dev/null +++ b/crates/json-abi/tests/abi/NamelessParams.sol @@ -0,0 +1,11 @@ +interface NamelessParams { + event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); + event ApprovalForAll(address indexed owner, address indexed operator, bool approved); + event CancelLockupStream(uint256 streamId, address indexed sender, address indexed recipient, address indexed asset, uint128 senderAmount, uint128 recipientAmount); + event CreateLockupDynamicStream(uint256 streamId, address funder, address indexed sender, address indexed recipient, (uint128, uint128, uint128) amounts, address indexed asset, bool cancelable, bool transferable, (uint128, uint64, uint40)[] segments, (uint40, uint40) range, address broker); + event CreateLockupLinearStream(uint256 streamId, address funder, address indexed sender, address indexed recipient, (uint128, uint128, uint128) amounts, address indexed asset, bool cancelable, bool transferable, (uint40, uint40, uint40) range, address broker); + event RenounceLockupStream(uint256 indexed streamId); + event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); + event TransferAdmin(address indexed oldAdmin, address indexed newAdmin); + event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, address indexed asset, uint128 amount); +} \ No newline at end of file diff --git a/crates/primitives/benches/primitives.rs b/crates/primitives/benches/primitives.rs index ed4b89fc0..450426152 100644 --- a/crates/primitives/benches/primitives.rs +++ b/crates/primitives/benches/primitives.rs @@ -1,3 +1,5 @@ +#![allow(clippy::incompatible_msrv)] + use alloy_primitives::{keccak256, Address, B256}; use criterion::{criterion_group, criterion_main, Criterion}; use std::hint::black_box; diff --git a/crates/sol-types/src/types/data_type.rs b/crates/sol-types/src/types/data_type.rs index d31a1b5d4..c9ffcb9aa 100644 --- a/crates/sol-types/src/types/data_type.rs +++ b/crates/sol-types/src/types/data_type.rs @@ -1083,6 +1083,14 @@ impl NameBuffer { digits += 1; } + // TODO(MSRV-1.67): Uncomment and remove everything above + /* + let Some(digits) = number.checked_ilog10() else { + return self.write_byte(b'0'); + }; + let digits = digits as usize + 1; + */ + let mut n = number; let mut i = self.len + digits; while n > 0 {