alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

[Bug] sol! macro does not generate enum types from JSON ABI specifications #593

Closed rubydusa closed 5 months ago

rubydusa commented 5 months ago

Component

sol! macro

What version of Alloy are you on?

0.7.0

Operating System

Linux

Describe the bug

sol! macro does not generate enum types for enums within a contract when the macro is used with a json abi. Contract.sol:

pragma solidity ^0.8.0;

contract Contract {
    enum Enum {
        A,
        B,
        C
    }
}

main.rs:

use alloy::sol;

sol!(Contract, "src/Contract.json");

sol! {
    contract Contract2 {
        enum Enum2 {
            A2,
            B2,
            C2
        }
    }
}

// doesn't compile
fn main() {
    let a = Contract::Enum::A; // throws an error
    let a2 = Contract2::Enum2::A2; // doesn't throw an error
}

I've linked a repo so the exact json artifact I tested against is available:

https://github.com/rubydusa/alloy-json-abi-enum-bug.git