Skip to content

Commit

Permalink
[fix] #4084: NumericValue suffix is mandatory
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Nov 28, 2023
1 parent 302f599 commit 794fe35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Binary file modified configs/peer/executor.wasm
Binary file not shown.
14 changes: 8 additions & 6 deletions data_model/src/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloc::{
use core::{num::ParseIntError, str::FromStr};

use derive_more::From;
use iroha_primitives::fixed::{Fixed, FixedPointOperationError};
use iroha_primitives::fixed::FixedPointOperationError;
use serde::{de::Error, Deserializer, Serializer};

pub use self::model::*;
Expand Down Expand Up @@ -115,10 +115,6 @@ impl FromStr for NumericValue {
} else {
Err(ParseNumericError::Format)
}
} else if let Ok(fixed) = Fixed::from_str(s) {
// This is the only unambiguous numerical type which we
// can safely deserialize from a string.
Ok(NumericValue::Fixed(fixed))
} else {
Err(ParseNumericError::Format)
}
Expand Down Expand Up @@ -310,8 +306,14 @@ mod tests {
NumericValue::Fixed((u32::MAX as f64).try_into().expect("trivial conversion")),
];
for val in values {
let new_value: NumericValue = format!("{val}").parse().expect("Failed to parse");
let new_value: NumericValue = format!("{val:?}").parse().expect("Failed to parse");
assert_eq!(new_value, val);
}
}

#[test]
fn deserialize_without_prefix_fails() {
assert!(serde_json::from_str::<NumericValue>("\"100\"").is_err());
assert!(serde_json::from_str::<NumericValue>("\"100.0\"").is_err());
}
}

0 comments on commit 794fe35

Please sign in to comment.