Skip to content

Amount serde does not roundtrip Amount::MAX #3688

@tcharding

Description

@tcharding

Deserializing Amount::MAX currently fails with

---- amount::serde::tests::can_serde_as_btc stdout ----
thread 'amount::serde::tests::can_serde_as_btc' panicked at units/src/amount/serde.rs:423:61:
failed to deser: Error("amount out of range: the amount is greater than 18446744073709551615", line: 1, column: 29)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I would expect this test to pass:

    #[test]
    fn can_serde_as_btc() {
        #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
        pub struct HasAmount {
            #[serde(with = "crate::amount::serde::as_btc")]
            pub amount: Amount,
        }

        let orig = HasAmount {
            amount: Amount::MAX,
        };

        let json = serde_json::to_string(&orig).expect("failed to ser");
        let rinsed: HasAmount = serde_json::from_str(&json).expect("failed to deser");
        assert_eq!(rinsed, orig)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions