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

chore: assert_eq! on Ok instead of unwrapping where possible #297

Merged
merged 1 commit into from
Sep 24, 2023
Merged
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
6 changes: 3 additions & 3 deletions crates/dyn-abi/src/eip712/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ mod tests {
let top = j.as_object().unwrap().get("message").unwrap();

assert_eq!(
ty.coerce(top).unwrap(),
DynSolValue::CustomStruct {
ty.coerce(top),
Ok(DynSolValue::CustomStruct {
name: "Message".to_owned(),
prop_names: vec!["contents".to_string(), "from".to_string(), "to".to_string()],
tuple: vec![
Expand Down Expand Up @@ -337,7 +337,7 @@ mod tests {
}]
.into()
]
}
})
);
}
}
12 changes: 6 additions & 6 deletions crates/dyn-abi/src/eip712/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,32 @@ mod tests {
#[test]
fn test_component_type() {
assert_eq!(
ComponentType::try_from("Transaction(Person from,Person to,Asset tx)").unwrap(),
ComponentType {
ComponentType::try_from("Transaction(Person from,Person to,Asset tx)"),
Ok(ComponentType {
span: "Transaction(Person from,Person to,Asset tx)",
type_name: "Transaction",
props: vec![
"Person from".try_into().unwrap(),
"Person to".try_into().unwrap(),
"Asset tx".try_into().unwrap(),
],
}
})
);
}

#[test]
fn test_encode_type() {
assert_eq!(
EncodeType::try_from(EXAMPLE).unwrap(),
EncodeType {
EncodeType::try_from(EXAMPLE),
Ok(EncodeType {
types: vec![
"Transaction(Person from,Person to,Asset tx)"
.try_into()
.unwrap(),
"Asset(address token,uint256 amount)".try_into().unwrap(),
"Person(address wallet,string name)".try_into().unwrap(),
]
}
})
);
}
}
12 changes: 6 additions & 6 deletions crates/dyn-abi/src/eip712/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ mod tests {
prop_names: vec!["myB".to_string()],
tuple: vec![b.clone()],
};
assert_eq!(graph.resolve("A").unwrap(), a);
assert_eq!(graph.resolve("B").unwrap(), b);
assert_eq!(graph.resolve("C").unwrap(), c);
assert_eq!(graph.resolve("A"), Ok(a));
assert_eq!(graph.resolve("B"), Ok(b));
assert_eq!(graph.resolve("C"), Ok(c));
}

#[test]
Expand Down Expand Up @@ -630,9 +630,9 @@ mod tests {
prop_names: vec!["myB".to_string()],
tuple: vec![b.clone()],
};
assert_eq!(graph.resolve("C").unwrap(), c);
assert_eq!(graph.resolve("B").unwrap(), b);
assert_eq!(graph.resolve("A").unwrap(), a);
assert_eq!(graph.resolve("C"), Ok(c));
assert_eq!(graph.resolve("B"), Ok(b));
assert_eq!(graph.resolve("A"), Ok(a));
}

#[test]
Expand Down
76 changes: 41 additions & 35 deletions crates/dyn-abi/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,48 +210,54 @@ mod tests {
#[test]
fn it_parses_tuples() {
assert_eq!(
parse("(bool,)").unwrap(),
DynSolType::Tuple(vec![DynSolType::Bool])
parse("(bool,)"),
Ok(DynSolType::Tuple(vec![DynSolType::Bool]))
);
assert_eq!(
parse("(uint256,uint256)").unwrap(),
DynSolType::Tuple(vec![DynSolType::Uint(256), DynSolType::Uint(256)])
parse("(uint256,uint256)"),
Ok(DynSolType::Tuple(vec![
DynSolType::Uint(256),
DynSolType::Uint(256)
]))
);
assert_eq!(
parse("(uint256,uint256)[2]").unwrap(),
DynSolType::FixedArray(
parse("(uint256,uint256)[2]"),
Ok(DynSolType::FixedArray(
Box::new(DynSolType::Tuple(vec![
DynSolType::Uint(256),
DynSolType::Uint(256)
])),
2
)
))
);
}

#[test]
fn nested_tuples() {
assert_eq!(
parse("(bool,(uint256,uint256))").unwrap(),
DynSolType::Tuple(vec![
parse("(bool,(uint256,uint256))"),
Ok(DynSolType::Tuple(vec![
DynSolType::Bool,
DynSolType::Tuple(vec![DynSolType::Uint(256), DynSolType::Uint(256)])
])
]))
);
assert_eq!(
parse("(((bool),),)").unwrap(),
DynSolType::Tuple(vec![DynSolType::Tuple(vec![DynSolType::Tuple(vec![
DynSolType::Bool
])])])
parse("(((bool),),)"),
Ok(DynSolType::Tuple(vec![DynSolType::Tuple(vec![
DynSolType::Tuple(vec![DynSolType::Bool])
])]))
);
}

#[test]
fn empty_tuples() {
assert_eq!(parse("()").unwrap(), DynSolType::Tuple(vec![]));
assert_eq!(parse("()"), Ok(DynSolType::Tuple(vec![])));
assert_eq!(
parse("((),())").unwrap(),
DynSolType::Tuple(vec![DynSolType::Tuple(vec![]), DynSolType::Tuple(vec![])])
parse("((),())"),
Ok(DynSolType::Tuple(vec![
DynSolType::Tuple(vec![]),
DynSolType::Tuple(vec![])
]))
);
assert_eq!(
parse("((()))"),
Expand All @@ -263,37 +269,37 @@ mod tests {

#[test]
fn it_parses_simple_types() {
assert_eq!(parse("uint256").unwrap(), DynSolType::Uint(256));
assert_eq!(parse("uint8").unwrap(), DynSolType::Uint(8));
assert_eq!(parse("uint").unwrap(), DynSolType::Uint(256));
assert_eq!(parse("address").unwrap(), DynSolType::Address);
assert_eq!(parse("bool").unwrap(), DynSolType::Bool);
assert_eq!(parse("string").unwrap(), DynSolType::String);
assert_eq!(parse("bytes").unwrap(), DynSolType::Bytes);
assert_eq!(parse("bytes32").unwrap(), DynSolType::FixedBytes(32));
assert_eq!(parse("uint256"), Ok(DynSolType::Uint(256)));
assert_eq!(parse("uint8"), Ok(DynSolType::Uint(8)));
assert_eq!(parse("uint"), Ok(DynSolType::Uint(256)));
assert_eq!(parse("address"), Ok(DynSolType::Address));
assert_eq!(parse("bool"), Ok(DynSolType::Bool));
assert_eq!(parse("string"), Ok(DynSolType::String));
assert_eq!(parse("bytes"), Ok(DynSolType::Bytes));
assert_eq!(parse("bytes32"), Ok(DynSolType::FixedBytes(32)));
}

#[test]
fn it_parses_complex_solidity_types() {
assert_eq!(
parse("uint256[]").unwrap(),
DynSolType::Array(Box::new(DynSolType::Uint(256)))
parse("uint256[]"),
Ok(DynSolType::Array(Box::new(DynSolType::Uint(256))))
);
assert_eq!(
parse("uint256[2]").unwrap(),
DynSolType::FixedArray(Box::new(DynSolType::Uint(256)), 2)
parse("uint256[2]"),
Ok(DynSolType::FixedArray(Box::new(DynSolType::Uint(256)), 2))
);
assert_eq!(
parse("uint256[2][3]").unwrap(),
DynSolType::FixedArray(
parse("uint256[2][3]"),
Ok(DynSolType::FixedArray(
Box::new(DynSolType::FixedArray(Box::new(DynSolType::Uint(256)), 2)),
3
)
))
);
assert_eq!(
parse("uint256[][][]").unwrap(),
DynSolType::Array(Box::new(DynSolType::Array(Box::new(DynSolType::Array(
Box::new(DynSolType::Uint(256))
parse("uint256[][][]"),
Ok(DynSolType::Array(Box::new(DynSolType::Array(Box::new(
DynSolType::Array(Box::new(DynSolType::Uint(256)))
)))))
);

Expand Down