Skip to content

Commit

Permalink
tests and docs for Order serialization
Browse files Browse the repository at this point in the history
Fixes comment at #2174 (comment)
  • Loading branch information
dakom committed Jun 24, 2024
1 parent df4681e commit 997cce1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 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,8 @@ 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
30 changes: 30 additions & 0 deletions packages/std/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,33 @@ impl From<Order> for i32 {
original as _
}
}

#[cfg(test)]
mod tests {
use super::*;

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

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

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

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

0 comments on commit 997cce1

Please sign in to comment.