Skip to content

Commit

Permalink
feat: cmp traits for json_types::integers (#822) (#823)
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Abell <austinabell8@gmail.com>
  • Loading branch information
curryrasul and austinabell authored May 24, 2022
1 parent d711a0f commit 2751292
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Added
- Added `Eq`, `PartialOrd`, `Ord` to `json_types` integer types. [PR 823](https://github.com/near/near-sdk-rs/pull/823)

### Changed
- Updated `nearcore` crates used for unit testing to version `0.13.0`. [PR 820](https://github.com/near/near-sdk-rs/pull/820)
- Removed `outcome` function from `MockedBlockchain` (incomplete and misleading data)
Expand Down
8 changes: 7 additions & 1 deletion near-sdk/src/json_types/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};

macro_rules! impl_str_type {
($iden: ident, $ty: tt) => {
#[derive(Debug, Clone, Copy, PartialEq, BorshDeserialize, BorshSerialize)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, BorshDeserialize, BorshSerialize,
)]
pub struct $iden(pub $ty);

impl From<$ty> for $iden {
Expand Down Expand Up @@ -80,6 +82,7 @@ mod tests {
test_serde!(U128, u128, 10u128.pow(18));
test_serde!(U128, u128, 2u128.pow(100));
test_serde!(U128, u128, u128::max_value());
assert!(U128::from(u128::min_value()) < U128::from(u128::max_value()));
}

#[test]
Expand All @@ -93,6 +96,7 @@ mod tests {
test_serde!(I128, i128, -(2i128.pow(100)));
test_serde!(I128, i128, i128::max_value());
test_serde!(I128, i128, i128::min_value());
assert!(I128::from(i128::min_value()) < I128::from(i128::max_value()));
}

#[test]
Expand All @@ -103,6 +107,7 @@ mod tests {
test_serde!(U64, u64, 10u64.pow(18));
test_serde!(U64, u64, 2u64.pow(60));
test_serde!(U64, u64, u64::max_value());
assert!(U64::from(u64::min_value()) < U64::from(u64::max_value()));
}

#[test]
Expand All @@ -116,5 +121,6 @@ mod tests {
test_serde!(I64, i64, -(2i64.pow(60)));
test_serde!(I64, i64, i64::max_value());
test_serde!(I64, i64, i64::min_value());
assert!(I64::from(i64::min_value()) < I64::from(i64::max_value()));
}
}

0 comments on commit 2751292

Please sign in to comment.