Skip to content

Commit

Permalink
more tests for CwKeySet
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Jan 29, 2025
1 parent 65c1d06 commit 4811136
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
lcov.info
/target
/Cargo.lock
dodo.py
.doit.db*
__pycache__
51 changes: 51 additions & 0 deletions packages/cw-storey/src/containers/key_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,57 @@ impl<const N: usize> OwnedKey<CwKeySet> for [u8; N] {
mod tests {
use super::*;

#[test]
fn unsigned_ints_1() {
let test_vector = [
(Uint64::from(0u64), [0, 0, 0, 0, 0, 0, 0, 0]),
(Uint64::from(1u64), [0, 0, 0, 0, 0, 0, 0, 1]),
(
Uint64::from(0x1234567890abcdefu64),
[0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef],
),
];

for (num, expected) in test_vector.iter() {
let encoded = num.encode();
assert_eq!(encoded, *expected);
}

for (expected, bytes) in test_vector.iter() {
let decoded = Uint64::from_bytes(bytes).unwrap();
assert_eq!(decoded, *expected);
}
}

#[test]
fn unsigned_ints_2() {
let test_vector = [
(Uint256::from(0u64), [0; 32]),
(
Uint256::new([
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90,
0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34,
0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
]),
[
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90,
0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34,
0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
],
),
];

for (num, expected) in test_vector.iter() {
let encoded = num.encode();
assert_eq!(encoded, *expected);
}

for (expected, bytes) in test_vector.iter() {
let decoded = Uint256::from_bytes(bytes).unwrap();
assert_eq!(decoded, *expected);
}
}

#[test]
fn signed_ints() {
let nums = [
Expand Down

0 comments on commit 4811136

Please sign in to comment.