Skip to content

Commit db72e77

Browse files
authored
test: parity roundtripping (#497)
1 parent a315b0d commit db72e77

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

crates/primitives/src/signature/parity.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Parity {
7373
pub const fn y_parity(&self) -> bool {
7474
match self {
7575
Self::Eip155(v @ 0..=34) => *v % 2 == 1,
76-
Self::Eip155(v) => (*v ^ 1) % 2 == 0,
76+
Self::Eip155(v) => (*v ^ 1) % 2 == 1,
7777
Self::NonEip155(b) | Self::Parity(b) => *b,
7878
}
7979
}
@@ -170,10 +170,12 @@ impl alloy_rlp::Decodable for Parity {
170170

171171
#[cfg(test)]
172172
mod test {
173+
use crate::Parity;
174+
173175
#[cfg(feature = "rlp")]
174176
#[test]
175177
fn basic_rlp() {
176-
use crate::{hex, Parity};
178+
use crate::hex;
177179

178180
use alloy_rlp::{Decodable, Encodable};
179181

@@ -193,4 +195,14 @@ mod test {
193195
assert_eq!(test.1, Parity::decode(&mut buf.as_slice()).unwrap());
194196
}
195197
}
198+
199+
#[test]
200+
fn round_trip() {
201+
// with chain ID 1
202+
let p = Parity::Eip155(37);
203+
204+
assert_eq!(p.to_parity_bool(), Parity::Parity(false));
205+
206+
assert_eq!(p.with_chain_id(1), Parity::Eip155(37));
207+
}
196208
}

0 commit comments

Comments
 (0)