Skip to content

Commit a4b3c89

Browse files
committed
chore: docs
1 parent af4e012 commit a4b3c89

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

crates/cheatcodes/src/json.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ pub(super) fn parse_json_coerce(json: &str, path: &str, ty: &DynSolType) -> Resu
328328
parse_json_as(&value, ty).map(|v| v.abi_encode())
329329
}
330330

331+
/// Parses given [serde_json::Value] as a [DynSolValue].
331332
pub(super) fn parse_json_as(value: &Value, ty: &DynSolType) -> Result<DynSolValue> {
332333
let to_string = |v: &Value| {
333334
let mut s = v.to_string();
@@ -351,7 +352,7 @@ pub(super) fn parse_json_array(array: &[Value], ty: &DynSolType) -> Result<DynSo
351352
let (inner, fixed_len) = match ty {
352353
DynSolType::FixedArray(inner, len) => (inner, Some(*len)),
353354
DynSolType::Array(inner) => (inner, None),
354-
_ => bail!("expected array type"),
355+
_ => bail!("expected {ty}, found array"),
355356
};
356357

357358
let values = array.iter().map(|e| parse_json_as(e, inner)).collect::<Result<Vec<_>>>()?;
@@ -366,7 +367,7 @@ pub(super) fn parse_json_array(array: &[Value], ty: &DynSolType) -> Result<DynSo
366367

367368
pub(super) fn parse_json_map(map: &Map<String, Value>, ty: &DynSolType) -> Result<DynSolValue> {
368369
let Some((_, fields, types)) = ty.as_custom_struct() else {
369-
bail!("expected struct type");
370+
bail!("expected {ty}, found JSON object");
370371
};
371372

372373
let mut values = Vec::with_capacity(fields.len());
@@ -571,6 +572,7 @@ where
571572
s
572573
}
573574

575+
/// Resolves a [DynSolType] from user input.
574576
fn resolve_type(type_description: &str) -> Result<DynSolType> {
575577
if let Ok(ty) = DynSolType::parse(type_description) {
576578
return Ok(ty);

crates/cheatcodes/src/toml.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Cheatcode for parseTomlUintCall {
4545
impl Cheatcode for parseTomlUintArrayCall {
4646
fn apply(&self, _state: &mut Cheatcodes) -> Result {
4747
let Self { toml, key } = self;
48-
parse_toml_coerce(toml, key, &DynSolType::Uint(256))
48+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::Uint(256))))
4949
}
5050
}
5151

@@ -59,7 +59,7 @@ impl Cheatcode for parseTomlIntCall {
5959
impl Cheatcode for parseTomlIntArrayCall {
6060
fn apply(&self, _state: &mut Cheatcodes) -> Result {
6161
let Self { toml, key } = self;
62-
parse_toml_coerce(toml, key, &DynSolType::Int(256))
62+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::Int(256))))
6363
}
6464
}
6565

@@ -73,7 +73,7 @@ impl Cheatcode for parseTomlBoolCall {
7373
impl Cheatcode for parseTomlBoolArrayCall {
7474
fn apply(&self, _state: &mut Cheatcodes) -> Result {
7575
let Self { toml, key } = self;
76-
parse_toml_coerce(toml, key, &DynSolType::Bool)
76+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::Bool)))
7777
}
7878
}
7979

@@ -87,7 +87,7 @@ impl Cheatcode for parseTomlAddressCall {
8787
impl Cheatcode for parseTomlAddressArrayCall {
8888
fn apply(&self, _state: &mut Cheatcodes) -> Result {
8989
let Self { toml, key } = self;
90-
parse_toml_coerce(toml, key, &DynSolType::Address)
90+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::Address)))
9191
}
9292
}
9393

@@ -101,7 +101,7 @@ impl Cheatcode for parseTomlStringCall {
101101
impl Cheatcode for parseTomlStringArrayCall {
102102
fn apply(&self, _state: &mut Cheatcodes) -> Result {
103103
let Self { toml, key } = self;
104-
parse_toml_coerce(toml, key, &DynSolType::String)
104+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::String)))
105105
}
106106
}
107107

@@ -115,7 +115,7 @@ impl Cheatcode for parseTomlBytesCall {
115115
impl Cheatcode for parseTomlBytesArrayCall {
116116
fn apply(&self, _state: &mut Cheatcodes) -> Result {
117117
let Self { toml, key } = self;
118-
parse_toml_coerce(toml, key, &DynSolType::Bytes)
118+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::Bytes)))
119119
}
120120
}
121121

@@ -129,7 +129,7 @@ impl Cheatcode for parseTomlBytes32Call {
129129
impl Cheatcode for parseTomlBytes32ArrayCall {
130130
fn apply(&self, _state: &mut Cheatcodes) -> Result {
131131
let Self { toml, key } = self;
132-
parse_toml_coerce(toml, key, &DynSolType::FixedBytes(32))
132+
parse_toml_coerce(toml, key, &DynSolType::Array(Box::new(DynSolType::FixedBytes(32))))
133133
}
134134
}
135135

crates/forge/bin/cmd/eip712.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl Eip712Args {
7474
}
7575
}
7676

77+
/// AST [Visitor] used for collecting struct definitions.
7778
#[derive(Debug, Clone, Default)]
7879
struct StructCollector(BTreeMap<usize, StructDefinition>);
7980

@@ -86,7 +87,7 @@ impl Visitor for StructCollector {
8687
/// Collects mapping from AST id of type definition to representation of this type for EIP-712
8788
/// encoding.
8889
///
89-
/// For now, maps contract definitions to address and enums to uint8
90+
/// For now, maps contract definitions to `address` and enums to `uint8`.
9091
#[derive(Debug, Clone, Default)]
9192
struct SimpleCustomTypesCollector(BTreeMap<usize, String>);
9293

@@ -123,6 +124,10 @@ impl Resolver {
123124
Self { simple_types, structs }
124125
}
125126

127+
/// Converts a given struct definition into EIP-712 `encodeType` representation.
128+
///
129+
/// Returns `None` if struct contains any fields that are not supported by EIP-712 (e.g.
130+
/// mappings or function pointers).
126131
pub fn resolve_struct_eip712(
127132
&self,
128133
id: usize,
@@ -229,8 +234,8 @@ fn parse_array_length(type_description: &TypeDescriptions) -> Result<Option<&str
229234
};
230235

231236
if inside_brackets.is_empty() {
232-
return Ok(None)
237+
Ok(None)
233238
} else {
234-
return Ok(Some(inside_brackets))
239+
Ok(Some(inside_brackets))
235240
}
236241
}

testdata/default/cheats/Json.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ contract ParseJsonTest is DSTest {
9797
}
9898

9999
function test_coercionRevert() public {
100-
vm._expectCheatcodeRevert("values at \".nestedObject\" must not be JSON objects");
100+
vm._expectCheatcodeRevert("expected uint256, found JSON object");
101101
vm.parseJsonUint(json, ".nestedObject");
102102
}
103103

testdata/default/cheats/Toml.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ contract ParseTomlTest is DSTest {
116116
}
117117

118118
function test_coercionRevert() public {
119-
vm._expectCheatcodeRevert("values at \".nestedObject\" must not be JSON objects");
119+
vm._expectCheatcodeRevert("expected uint256, found JSON object");
120120
vm.parseTomlUint(toml, ".nestedObject");
121121
}
122122

0 commit comments

Comments
 (0)