diff --git a/crates/forge/bin/cmd/eip712.rs b/crates/forge/bin/cmd/eip712.rs index 2ab15f05488e..5014d38d703b 100644 --- a/crates/forge/bin/cmd/eip712.rs +++ b/crates/forge/bin/cmd/eip712.rs @@ -126,7 +126,9 @@ impl Resolver { /// Returns `None` if struct contains any fields that are not supported by EIP-712 (e.g. /// mappings or function pointers). pub fn resolve_struct_eip712(&self, id: usize) -> Result> { - self.resolve_eip712_inner(id, &mut Default::default(), true, None) + let mut subtypes = BTreeMap::new(); + subtypes.insert(self.structs[&id].name.clone(), id); + self.resolve_eip712_inner(id, &mut subtypes, true, None) } fn resolve_eip712_inner( @@ -205,8 +207,17 @@ impl Resolver { // If we've already seen struct with this ID, just use assigned name. if let Some((name, _)) = subtypes.iter().find(|(_, id)| **id == def.id) { name.clone() - // Otherwise, try assigning a new name. } else { + // Otherwise, assign new name. + let mut i = 0; + let mut name = def.name.clone(); + while subtypes.contains_key(&name) { + i += 1; + name = format!("{}_{i}", def.name); + } + + subtypes.insert(name.clone(), def.id); + // iterate over members to check if they are resolvable and to populate subtypes for member in &def.members { if self.resolve_type( @@ -218,14 +229,6 @@ impl Resolver { return Ok(None) } } - let mut i = 0; - let mut name = def.name.clone(); - while subtypes.contains_key(&name) { - i += 1; - name = format!("{}_{i}", def.name); - } - - subtypes.insert(name.clone(), def.id); name }; diff --git a/crates/forge/tests/cli/eip712.rs b/crates/forge/tests/cli/eip712.rs index 2f832ae315c6..9ec944631d9d 100644 --- a/crates/forge/tests/cli/eip712.rs +++ b/crates/forge/tests/cli/eip712.rs @@ -19,6 +19,11 @@ library Structs { struct Complex { Structs2.Foo foo2; Foo[] foos; + Rec[][] recs; + } + + struct Rec { + Rec[] rec; } } @@ -26,6 +31,23 @@ library Structs2 { struct Foo { uint256 id; } + + struct Rec { + Bar[] bar; + } + + struct Bar { + Rec rec; + } + + struct FooBar { + Foo[] foos; + Bar[] bars; + Structs.Foo foo; + Structs.Bar bar; + Rec[] recs; + Structs.Rec rec; + } } "#, ) @@ -42,10 +64,18 @@ Bar(Art art)Art(uint256 id) Art(uint256 id) -Complex(Foo foo2,Foo_1[] foos)Art(uint256 id)Bar(Art art)Foo(uint256 id)Foo_1(Bar bar) +Complex(Foo foo2,Foo_1[] foos,Rec[][] recs)Art(uint256 id)Bar(Art art)Foo(uint256 id)Foo_1(Bar bar)Rec(Rec[] rec) + +Rec(Rec[] rec) Foo(uint256 id) +Rec(Bar[] bar)Bar(Rec rec) + +Bar(Rec rec)Rec(Bar[] bar) + +FooBar(Foo[] foos,Bar[] bars,Foo_1 foo,Bar_1 bar,Rec[] recs,Rec_1 rec)Art(uint256 id)Bar(Rec rec)Bar_1(Art art)Foo(uint256 id)Foo_1(Bar_1 bar)Rec(Bar[] bar)Rec_1(Rec_1[] rec) + "#]], );