Open modship opened 5 months ago
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 :
minimal_fees
should be update from 0.01
to 10000000
balance
should be update from ex "1000"
string massa to 1000000000000
nanoMassa (has u64)Also interface_impl.rs
:
native_amount_from_str_wasmv1
native_amount_to_string_wasmv1
massa-client :
fee
is now nanoMassa instead of Massa coins
&& fee
in nanoMassa instead of Massa Api :
First
And then we should also :
Amount
wrapper which is oneOf [ string, number]