Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-atreya committed Jan 9, 2025
1 parent 544e059 commit 3c0d94c
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 19 deletions.
1 change: 1 addition & 0 deletions crates/core/tests/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions crates/sol-macro/doctests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions crates/sol-macro/doctests/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_sol_types::{sol, SolCall};

sol!(
#[sol(rpc = false)]
MyJsonContract1,
r#"[
{
Expand All @@ -26,6 +27,7 @@ sol!(

// This is the same as:
sol! {
#[sol(rpc = false)]
interface MyJsonContract2 {
struct MyStruct {
bool[] a;
Expand Down
1 change: 1 addition & 0 deletions crates/sol-types/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ mod tests {
#[test]
fn decode_solidity_no_interface() {
sol! {
#[sol(rpc = false)]
interface C {
#[derive(Debug, PartialEq)]
error SenderAddressError(address);
Expand Down
2 changes: 2 additions & 0 deletions crates/sol-types/src/types/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ mod tests {
#[test]
fn contract_error_enum_1() {
crate::sol! {
#[sol(rpc = false)]
contract C {
error Err1();
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/sol-types/tests/macros/sol/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ fn custom() {
}

sol! {
#![sol(abi)]
#![sol(rpc = false, abi)]

#[allow(dead_code)]
contract Contract {
Expand Down
72 changes: 58 additions & 14 deletions crates/sol-types/tests/macros/sol/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -183,30 +215,42 @@ 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
// https://github.com/alloy-rs/core/issues/485
#[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)");
}

// https://etherscan.io/address/0xBA12222222228d8Ba445958a75a0704d566BF2C8#code
sol!(
#![sol(all_derives)]
#![sol(rpc = false, all_derives)]
BalancerV2Vault,
"../json-abi/tests/abi/BalancerV2Vault.json"
);
Expand Down
26 changes: 22 additions & 4 deletions crates/sol-types/tests/macros/sol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ fn error() {
#[test]
fn empty_call() {
sol! {
#[sol(rpc = false)]
interface WETH {
function deposit() external payable;
}
Expand All @@ -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();
Expand Down Expand Up @@ -241,6 +242,7 @@ fn getters() {
#[test]
fn getter_names() {
sol! {
#[sol(rpc = false)]
contract Getters {
string public value;
string[] public array;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -433,6 +438,7 @@ fn nested_items() {
}

#[derive(Debug, PartialEq)]
#[sol(rpc = false)]
interface InterfaceTest {
function f1(FilAddress memory fAddress, uint256 value) public payable;

Expand Down Expand Up @@ -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();
Expand All @@ -491,6 +498,7 @@ fn same_names_different_namespaces() {
#[test]
fn rust_keywords() {
sol! {
#[sol(rpc = false)]
contract dyn {
struct const {
bool unsafe;
Expand Down Expand Up @@ -597,6 +605,7 @@ fn raw_identifiers() {
#[test]
fn contract_type() {
sol! {
#[sol(rpc = false)]
interface IERC20 {}
function func(IERC20 addr);
struct Struct {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {}
}

Expand Down Expand Up @@ -913,6 +924,7 @@ fn event_overrides() {
fn contract_derive_default() {
sol! {
#[derive(Debug, Default)]
#[sol(rpc = false)]
contract MyContract {
function f1();
function f2();
Expand All @@ -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;
Expand Down Expand Up @@ -981,6 +994,7 @@ fn contract_namespaces() {
#[test]
fn regression_overloads() {
sol! {
#[sol(rpc = false)]
contract Vm {
struct Wallet {
uint stuff;
Expand All @@ -1006,6 +1020,7 @@ fn regression_overloads() {
#[test]
fn normal_paths() {
sol! {
#[sol(rpc = false)]
interface I {
struct S {
uint x;
Expand All @@ -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;
Expand Down Expand Up @@ -1181,6 +1197,7 @@ fn mapping_getters() {
sol! {
#![sol(all_derives)]

#[sol(rpc = false)]
contract TestIbc {
/// ConnectionId -> Connection
mapping(uint32 => Connection) public connections;
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 3c0d94c

Please sign in to comment.