Adjust test to cover WitnessVersion fmt traits
What changed, and why it matters
This commit only changes test code. It renames a test and adds extra checks to make sure a Bitcoin data type (WitnessVersion) prints correctly in different number formats (decimal, hexadecimal, octal, binary). There is no change to production code and no security issue.
No action required; this is a routine test-coverage change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies primitives/src/witness_version.rs under #[cfg(test)]. It renames witness_version_display to witness_version_fmt and expands assertions to cover Display, LowerHex, UpperHex, Octal, and Binary formatting traits for WitnessVersion. No runtime code is altered.
Changed components
primitives/src/witness_version.rs (test module only)Inspect captured patch +18 / −6
diff --git a/primitives/src/witness_version.rs b/primitives/src/witness_version.rs
index 6707eee4..17bcff2b 100644
--- a/primitives/src/witness_version.rs
+++ b/primitives/src/witness_version.rs
@@ -233,7 +233,7 @@ pub mod error {
#[cfg(test)]
mod tests {
#[cfg(feature = "alloc")]
- use alloc::string::ToString;
+ use alloc::format;
use super::*;
use crate::opcodes::OP_PUSHDATA4;
@@ -248,11 +248,23 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
- fn witness_version_display() {
- assert_eq!(WitnessVersion::V0.to_string(), "0");
- assert_eq!(WitnessVersion::V1.to_string(), "1");
- assert_eq!(WitnessVersion::V10.to_string(), "10");
- assert_eq!(WitnessVersion::V16.to_string(), "16");
+ fn witness_version_fmt() {
+ assert_eq!(format!("{}", WitnessVersion::V0), "0");
+ assert_eq!(format!("{}", WitnessVersion::V1), "1");
+ assert_eq!(format!("{}", WitnessVersion::V10), "10");
+ assert_eq!(format!("{}", WitnessVersion::V16), "16");
+
+ assert_eq!(format!("{:x}", WitnessVersion::V10), "a");
+ assert_eq!(format!("{:x}", WitnessVersion::V16), "10");
+
+ assert_eq!(format!("{:X}", WitnessVersion::V10), "A");
+ assert_eq!(format!("{:X}", WitnessVersion::V16), "10");
+
+ assert_eq!(format!("{:o}", WitnessVersion::V10), "12");
+ assert_eq!(format!("{:o}", WitnessVersion::V16), "20");
+
+ assert_eq!(format!("{:b}", WitnessVersion::V10), "1010");
+ assert_eq!(format!("{:b}", WitnessVersion::V16), "10000");
}
#[test]
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.