Merge rust-bitcoin/rust-bitcoin#2834: pow: Fix off-by-one error
3298c0c4b5
pow: Unit test from_hex_internal (Tobin C. Harding)47e4bff0ee
pow: Fix off-by-one error (Tobin C. Harding) Pull request description: Patch 1 adds the fix, patch 2 is a unit test that fails if move to the front. ACKs for top commit: apoelstra: ACK3298c0c4b5
nice find! and lucky this just returns an error rather than panicking. may be worth backporting nonetheless brunoerg: ACK3298c0c4b5
Tree-SHA512: 15bbd5aa4ac62c91492f5394444d179d95770bae822422bf00bb62896dcaf6c92d32f7d2e3380c352ff7242422ec6af6ff637ff78d14406cd047ef4ad5f22649
This commit is contained in:
commit
2cfe0e204d
|
@ -497,7 +497,7 @@ impl U256 {
|
|||
|
||||
// Caller to ensure `s` does not contain a prefix.
|
||||
fn from_hex_internal(s: &str) -> Result<Self, ParseIntError> {
|
||||
let (high, low) = if s.len() < 32 {
|
||||
let (high, low) = if s.len() <= 32 {
|
||||
let low = parse::hex_u128_unchecked(s)?;
|
||||
(0, low)
|
||||
} else {
|
||||
|
@ -1652,6 +1652,14 @@ mod tests {
|
|||
assert_eq!(got, val);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn u256_from_hex_32_characters_long() {
|
||||
let hex = "a69b455cd41bb662a69b4555deadbeef";
|
||||
let want = U256(0x00, 0xA69B_455C_D41B_B662_A69B_4555_DEAD_BEEF);
|
||||
let got = U256::from_unprefixed_hex(hex).expect("failed to parse hex");
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn u256_serde() {
|
||||
|
|
Loading…
Reference in New Issue