-
Notifications
You must be signed in to change notification settings - Fork 715
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
Improve Amount usage in api #4688
Labels
api
Issues related to the API
Comments
Some modifications should be done, we can't safely accept Massa and nanoMassa in from str. So, now the number provided is in nanoMassa not in Massa and we return errors when a decimal is provided @AurelienFT can u validate if this test verify all case #[test]
fn test_amount() {
// decimal now return error
assert!(Amount::from_str("15463.123").is_err());
assert!(Amount::from_str("100.0").is_err());
// from str now uses nanoMassa
let amount = Amount::from_str("100").unwrap(); // nanoMassa
// print no longer display massa unit as decimal
// print display nanoMassa
println!("{}", amount); // Should print 100 (nanoMassa)
// to_raw return nanoMassa as u64 like before
assert_eq!(amount.to_raw(), 100);
// to_string return nanoMassa as string
assert_eq!(amount.to_string(), "100".to_string());
let serialized_serde = serde_json::to_string(&amount).unwrap();
assert_eq!(serialized_serde, "100".to_string());
// serde from_str
let deserialized_serde: Amount = serde_json::from_str(&serialized_serde).unwrap();
// amount from_str
let deserialized_amount: Amount = Amount::from_str(&serialized_serde).unwrap();
assert_eq!(deserialized_serde.to_string(), "100");
assert_eq!(deserialized_serde.to_raw(), 100);
assert_eq!(deserialized_amount.to_string(), "100");
assert_eq!(deserialized_amount.to_raw(), 100);
assert_eq!(deserialized_serde, deserialized_amount);
} |
@modship sorry for the late reply the test seems very effective. |
impact in config files :
Also
massa-client :
Api :
|
Draft
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First
And then we should also :
Amount
wrapper which is oneOf [ string, number]The text was updated successfully, but these errors were encountered: