What changed, and why it matters
This commit simply moves existing proof-of-work serialization tests from one crate to another within the same project. It is a test-only refactoring change with no effect on production code or security.
No security action required; this is a benign test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates serde regression tests for Work and Target types, along with the u256_bincode test fixture, from the bitcoin crate integration tests to the units crate integration tests. The test logic and expected serialized bytes remain identical; only the file paths and imports are adjusted. No functional code was modified.
Changed components
bitcoin/tests/serde.rsunits/tests/serde.rsunits/tests/data/u256_bincodeInspect captured patch +34 / −34
diff --git a/bitcoin/tests/data/serde/u256_bincode b/bitcoin/tests/data/serde/u256_bincode
deleted file mode 100644
index e91e8a92..00000000
Binary files a/bitcoin/tests/data/serde/u256_bincode and /dev/null differ
diff --git a/bitcoin/tests/serde.rs b/bitcoin/tests/serde.rs
index 59b9be40..f1c81aae 100644
--- a/bitcoin/tests/serde.rs
+++ b/bitcoin/tests/serde.rs
@@ -31,8 +31,8 @@ use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapTree, TaprootBuilder}
use bitcoin::witness::Witness;
use bitcoin::{
ecdsa, hex, transaction, Address, Amount, LegacyPublicKey, NetworkKind, OutPoint,
- ScriptPubKeyBuf, ScriptSigBuf, Sequence, TapScriptBuf, Target, Transaction, TxIn, TxOut, Txid,
- WifKey, Work,
+ ScriptPubKeyBuf, ScriptSigBuf, Sequence, TapScriptBuf, Transaction, TxIn, TxOut, Txid,
+ WifKey,
};
#[test]
@@ -331,34 +331,3 @@ fn serde_regression_taptree() {
let want = include_bytes!("data/serde/taptree_bincode") as &[_];
assert_eq!(got, want)
}
-
-// Used to get a 256 bit integer as a byte array.
-fn le_bytes() -> [u8; 32] {
- let x: u128 = 0xDEAD_BEEF_CAFE_BABE_DEAD_BEEF_CAFE_BABE;
- let y: u128 = 0xCAFE_DEAD_BABE_BEEF_CAFE_DEAD_BABE_BEEF;
-
- let mut bytes = [0_u8; 32];
-
- bytes[..16].copy_from_slice(&x.to_le_bytes());
- bytes[16..].copy_from_slice(&y.to_le_bytes());
-
- bytes
-}
-
-#[test]
-fn serde_regression_work() {
- let work = Work::from_le_bytes(le_bytes());
-
- let got = serialize(&work).unwrap();
- let want = include_bytes!("data/serde/u256_bincode") as &[_];
- assert_eq!(got, want)
-}
-
-#[test]
-fn serde_regression_target() {
- let target = Target::from_le_bytes(le_bytes());
-
- let got = serialize(&target).unwrap();
- let want = include_bytes!("data/serde/u256_bincode") as &[_];
- assert_eq!(got, want)
-}
diff --git a/units/tests/data/u256_bincode b/units/tests/data/u256_bincode
new file mode 100644
index 00000000..e91e8a92
Binary files /dev/null and b/units/tests/data/u256_bincode differ
diff --git a/units/tests/serde.rs b/units/tests/serde.rs
index 7ebb493b..2d184e2f 100644
--- a/units/tests/serde.rs
+++ b/units/tests/serde.rs
@@ -10,7 +10,7 @@ use bitcoin_units::absolute::{Height, LockTime as AbsoluteLockTime, MedianTimePa
use bitcoin_units::relative::{LockTime as RelativeLockTime, NumberOf512Seconds, NumberOfBlocks};
use bitcoin_units::{
amount, fee_rate, Amount, BlockHeight, BlockHeightInterval, BlockTime, FeeRate, Sequence,
- SignedAmount, Weight,
+ SignedAmount, Target, Weight, Work,
};
use serde::{Deserialize, Serialize};
@@ -827,3 +827,34 @@ fn serde_as_locktime_from_time() {
let value: serde_json::Value = serde_json::from_str(json).unwrap();
assert_eq!(t, serde_json::from_value(value).unwrap());
}
+
+// Used to get a 256 bit integer as a byte array.
+fn le_bytes() -> [u8; 32] {
+ let x: u128 = 0xDEAD_BEEF_CAFE_BABE_DEAD_BEEF_CAFE_BABE;
+ let y: u128 = 0xCAFE_DEAD_BABE_BEEF_CAFE_DEAD_BABE_BEEF;
+
+ let mut bytes = [0_u8; 32];
+
+ bytes[..16].copy_from_slice(&x.to_le_bytes());
+ bytes[16..].copy_from_slice(&y.to_le_bytes());
+
+ bytes
+}
+
+#[test]
+fn serde_regression_work() {
+ let work = Work::from_le_bytes(le_bytes());
+
+ let got = serialize(&work).unwrap();
+ let want = include_bytes!("data/u256_bincode") as &[_];
+ assert_eq!(got, want);
+}
+
+#[test]
+fn serde_regression_target() {
+ let target = Target::from_le_bytes(le_bytes());
+
+ let got = serialize(&target).unwrap();
+ let want = include_bytes!("data/u256_bincode") as &[_];
+ assert_eq!(got, want);
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.