Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: parity roundtripping #497

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/primitives/src/signature/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Parity {
pub const fn y_parity(&self) -> bool {
match self {
Self::Eip155(v @ 0..=34) => *v % 2 == 1,
Self::Eip155(v) => (*v ^ 1) % 2 == 0,
Self::Eip155(v) => (*v ^ 1) % 2 == 1,
Self::NonEip155(b) | Self::Parity(b) => *b,
}
}
Expand Down Expand Up @@ -170,10 +170,12 @@ impl alloy_rlp::Decodable for Parity {

#[cfg(test)]
mod test {
use crate::Parity;

#[cfg(feature = "rlp")]
#[test]
fn basic_rlp() {
use crate::{hex, Parity};
use crate::hex;

use alloy_rlp::{Decodable, Encodable};

Expand All @@ -193,4 +195,14 @@ mod test {
assert_eq!(test.1, Parity::decode(&mut buf.as_slice()).unwrap());
}
}

#[test]
fn round_trip() {
// with chain ID 1
let p = Parity::Eip155(37);

assert_eq!(p.to_parity_bool(), Parity::Parity(false));

assert_eq!(p.with_chain_id(1), Parity::Eip155(37));
}
}
Loading