Skip to content

Commit 997cce1

Browse files
committed
tests and docs for Order serialization
Fixes comment at #2174 (comment)
1 parent df4681e commit 997cce1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/MESSAGE_TYPES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Rust types as well as `cosmwasm_std` types and how they are encoded in JSON.
3131
| [Binary] | string containing base64 data | `"MTIzCg=="` | |
3232
| [HexBinary] | string containing hex data | `"b5d7d24e428c"` | |
3333
| [Timestamp] | string containing nanoseconds since epoch | `"1677687687000000000"` | |
34+
| [Order] | string containing order variant | `"ascending"` or `"descending"` | |
3435

3536
[uint64]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Uint64.html
3637
[uint128]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Uint128.html
@@ -48,6 +49,8 @@ Rust types as well as `cosmwasm_std` types and how they are encoded in JSON.
4849
https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.HexBinary.html
4950
[timestamp]:
5051
https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/struct.Timestamp.html
52+
[order]:
53+
https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/enum.Order.html
5154
[dev-note-4]:
5255
https://medium.com/cosmwasm/dev-note-4-u128-i128-serialization-in-cosmwasm-90cb76784d44
5356

packages/std/src/iterator.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,33 @@ impl From<Order> for i32 {
3333
original as _
3434
}
3535
}
36+
37+
#[cfg(test)]
38+
mod tests {
39+
use super::*;
40+
41+
#[test]
42+
fn order_serde() {
43+
let ascending_bytes = br#""ascending""#;
44+
let descending_bytes = br#""descending""#;
45+
46+
assert_eq!(
47+
serde_json::to_vec(&Order::Ascending).unwrap(),
48+
ascending_bytes
49+
);
50+
assert_eq!(
51+
serde_json::to_vec(&Order::Descending).unwrap(),
52+
descending_bytes
53+
);
54+
55+
assert_eq!(
56+
serde_json::from_slice::<Order>(ascending_bytes).unwrap(),
57+
Order::Ascending
58+
);
59+
60+
assert_eq!(
61+
serde_json::from_slice::<Order>(descending_bytes).unwrap(),
62+
Order::Descending
63+
);
64+
}
65+
}

0 commit comments

Comments
 (0)