Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from anton-rs/brianbland/op-fix-sig-tests
Browse files Browse the repository at this point in the history
op-reth: Fix reth-primitives signature tests
  • Loading branch information
refcell authored Aug 2, 2023
2 parents cf47477 + 12d4093 commit 1a996e7
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,50 @@ mod tests {

#[test]
fn test_payload_len_with_eip155_chain_id() {
let signature = Signature { r: U256::default(), s: U256::default(), odd_y_parity: false };
// Select 1 as an arbitrary nonzero value for R and S, as v() always returns 0 for (0, 0).
let signature = Signature { r: U256::from(1), s: U256::from(1), odd_y_parity: false };

assert_eq!(3, signature.payload_len_with_eip155_chain_id(None));
assert_eq!(3, signature.payload_len_with_eip155_chain_id(Some(1)));
assert_eq!(4, signature.payload_len_with_eip155_chain_id(Some(47)));
}

#[cfg(feature = "optimism")]
#[test]
fn test_zero_signature_payload_len_with_eip155_chain_id() {
let zero_signature = Signature { r: U256::ZERO, s: U256::ZERO, odd_y_parity: false };

assert_eq!(3, zero_signature.payload_len_with_eip155_chain_id(None));
assert_eq!(3, zero_signature.payload_len_with_eip155_chain_id(Some(1)));
assert_eq!(3, zero_signature.payload_len_with_eip155_chain_id(Some(47)));
}

#[test]
fn test_v() {
let signature = Signature { r: U256::default(), s: U256::default(), odd_y_parity: false };
// Select 1 as an arbitrary nonzero value for R and S, as v() always returns 0 for (0, 0).
let signature = Signature { r: U256::from(1), s: U256::from(1), odd_y_parity: false };
assert_eq!(27, signature.v(None));
assert_eq!(37, signature.v(Some(1)));

let signature = Signature { r: U256::default(), s: U256::default(), odd_y_parity: true };
let signature = Signature { r: U256::from(1), s: U256::from(1), odd_y_parity: true };
assert_eq!(28, signature.v(None));
assert_eq!(38, signature.v(Some(1)));
}

#[cfg(feature = "optimism")]
#[test]
fn test_zero_signature_v() {
let signature = Signature { r: U256::ZERO, s: U256::ZERO, odd_y_parity: false };

assert_eq!(0, signature.v(None));
assert_eq!(0, signature.v(Some(1)));
assert_eq!(0, signature.v(Some(47)));
}

#[test]
fn test_encode_and_decode_with_eip155_chain_id() {
let signature = Signature { r: U256::default(), s: U256::default(), odd_y_parity: false };
// Select 1 as an arbitrary nonzero value for R and S, as v() always returns 0 for (0, 0).
let signature = Signature { r: U256::from(1), s: U256::from(1), odd_y_parity: false };

let mut encoded = BytesMut::new();
signature.encode_with_eip155_chain_id(&mut encoded, None);
Expand Down

0 comments on commit 1a996e7

Please sign in to comment.