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

feat(sol!): make #[sol(rpc)] default if rpc feat enabled #852

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std = [
"alloy-rlp?/std",
]
nightly = ["alloy-primitives/nightly"]

rpc = ["alloy-sol-types?/rpc"]
dyn-abi = ["sol-types", "dep:alloy-dyn-abi"]
json-abi = ["json", "serde", "dep:alloy-json-abi"]
json = ["alloy-sol-types?/json"]
Expand Down
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-expander/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ alloy-json-abi = { workspace = true, optional = true }

[features]
json = ["dep:alloy-json-abi", "alloy-sol-macro-input/json"]
rpc = []
2 changes: 1 addition & 1 deletion crates/sol-macro-expander/src/expand/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn expand(cx: &mut ExpCtxt<'_>, contract: &ItemContract) -> Result<To
let (sol_attrs, attrs) = contract.split_attrs()?;

let extra_methods = sol_attrs.extra_methods.or(cx.attrs.extra_methods).unwrap_or(false);
let rpc = sol_attrs.rpc.or(cx.attrs.rpc).unwrap_or(false);
let rpc = sol_attrs.rpc.or(cx.attrs.rpc).unwrap_or(cfg!(feature = "rpc"));
let abi = sol_attrs.abi.or(cx.attrs.abi).unwrap_or(false);
let docs = sol_attrs.docs.or(cx.attrs.docs).unwrap_or(true);

Expand Down
1 change: 1 addition & 0 deletions crates/sol-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ syn = { workspace = true, features = ["extra-traits"] }

[features]
json = ["alloy-sol-macro-expander/json"]
rpc = ["alloy-sol-macro-expander/rpc"]
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
3 changes: 2 additions & 1 deletion crates/sol-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ use syn::parse_macro_input;
/// - `rpc [ = <bool = false>]` (contracts and alike only): generates a structs with methods to
/// construct `eth_call`s to an on-chain contract through Ethereum JSON RPC, similar to the
/// default behavior of [`abigen`]. This makes use of the [`alloy-contract`](https://github.com/alloy-rs/alloy)
/// crate.
/// crate. RPC-related code will be automatically generated if the "rpc" feature is enabled in
/// Cargo.toml removing the need to specify this `#[sol(rpc)]` attribute.
///
/// N.B: at the time of writing, the `alloy-contract` crate is not yet released on `crates.io`,
/// and its API is completely unstable and subject to change, so this feature is not yet
Expand Down
1 change: 1 addition & 0 deletions crates/sol-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ std = ["alloy-primitives/std", "hex/std", "alloy-json-abi?/std", "serde?/std"]
json = ["dep:alloy-json-abi", "alloy-sol-macro/json"]
eip712-serde = ["dep:serde", "alloy-primitives/serde"]
arbitrary = ["alloy-primitives/arbitrary"]
rpc = ["alloy-sol-macro/rpc"]
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
Loading
Loading