Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(json-abi): accept nameless Params #526

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*.sol linguist-language=Solidity
**/tests/abi/* linguist-vendored
**/tests/contracts/* linguist-vendored
2 changes: 2 additions & 0 deletions crates/dyn-abi/benches/abi.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 2 additions & 0 deletions crates/dyn-abi/benches/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::incompatible_msrv)]

use alloy_dyn_abi::{DynSolType, ResolveSolType};
use alloy_sol_type_parser::TypeSpecifier;
use criterion::{
Expand Down
2 changes: 2 additions & 0 deletions crates/json-abi/benches/json_abi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::incompatible_msrv)]

use criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
};
Expand Down
1 change: 1 addition & 0 deletions crates/json-abi/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ impl EventParam {

#[derive(Deserialize, Serialize)]
struct BorrowedParam<'a> {
#[serde(default)]
name: &'a str,
#[serde(rename = "type")]
ty: &'a str,
Expand Down
2 changes: 1 addition & 1 deletion crates/json-abi/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions crates/json-abi/tests/abi/NamelessParams.json
Original file line number Diff line number Diff line change
@@ -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}]
11 changes: 11 additions & 0 deletions crates/json-abi/tests/abi/NamelessParams.sol
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions crates/primitives/benches/primitives.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 8 additions & 0 deletions crates/sol-types/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down