Skip to content

Commit

Permalink
Merge pull request #2177 from dakom/order-followup
Browse files Browse the repository at this point in the history
tests and docs for Order serialization
  • Loading branch information
webmaster128 authored Jun 24, 2024
2 parents df4681e + e78dd73 commit 425679d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/MESSAGE_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Rust types as well as `cosmwasm_std` types and how they are encoded in JSON.
| [Binary] | string containing base64 data | `"MTIzCg=="` | |
| [HexBinary] | string containing hex data | `"b5d7d24e428c"` | |
| [Timestamp] | string containing nanoseconds since epoch | `"1677687687000000000"` | |
| [Order] | string containing order variant | `"ascending"` or `"descending"` | |

[uint64]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Uint64.html
[uint128]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Uint128.html
Expand All @@ -48,6 +49,7 @@ Rust types as well as `cosmwasm_std` types and how they are encoded in JSON.
https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.HexBinary.html
[timestamp]:
https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Timestamp.html
[order]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/enum.Order.html
[dev-note-4]:
https://medium.com/cosmwasm/dev-note-4-u128-i128-serialization-in-cosmwasm-90cb76784d44

Expand Down
26 changes: 26 additions & 0 deletions packages/std/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,29 @@ impl From<Order> for i32 {
original as _
}
}

#[cfg(test)]
mod tests {
use crate::{from_json, to_json_vec};

use super::*;

#[test]
fn order_serde() {
let ascending_bytes = br#""ascending""#;
let descending_bytes = br#""descending""#;

assert_eq!(to_json_vec(&Order::Ascending).unwrap(), ascending_bytes);
assert_eq!(to_json_vec(&Order::Descending).unwrap(), descending_bytes);

assert_eq!(
from_json::<Order>(ascending_bytes).unwrap(),
Order::Ascending
);

assert_eq!(
from_json::<Order>(descending_bytes).unwrap(),
Order::Descending
);
}
}

0 comments on commit 425679d

Please sign in to comment.