Skip to content

Commit 425679d

Browse files
authored
Merge pull request #2177 from dakom/order-followup
tests and docs for Order serialization
2 parents df4681e + e78dd73 commit 425679d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/MESSAGE_TYPES.md

Lines changed: 2 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,7 @@ 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]: https://docs.rs/cosmwasm-std/1.3.3/cosmwasm_std/enum.Order.html
5153
[dev-note-4]:
5254
https://medium.com/cosmwasm/dev-note-4-u128-i128-serialization-in-cosmwasm-90cb76784d44
5355

packages/std/src/iterator.rs

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

0 commit comments

Comments
 (0)