Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Jan 23, 2025
1 parent 7e86435 commit 16d7e27
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,50 +206,50 @@ fn ed25519_try_from_bytes() {
}

#[test]
fn ed25519_b512_from() {
fn ed25519_into_b512() {
let b512_1 = B512::from((b256::zero(), b256::zero()));
let ed25519_1 = Ed25519::from(b512_1);
assert(B512::from(ed25519_1) == b512_1);
assert(<Ed25519 as Into<B512>>::into(ed25519_1) == b512_1);

let b512_2 = B512::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let ed25519_2 = Ed25519::from(b512_2);
assert(B512::from(ed25519_2) == b512_2);
assert(<Ed25519 as Into<B512>>::into(ed25519_2) == b512_2);

let b512_3 = B512::from((b256::max(), b256::max()));
let ed25519_3 = Ed25519::from(b512_3);
assert(B512::from(ed25519_3) == b512_3);
assert(<Ed25519 as Into<B512>>::into(ed25519_3) == b512_3);
}

#[test]
fn ed25519_b256_tuple_from() {
fn ed25519_into_b256() {
let ed25519_1 = Ed25519::from((b256::zero(), b256::zero()));
let (result_1_1, result_2_1) = <(b256, b256) as From<Ed25519>>::from(ed25519_1);
let (result_1_1, result_2_1) = <Ed25519 as Into<(b256, b256)>>::into(ed25519_1);
assert(result_1_1 == b256::zero());
assert(result_2_1 == b256::zero());

let ed25519_2 = Ed25519::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let (result_1_2, result_2_2) = <(b256, b256) as From<Ed25519>>::from(ed25519_2);
let (result_1_2, result_2_2): (b256, b256) = <Ed25519 as Into<(b256, b256)>>::into(ed25519_2);
assert(result_1_2 == b256::zero());
assert(result_2_2 == 0x0000000000000000000000000000000000000000000000000000000000000001);

let ed25519_3 = Ed25519::from((b256::max(), b256::max()));
let (result_1_3, result_2_3) = <(b256, b256) as From<Ed25519>>::from(ed25519_3);
let (result_1_3, result_2_3): (b256, b256) = <Ed25519 as Into<(b256, b256)>>::into(ed25519_3);
assert(result_1_3 == b256::max());
assert(result_2_3 == b256::max());
}

#[test]
fn ed25519_bytes_from() {
fn ed25519_into_bytes() {
let ed25519_1 = Ed25519::from((b256::zero(), b256::zero()));
let bytes_result_1 = Bytes::from(ed25519_1);
let bytes_result_1: Bytes = <Ed25519 as Into<Bytes>>::into(ed25519_1);
let mut iter_1 = 0;
while iter_1 < 64 {
assert(bytes_result_1.get(iter_1).unwrap() == 0u8);
iter_1 += 1;
}

let ed25519_2 = Ed25519::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let bytes_result_2 = Bytes::from(ed25519_2);
let bytes_result_2: Bytes = <Ed25519 as Into<Bytes>>::into(ed25519_2);
assert(bytes_result_2.get(63).unwrap() == 1u8);
let mut iter_2 = 0;
while iter_2 < 63 {
Expand All @@ -258,7 +258,7 @@ fn ed25519_bytes_from() {
}

let ed25519_3 = Ed25519::from((b256::max(), b256::max()));
let bytes_result_3 = Bytes::from(ed25519_3);
let bytes_result_3: Bytes = <Ed25519 as Into<Bytes>>::into(ed25519_3);
let mut iter_3 = 0;
while iter_3 < 64 {
assert(bytes_result_3.get(iter_3).unwrap() == 255u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,28 @@ fn message_from_bytes() {
}

#[test]
fn message_b256_try_from() {
fn message_try_into_b256() {
let zero_b256 = b256::zero();
let max_b256 = b256::max();
let other_b256 = 0x0000000000000000000000000000000000000000000000000000000000000001;
let mut bytes = Bytes::from(b256::max());
bytes.push(0u8);

let zero_message = Message::from(zero_b256);
assert(b256::try_from(zero_message).unwrap() == zero_b256);
let b256_1 = <Message as TryInto<b256>>::try_into(zero_message);
assert(b256_1.unwrap() == zero_b256);

let max_message = Message::from(max_b256);
assert(b256::try_from(max_message).unwrap() == max_b256);
let b256_2 = <Message as TryInto<b256>>::try_into(max_message);
assert(b256_2.unwrap() == max_b256);

let other_message = Message::from(other_b256);
assert(b256::try_from(other_b256).unwrap() == other_b256);
let b256_3 = <Message as TryInto<b256>>::try_into(other_message);
assert(b256_3.unwrap() == other_b256);

let bytes_message = Message::from(bytes);
let b256_4 = <Message as TryInto<b256>>::try_into(bytes_message);
assert(b256_4.is_none());
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,62 +198,62 @@ fn public_key_try_from_bytes() {
}

#[test]
fn public_key_b256_tuple_try_from() {
fn public_key_try_into_b256_tuple() {
let public_key_1 = PublicKey::from((b256::zero(), b256::zero()));
let (result_1_1, result_2_1) = <(b256, b256) as TryFrom<PublicKey>>::try_from(public_key_1).unwrap();
let (result_1_1, result_2_1) = <PublicKey as TryInto<(b256, b256)>>::try_into(public_key_1).unwrap();
assert(result_1_1 == b256::zero());
assert(result_2_1 == b256::zero());

let public_key_2 = PublicKey::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let (result_1_2, result_2_2) = <(b256, b256) as TryFrom<PublicKey>>::try_from(public_key_2).unwrap();
let (result_1_2, result_2_2) = <PublicKey as TryInto<(b256, b256)>>::try_into(public_key_2).unwrap();
assert(result_1_2 == b256::zero());
assert(result_2_2 == 0x0000000000000000000000000000000000000000000000000000000000000001);

let public_key_3 = PublicKey::from((b256::max(), b256::max()));
let (result_1_3, result_2_3) = <(b256, b256) as TryFrom<PublicKey>>::try_from(public_key_3).unwrap();
let (result_1_3, result_2_3) = <PublicKey as TryInto<(b256, b256)>>::try_into(public_key_3).unwrap();
assert(result_1_3 == b256::max());
assert(result_2_3 == b256::max());

let public_key_4 = PublicKey::from(b256::zero());
let result_4 = <(b256, b256) as TryFrom<PublicKey>>::try_from(public_key_4);
let result_4 = <PublicKey as TryInto<(b256, b256)>>::try_into(public_key_4);
assert(result_4.is_none());
}

#[test]
fn public_key_b512_try_from() {
fn public_key_try_into_b512() {
let b512_1 = B512::from((b256::zero(), b256::zero()));
let public_key_1 = PublicKey::from(b512_1);
assert(B512::try_from(public_key_1).unwrap() == b512_1);
assert(<PublicKey as TryInto<B512>>::try_into(public_key_1).unwrap() == b512_1);

let b512_2 = B512::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let public_key_2 = PublicKey::from(b512_2);
assert(B512::try_from(public_key_2).unwrap() == b512_2);
assert(<PublicKey as TryInto<B512>>::try_into(public_key_2).unwrap() == b512_2);

let b512_3 = B512::from((b256::max(), b256::max()));
let public_key_3 = PublicKey::from(b512_3);
assert(B512::try_from(public_key_3).unwrap() == b512_3);
assert(<PublicKey as TryInto<B512>>::try_into(public_key_3).unwrap() == b512_3);

let public_key_4 = PublicKey::from(b256::zero());
let result = B512::try_from(public_key_4);
let result = <PublicKey as TryInto<B512>>::try_into(public_key_4);
assert(result.is_none());
}

#[test]
fn public_key_b256_try_from() {
fn public_key_try_into_b256() {
let public_key_1 = PublicKey::from(b256::zero());
let result_1 = b256::try_from(public_key_1).unwrap();
let result_1: b256 = <PublicKey as TryInto<b256>>::try_into(public_key_1).unwrap();
assert(result_1 == b256::zero());

let public_key_2 = PublicKey::from(0x0000000000000000000000000000000000000000000000000000000000000001);
let result_2 = b256::try_from(public_key_2).unwrap();
let result_2: b256 = <PublicKey as TryInto<b256>>::try_into(public_key_2).unwrap();
assert(result_2 == 0x0000000000000000000000000000000000000000000000000000000000000001);

let public_key_3 = PublicKey::from(b256::max());
let result_3 = b256::try_from(public_key_3).unwrap();
let result_3: b256 = <PublicKey as TryInto<b256>>::try_into(public_key_3).unwrap();
assert(result_3 == b256::max());

let public_key_4 = PublicKey::from((b256::zero(), b256::zero()));
let result_4 = b256::try_from(public_key_4);
let result_4 = <PublicKey as TryInto<b256>>::try_into(public_key_4);
assert(result_4.is_none());
}

Expand Down Expand Up @@ -309,6 +309,4 @@ fn public_key_hash() {
let one_public_key = PublicKey::from(0x0000000000000000000000000000000000000000000000000000000000000001);
let result_2 = sha256(one_public_key);
assert(result_2 == 0xec4916dd28fc4c10d78e287ca5d9cc51ee1ae73cbfde08c6b37324cbfaac8bc5);

// TODO: Test with length 64
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,50 +350,50 @@ fn secp256k1_try_from_bytes() {
}

#[test]
fn secp256k1_b512_from() {
fn secp256k1_into_b512() {
let b512_1 = B512::from((b256::zero(), b256::zero()));
let secp256k1_1 = Secp256k1::from(b512_1);
assert(B512::from(secp256k1_1) == b512_1);
assert(<Secp256k1 as Into<B512>>::into(secp256k1_1) == b512_1);

let b512_2 = B512::from((
b256::zero(),
0x0000000000000000000000000000000000000000000000000000000000000001,
));
let secp256k1_2 = Secp256k1::from(b512_2);
assert(B512::from(secp256k1_2) == b512_2);
assert(<Secp256k1 as Into<B512>>::into(secp256k1_2) == b512_2);

let b512_3 = B512::from((b256::max(), b256::max()));
let secp256k1_3 = Secp256k1::from(b512_3);
assert(B512::from(secp256k1_3) == b512_3);
assert(<Secp256k1 as Into<B512>>::into(secp256k1_3) == b512_3);
}

#[test]
fn secp256k1_b256_tuple_from() {
fn secp256k1_into_b256_tuple() {
let secp256k1_1 = Secp256k1::from((b256::zero(), b256::zero()));
let (result_1_1, result_2_1) = <(b256, b256) as From<Secp256k1>>::from(secp256k1_1);
let (result_1_1, result_2_1) = <Secp256k1 as Into<(b256, b256)>>::into(secp256k1_1);
assert(result_1_1 == b256::zero());
assert(result_2_1 == b256::zero());

let secp256k1_2 = Secp256k1::from((
b256::zero(),
0x0000000000000000000000000000000000000000000000000000000000000001,
));
let (result_1_2, result_2_2) = <(b256, b256) as From<Secp256k1>>::from(secp256k1_2);
let (result_1_2, result_2_2) = <Secp256k1 as Into<(b256, b256)>>::into(secp256k1_2);
assert(result_1_2 == b256::zero());
assert(
result_2_2 == 0x0000000000000000000000000000000000000000000000000000000000000001,
);

let secp256k1_3 = Secp256k1::from((b256::max(), b256::max()));
let (result_1_3, result_2_3) = <(b256, b256) as From<Secp256k1>>::from(secp256k1_3);
let (result_1_3, result_2_3) = <Secp256k1 as Into<(b256, b256)>>::into(secp256k1_3);
assert(result_1_3 == b256::max());
assert(result_2_3 == b256::max());
}

#[test]
fn secp256k1_bytes_from() {
fn secp256k1_into_bytes() {
let secp256k1_1 = Secp256k1::from((b256::zero(), b256::zero()));
let bytes_result_1 = Bytes::from(secp256k1_1);
let bytes_result_1 = <Secp256k1 as Into<Bytes>>::into(secp256k1_1);
let mut iter_1 = 0;
while iter_1 < 64 {
assert(bytes_result_1.get(iter_1).unwrap() == 0u8);
Expand All @@ -404,7 +404,7 @@ fn secp256k1_bytes_from() {
b256::zero(),
0x0000000000000000000000000000000000000000000000000000000000000001,
));
let bytes_result_2 = Bytes::from(secp256k1_2);
let bytes_result_2 = <Secp256k1 as Into<Bytes>>::into(secp256k1_2);
assert(bytes_result_2.get(63).unwrap() == 1u8);
let mut iter_2 = 0;
while iter_2 < 63 {
Expand All @@ -413,7 +413,7 @@ fn secp256k1_bytes_from() {
}

let secp256k1_3 = Secp256k1::from((b256::max(), b256::max()));
let bytes_result_3 = Bytes::from(secp256k1_3);
let bytes_result_3 = <Secp256k1 as Into<Bytes>>::into(secp256k1_3);
let mut iter_3 = 0;
while iter_3 < 64 {
assert(bytes_result_3.get(iter_3).unwrap() == 255u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,50 +327,50 @@ fn secp256r1_try_from_bytes() {
}

#[test]
fn secp256r1_b512_from() {
fn secp256r1_into_b512() {
let b512_1 = B512::from((b256::zero(), b256::zero()));
let secp256r1_1 = Secp256r1::from(b512_1);
assert(B512::from(secp256r1_1) == b512_1);
assert(<Secp256r1 as Into<B512>>::into(secp256r1_1) == b512_1);

let b512_2 = B512::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let secp256r1_2 = Secp256r1::from(b512_2);
assert(B512::from(secp256r1_2) == b512_2);
assert(<Secp256r1 as Into<B512>>::into(secp256r1_2) == b512_2);

let b512_3 = B512::from((b256::max(), b256::max()));
let secp256r1_3 = Secp256r1::from(b512_3);
assert(B512::from(secp256r1_3) == b512_3);
assert(<Secp256r1 as Into<B512>>::into(secp256r1_3) == b512_3);
}

#[test]
fn secp256r1_b256_tuple_from() {
fn secp256r1_into_b256_tuple() {
let secp256r1_1 = Secp256r1::from((b256::zero(), b256::zero()));
let (result_1_1, result_2_1) = <(b256, b256) as From<Secp256r1>>::from(secp256r1_1);
let (result_1_1, result_2_1) = <Secp256r1 as Into<(b256, b256)>>::into(secp256r1_1);
assert(result_1_1 == b256::zero());
assert(result_2_1 == b256::zero());

let secp256r1_2 = Secp256r1::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let (result_1_2, result_2_2) = <(b256, b256) as From<Secp256r1>>::from(secp256r1_2);
let (result_1_2, result_2_2) = <Secp256r1 as Into<(b256, b256)>>::into(secp256r1_2);
assert(result_1_2 == b256::zero());
assert(result_2_2 == 0x0000000000000000000000000000000000000000000000000000000000000001);

let secp256r1_3 = Secp256r1::from((b256::max(), b256::max()));
let (result_1_3, result_2_3) = <(b256, b256) as From<Secp256r1>>::from(secp256r1_3);
let (result_1_3, result_2_3) = <Secp256r1 as Into<(b256, b256)>>::into(secp256r1_3);
assert(result_1_3 == b256::max());
assert(result_2_3 == b256::max());
}

#[test]
fn secp256r1_bytes_from() {
fn secp256r1_into_bytes() {
let secp256r1_1 = Secp256r1::from((b256::zero(), b256::zero()));
let bytes_result_1 = Bytes::from(secp256r1_1);
let bytes_result_1 = <Secp256r1 as Into<Bytes>>::into(secp256r1_1);
let mut iter_1 = 0;
while iter_1 < 64 {
assert(bytes_result_1.get(iter_1).unwrap() == 0u8);
iter_1 += 1;
}

let secp256r1_2 = Secp256r1::from((b256::zero(), 0x0000000000000000000000000000000000000000000000000000000000000001));
let bytes_result_2 = Bytes::from(secp256r1_2);
let bytes_result_2 = <Secp256r1 as Into<Bytes>>::into(secp256r1_2);
assert(bytes_result_2.get(63).unwrap() == 1u8);
let mut iter_2 = 0;
while iter_2 < 63 {
Expand All @@ -379,7 +379,7 @@ fn secp256r1_bytes_from() {
}

let secp256r1_3 = Secp256r1::from((b256::max(), b256::max()));
let bytes_result_3 = Bytes::from(secp256r1_3);
let bytes_result_3 = <Secp256r1 as Into<Bytes>>::into(secp256r1_3);
let mut iter_3 = 0;
while iter_3 < 64 {
assert(bytes_result_3.get(iter_3).unwrap() == 255u8);
Expand Down

0 comments on commit 16d7e27

Please sign in to comment.