Skip to content

Commit

Permalink
fix valid large negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
plotchy committed Jun 27, 2024
1 parent b144707 commit c10824b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions crates/solc-expressions/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,25 @@ mod tests {

#[test]
fn test_hex_num_literal_large_negative() -> Result<()> {
let hex_literal = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // max U256
let expected = Concrete::Int(256, I256::from_dec_str("-1").unwrap());
let hex_literal = "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // -1
let expected = Concrete::Int(
256,
I256::from_dec_str(
"-57896044618658097711785492504343953926634992332820282019728792003956564819967",
)
.unwrap(),
);
test_hex_num_literal(hex_literal, true, expected)
}

#[test]
fn test_hex_num_literal_too_large_negative() -> Result<()> {
let hex_literal = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // max U256
let expected = Concrete::Int(256, I256::default()); // doesn't matter since it's out of range
assert!(test_hex_num_literal(hex_literal, true, expected).is_err());
Ok(())
}

#[test]
fn test_hex_num_literal_zero() -> Result<()> {
let hex_literal = "0"; // zero
Expand Down Expand Up @@ -637,9 +651,15 @@ mod tests {
}

#[test]
fn test_hex_num_literal_just_above_min_negative() -> Result<()> {
let hex_literal = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; // just above min I256
let expected = Concrete::Int(256, I256::from_dec_str("-2").unwrap());
fn test_hex_num_literal_negative_just_above_min_negative() -> Result<()> {
let hex_literal = "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; // just above min I256
let expected = Concrete::Int(
256,
I256::from_dec_str(
"-57896044618658097711785492504343953926634992332820282019728792003956564819966",
)
.unwrap(),
);
test_hex_num_literal(hex_literal, true, expected)
}

Expand Down

0 comments on commit c10824b

Please sign in to comment.