Skip to content

Commit 467f1c0

Browse files
committed
Merge rust-bitcoin#2837: pow: Fix off-by-one error
dd80a08 pow: Unit test from_hex_internal (Tobin C. Harding) c16f7ad pow: Fix off-by-one error (Tobin C. Harding) Pull request description: This is a backport of the 2 patches in rust-bitcoin#2834, grammar mistakes in the commit log and all. Note, one difference, we call `hex_u128` instead of `hex_u128_unchecked` because the unchecked version does not exist in `v0.32`. ACKs for top commit: apoelstra: ACK dd80a08 Kixunil: ACK dd80a08 Tree-SHA512: c93d47fb57105523284600e81f695091afb9d1c6b21dc4481b81c97e5fe97fc3842ae15c563f266166d18eff14bf256e550604ab2999f2b878393ae6a0ca8bdb
2 parents 4677f82 + dd80a08 commit 467f1c0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bitcoin/src/pow.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl U256 {
434434

435435
// Caller to ensure `s` does not contain a prefix.
436436
fn from_hex_internal(s: &str) -> Result<Self, ParseIntError> {
437-
let (high, low) = if s.len() < 32 {
437+
let (high, low) = if s.len() <= 32 {
438438
let low = parse::hex_u128(s)?;
439439
(0, low)
440440
} else {
@@ -1589,6 +1589,14 @@ mod tests {
15891589
assert_eq!(got, val);
15901590
}
15911591

1592+
#[test]
1593+
fn u256_from_hex_32_characters_long() {
1594+
let hex = "a69b455cd41bb662a69b4555deadbeef";
1595+
let want = U256(0x00, 0xA69B_455C_D41B_B662_A69B_4555_DEAD_BEEF);
1596+
let got = U256::from_unprefixed_hex(hex).expect("failed to parse hex");
1597+
assert_eq!(got, want);
1598+
}
1599+
15921600
#[cfg(feature = "serde")]
15931601
#[test]
15941602
fn u256_serde() {

0 commit comments

Comments
 (0)