From 3c0d94c779be3c38ac8cbcf1d5cab96314b49caa Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:01:36 +0530 Subject: [PATCH] fix tests --- crates/core/tests/sol.rs | 1 + crates/sol-macro/doctests/contracts.rs | 1 + crates/sol-macro/doctests/json.rs | 2 + crates/sol-types/src/types/error.rs | 1 + crates/sol-types/src/types/interface/mod.rs | 2 + crates/sol-types/tests/macros/sol/abi.rs | 2 +- crates/sol-types/tests/macros/sol/json.rs | 72 +++++++++++++++++---- crates/sol-types/tests/macros/sol/mod.rs | 26 ++++++-- tests/core-sol/src/lib.rs | 2 + 9 files changed, 90 insertions(+), 19 deletions(-) diff --git a/crates/core/tests/sol.rs b/crates/core/tests/sol.rs index 2da1bfe29..82eab52d8 100644 --- a/crates/core/tests/sol.rs +++ b/crates/core/tests/sol.rs @@ -13,6 +13,7 @@ sol! { event MyEvent(uint32 a, uint32 b); error MyError(uint32 a, uint32 b); + #[sol(rpc = false)] contract MyContract { struct MyOtherStruct { uint32 a; diff --git a/crates/sol-macro/doctests/contracts.rs b/crates/sol-macro/doctests/contracts.rs index aa1bd5bed..720d25ba8 100644 --- a/crates/sol-macro/doctests/contracts.rs +++ b/crates/sol-macro/doctests/contracts.rs @@ -6,6 +6,7 @@ sol! { /// /// [the EIP]: https://eips.ethereum.org/EIPS/eip-20 #[derive(Debug, PartialEq, Eq)] + #[sol(rpc = false)] contract ERC20 { mapping(address account => uint256) public balanceOf; diff --git a/crates/sol-macro/doctests/json.rs b/crates/sol-macro/doctests/json.rs index 4ccfcf54d..6ce61b144 100644 --- a/crates/sol-macro/doctests/json.rs +++ b/crates/sol-macro/doctests/json.rs @@ -1,6 +1,7 @@ use alloy_sol_types::{sol, SolCall}; sol!( + #[sol(rpc = false)] MyJsonContract1, r#"[ { @@ -26,6 +27,7 @@ sol!( // This is the same as: sol! { + #[sol(rpc = false)] interface MyJsonContract2 { struct MyStruct { bool[] a; diff --git a/crates/sol-types/src/types/error.rs b/crates/sol-types/src/types/error.rs index b51d31400..e4b911086 100644 --- a/crates/sol-types/src/types/error.rs +++ b/crates/sol-types/src/types/error.rs @@ -499,6 +499,7 @@ mod tests { #[test] fn decode_solidity_no_interface() { sol! { + #[sol(rpc = false)] interface C { #[derive(Debug, PartialEq)] error SenderAddressError(address); diff --git a/crates/sol-types/src/types/interface/mod.rs b/crates/sol-types/src/types/interface/mod.rs index a054cf1e3..0cdfa5141 100644 --- a/crates/sol-types/src/types/interface/mod.rs +++ b/crates/sol-types/src/types/interface/mod.rs @@ -535,6 +535,7 @@ mod tests { #[test] fn contract_error_enum_1() { crate::sol! { + #[sol(rpc = false)] contract C { error Err1(); } @@ -564,6 +565,7 @@ mod tests { fn contract_error_enum_2() { crate::sol! { #[derive(Debug, PartialEq, Eq)] + #[sol(rpc = false)] contract C { error Err1(); error Err2(uint256); diff --git a/crates/sol-types/tests/macros/sol/abi.rs b/crates/sol-types/tests/macros/sol/abi.rs index a3bb4d37b..a3120af89 100644 --- a/crates/sol-types/tests/macros/sol/abi.rs +++ b/crates/sol-types/tests/macros/sol/abi.rs @@ -462,7 +462,7 @@ fn custom() { } sol! { - #![sol(abi)] + #![sol(rpc = false, abi)] #[allow(dead_code)] contract Contract { diff --git a/crates/sol-types/tests/macros/sol/json.rs b/crates/sol-types/tests/macros/sol/json.rs index 8751a598f..227d3deda 100644 --- a/crates/sol-types/tests/macros/sol/json.rs +++ b/crates/sol-types/tests/macros/sol/json.rs @@ -7,7 +7,7 @@ use std::borrow::Cow; #[test] fn large_array() { sol!( - #[sol(abi)] + #[sol(rpc = false, abi)] #[derive(Debug)] LargeArray, "../json-abi/tests/abi/LargeArray.json" @@ -47,7 +47,11 @@ fn large_array() { #[test] fn seaport() { - sol!(Seaport, "../json-abi/tests/abi/Seaport.json"); + sol!( + #[sol(rpc = false)] + Seaport, + "../json-abi/tests/abi/Seaport.json" + ); use Seaport::*; // Constructor with a single argument @@ -71,7 +75,7 @@ fn seaport() { // https://etherscan.io/address/0x1111111254eeb25477b68fb85ed929f73a960582#code sol!( - #[sol(docs = false)] + #![sol(rpc = false, docs = false)] #[derive(Debug)] AggregationRouterV5, "../json-abi/tests/abi/AggregationRouterV5.json" @@ -93,7 +97,11 @@ fn aggregation_router_v5() { #[test] fn uniswap_v3_position() { // https://etherscan.io/address/0x8638fbd429b19249bb3bcf3ec72d07a657e49642#code - sol!(UniswapV3Position, "../json-abi/tests/abi/UniswapV3Position.json"); + sol!( + #[sol(rpc = false)] + UniswapV3Position, + "../json-abi/tests/abi/UniswapV3Position.json" + ); let _ = UniswapV3Position::getLiquidityByRangeCall { pool_: Address::ZERO, @@ -122,7 +130,11 @@ fn uniswap_v3_position() { #[test] fn double_exponent_interest_setter() { // https://etherscan.io/address/0xef2ed07cc7a0825ced8ac1a67f88a0e17414fa6c#code - sol!(DoubleExponentInterestSetter, "../json-abi/tests/abi/DoubleExponentInterestSetter.json"); + sol!( + #[sol(rpc = false)] + DoubleExponentInterestSetter, + "../json-abi/tests/abi/DoubleExponentInterestSetter.json" + ); let _ = DoubleExponentInterestSetter::getInterestRateCall { _0: Address::ZERO, borrowWei: U256::ZERO, @@ -134,7 +146,11 @@ fn double_exponent_interest_setter() { // https://github.com/alloy-rs/core/issues/361 #[test] fn uniswap_v2_factory() { - sol!(UniswapV2Factory, "../json-abi/tests/abi/UniswapV2Factory.json"); + sol!( + #[sol(rpc = false)] + UniswapV2Factory, + "../json-abi/tests/abi/UniswapV2Factory.json" + ); let _ = UniswapV2Factory::PairCreated { token0: Address::ZERO, token1: Address::ZERO, @@ -143,7 +159,11 @@ fn uniswap_v2_factory() { }; } -sol!(GnosisSafe, "../json-abi/tests/abi/GnosisSafe.json"); +sol!( + #![sol(rpc = false)] + GnosisSafe, + "../json-abi/tests/abi/GnosisSafe.json" +); // Fully qualify `SolInterface::NAME` which conflicted with the `NAME` call // https://github.com/alloy-rs/core/issues/361 @@ -157,14 +177,22 @@ fn gnosis_safe() { // https://github.com/alloy-rs/core/issues/371 #[test] fn blur_exchange() { - sol!(BlurExchange, "../json-abi/tests/abi/BlurExchange.json"); + sol!( + #[sol(rpc = false)] + BlurExchange, + "../json-abi/tests/abi/BlurExchange.json" + ); let BlurExchange::NAMECall {} = BlurExchange::NAMECall {}; let BlurExchange::NAMEReturn { _0: _ } = BlurExchange::NAMEReturn { _0: String::new() }; } #[test] fn zerox_exchange_proxy() { - sol!(ZeroXExchangeProxy, "../json-abi/tests/abi/ZeroxExchangeProxy.json"); + sol!( + #[sol(rpc = false)] + ZeroXExchangeProxy, + "../json-abi/tests/abi/ZeroxExchangeProxy.json" + ); } // TODO: Error and event with the same name @@ -173,7 +201,11 @@ fn zerox_exchange_proxy() { #[cfg(any())] fn auction() { // https://etherscan.io/address/0xbb37a88508d464a1bb54cf627d05e39883ae0ef9 - sol!(Auction, "../json-abi/tests/abi/Auction.json"); + sol!( + #[sol(rpc = false)] + Auction, + "../json-abi/tests/abi/Auction.json" + ); } // https://github.com/alloy-rs/core/issues/378 @@ -183,14 +215,22 @@ fn uniswap_v2_factory_with_migrator() { // https://etherscan.io/address/0x1ffbe925f22fca796adf2a63313b8b70b5b1a7f4 // https://etherscan.io/address/0xc1a2706ceb8c21967d5c930c00c8ed16480f7255 - sol!(UniswapV2FactoryWithMigrator, "../json-abi/tests/abi/UniswapV2FactoryWithMigrator.json"); + sol!( + #[sol(rpc = false)] + UniswapV2FactoryWithMigrator, + "../json-abi/tests/abi/UniswapV2FactoryWithMigrator.json" + ); } // https://github.com/alloy-rs/core/issues/379 #[test] fn junkyard() { // https://etherscan.io/address/0x2e4b0f20bdb1caa0886c531256efdaab925dbe72 - sol!(Junkyard, "../json-abi/tests/abi/Junkyard.json"); + sol!( + #[sol(rpc = false)] + Junkyard, + "../json-abi/tests/abi/Junkyard.json" + ); } // Handle missing state mutability in JSON ABI @@ -198,7 +238,11 @@ fn junkyard() { #[test] fn zrx_token() { // https://etherscan.io/address/0xe41d2489571d322189246dafa5ebde1f4699f498#code - sol!(ZRXToken, "../json-abi/tests/abi/ZRXToken.json"); + sol!( + #[sol(rpc = false)] + ZRXToken, + "../json-abi/tests/abi/ZRXToken.json" + ); let _ = ZRXToken::approveCall { _spender: Address::ZERO, _value: U256::ZERO }; assert_eq!(ZRXToken::approveCall::SIGNATURE, "approve(address,uint256)"); @@ -206,7 +250,7 @@ fn zrx_token() { // https://etherscan.io/address/0xBA12222222228d8Ba445958a75a0704d566BF2C8#code sol!( - #![sol(all_derives)] + #![sol(rpc = false, all_derives)] BalancerV2Vault, "../json-abi/tests/abi/BalancerV2Vault.json" ); diff --git a/crates/sol-types/tests/macros/sol/mod.rs b/crates/sol-types/tests/macros/sol/mod.rs index 8e9d0b68d..2300e47fc 100644 --- a/crates/sol-types/tests/macros/sol/mod.rs +++ b/crates/sol-types/tests/macros/sol/mod.rs @@ -174,6 +174,7 @@ fn error() { #[test] fn empty_call() { sol! { + #[sol(rpc = false)] interface WETH { function deposit() external payable; } @@ -193,7 +194,7 @@ fn empty_call() { #[test] fn function_names() { sol! { - #[sol(extra_methods)] + #[sol(rpc = false, extra_methods)] contract LeadingUnderscores { function f(); function _f(); @@ -241,6 +242,7 @@ fn getters() { #[test] fn getter_names() { sol! { + #[sol(rpc = false)] contract Getters { string public value; string[] public array; @@ -269,12 +271,15 @@ fn getter_names() { #[test] fn abigen_sol_multicall() { - sol!("../syn-solidity/tests/contracts/Multicall.sol"); + sol!( + #[sol(rpc = false)] + "../syn-solidity/tests/contracts/Multicall.sol" + ); sol! { // SPDX-License-Identifier: MIT pragma solidity >=0.8.12 <0.9.0; - + #[sol(rpc = false)] interface IMulticall3_2 { struct Call { address target; @@ -433,6 +438,7 @@ fn nested_items() { } #[derive(Debug, PartialEq)] + #[sol(rpc = false)] interface InterfaceTest { function f1(FilAddress memory fAddress, uint256 value) public payable; @@ -470,6 +476,7 @@ fn enum_field_of_struct() { #[test] fn same_names_different_namespaces() { sol! { + #![sol(rpc = false)] library RouterErrors { error ReturnAmountIsNotEnough(); error InvalidMsgValue(); @@ -491,6 +498,7 @@ fn same_names_different_namespaces() { #[test] fn rust_keywords() { sol! { + #[sol(rpc = false)] contract dyn { struct const { bool unsafe; @@ -597,6 +605,7 @@ fn raw_identifiers() { #[test] fn contract_type() { sol! { + #[sol(rpc = false)] interface IERC20 {} function func(IERC20 addr); struct Struct { @@ -686,6 +695,7 @@ fn event_tokenize_fields() { #[test] fn duplicate_attributes() { sol! { + #[sol(rpc = false)] contract TaxableTeamToken is IERC20, Context, Ownable { constructor( string memory name, @@ -722,6 +732,7 @@ fn duplicate_attributes() { fn duplicate_events() { sol! { #[derive(derive_more::Display)] + #[sol(rpc = false)] interface Console { #[display("{val}")] event log(string val); @@ -834,7 +845,7 @@ fn decoder_fixed_array_before_dynamic() { #[test] fn bytecode_attributes() { sol! { - #[sol(bytecode = "1234", deployed_bytecode = "0x5678")] + #[sol(rpc = false, bytecode = "1234", deployed_bytecode = "0x5678")] contract Dummy {} } @@ -913,6 +924,7 @@ fn event_overrides() { fn contract_derive_default() { sol! { #[derive(Debug, Default)] + #[sol(rpc = false)] contract MyContract { function f1(); function f2(); @@ -933,6 +945,7 @@ fn contract_derive_default() { fn contract_namespaces() { mod inner { alloy_sol_types::sol! { + #![sol(rpc = false)] library LibA { struct Struct { uint64 field64; @@ -981,6 +994,7 @@ fn contract_namespaces() { #[test] fn regression_overloads() { sol! { + #[sol(rpc = false)] contract Vm { struct Wallet { uint stuff; @@ -1006,6 +1020,7 @@ fn regression_overloads() { #[test] fn normal_paths() { sol! { + #[sol(rpc = false)] interface I { struct S { uint x; @@ -1021,6 +1036,7 @@ fn normal_paths() { fn regression_nested_namespaced_structs() { mod inner { super::sol! { + #![sol(rpc = false)] library LibA { struct Simple { uint256 x; @@ -1181,6 +1197,7 @@ fn mapping_getters() { sol! { #![sol(all_derives)] + #[sol(rpc = false)] contract TestIbc { /// ConnectionId -> Connection mapping(uint32 => Connection) public connections; @@ -1252,6 +1269,7 @@ fn array_sizes() { uint constant x = 1; uint constant y = x + 1; + #[sol(rpc = false)] contract C { uint constant z = y * 2; diff --git a/tests/core-sol/src/lib.rs b/tests/core-sol/src/lib.rs index 72cd38751..aacd00605 100644 --- a/tests/core-sol/src/lib.rs +++ b/tests/core-sol/src/lib.rs @@ -38,6 +38,7 @@ sol! { } sol! { + #[sol(rpc = false)] contract MyContract { enum MyOtherEnum { A, B @@ -68,6 +69,7 @@ sol! { #[deny(missing_docs)] pub mod no_missing_docs { alloy_core::sol! { + #![sol(rpc = false)] #[allow(missing_docs)] contract Allowed { uint256 public number;