mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-02 00:07:23 +00:00
Fix serialization of transaction_paymentInfo (#4146)
* Add serialization test for u128 * Fix crash on serde of u128
This commit is contained in:
committed by
Gavin Wood
parent
07a05554c3
commit
613b5e7e2d
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user