Fix serialization of transaction_paymentInfo (#4146)

* Add serialization test for u128

* Fix crash on serde of u128
This commit is contained in:
Tomasz Drwięga
2019-11-19 18:42:35 +01:00
committed by Gavin Wood
parent 07a05554c3
commit 613b5e7e2d
5 changed files with 29 additions and 1 deletions
@@ -11,6 +11,9 @@ codec = { package = "parity-scale-codec", version = "1.0.6", default-features =
rstd = { package = "sr-std", path = "../../../../primitives/sr-std", default-features = false }
sr-primitives = { path = "../../../../primitives/sr-primitives", default-features = false }
[dev-dependencies]
serde_json = { version = "1.0.41", features = ["arbitrary_precision"] }
[features]
default = ["std"]
std = [
@@ -27,6 +27,7 @@ use serde::{Serialize, Deserialize};
/// Some information related to a dispatchable that can be queried from the runtime.
#[derive(Eq, PartialEq, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct RuntimeDispatchInfo<Balance> {
/// Weight of this dispatch.
pub weight: Weight,
@@ -45,3 +46,25 @@ sr_api::decl_runtime_apis! {
fn query_info(uxt: Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance>;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_serialize_properly_with_u128() {
let info = RuntimeDispatchInfo {
weight: 5,
class: DispatchClass::Normal,
partial_fee: 1_000_000_u128,
};
assert_eq!(
serde_json::to_string(&info).unwrap(),
r#"{"weight":5,"class":"normal","partialFee":1000000}"#,
);
// should not panic
serde_json::to_value(&info).unwrap();
}
}