Skip to content

Commit 53d928e

Browse files
committed
removed the Error::Asblocktime variant and made use of the Error::miniscript variant
Updated the display_string.contains for test_abs_lock_time_error_mapping Removed unused AbslockTime enum Error
1 parent 937c9e4 commit 53d928e

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/descriptor/dsl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,10 @@ macro_rules! fragment {
722722
});
723723
( after ( $value:expr ) ) => ({
724724
$crate::miniscript::AbsLockTime::from_consensus($value)
725-
.map_err($crate::descriptor::DescriptorError::from)
725+
.map_err(|e| $crate::descriptor::DescriptorError::Miniscript($crate::miniscript::Error::AbsoluteLockTime(e)))
726726
.and_then(|abs_lock_time| $crate::impl_leaf_opcode_value!(After, abs_lock_time))
727727
});
728+
728729
( older ( $value:expr ) ) => ({
729730
$crate::impl_leaf_opcode_value!(Older, $crate::miniscript::RelLockTime::from_consensus($value).expect("valid `RelLockTime`")) // TODO!!
730731
});

src/descriptor/error.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ pub enum Error {
4444
Hex(bitcoin::hex::HexToBytesError),
4545
/// The provided wallet descriptors are identical
4646
ExternalAndInternalAreTheSame,
47-
/// Abslocktime validation error
48-
AbsLockTime(miniscript::AbsLockTimeError),
4947
}
5048

5149
impl From<crate::keys::KeyError> for Error {
@@ -86,7 +84,6 @@ impl fmt::Display for Error {
8684
Self::ExternalAndInternalAreTheSame => {
8785
write!(f, "External and internal descriptors are the same")
8886
}
89-
Self::AbsLockTime(err) => write!(f, "AbsLockTime error: {err}"),
9087
}
9188
}
9289
}
@@ -128,9 +125,3 @@ impl From<crate::descriptor::policy::PolicyError> for Error {
128125
Error::Policy(err)
129126
}
130127
}
131-
132-
impl From<miniscript::AbsLockTimeError> for Error {
133-
fn from(err: miniscript::AbsLockTimeError) -> Self {
134-
Error::AbsLockTime(err)
135-
}
136-
}

tests/descriptor_macro.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ fn test_after_with_invalid_abslocktime_zero() {
1313
);
1414

1515
// Check for the correct error variant
16-
if let Err(descriptor::DescriptorError::AbsLockTime(_)) = result {
16+
if let Err(descriptor::DescriptorError::Miniscript(miniscript::Error::AbsoluteLockTime(_))) =
17+
result
18+
{
1719
// Success: Error was caught and mapped correctly
1820
} else {
1921
panic!("Expected AbsLockTime error, got {:?}", result);
@@ -55,8 +57,13 @@ fn test_after_with_invalid_just_above_max() {
5557
let result = descriptor!(wsh(after(too_large)));
5658

5759
assert!(
58-
result.is_err(),
59-
"Value 2,147,483,649 should return a DescriptorError::AbsLockTime"
60+
matches!(
61+
result,
62+
Err(descriptor::DescriptorError::Miniscript(
63+
miniscript::Error::AbsoluteLockTime(_)
64+
))
65+
),
66+
"Should fail specifically with a Miniscript AbsoluteLockTime error"
6067
);
6168
}
6269

@@ -74,21 +81,26 @@ fn test_after_with_u32_max_is_invalid() {
7481

7582
#[test]
7683
fn test_abs_lock_time_error_mapping() {
77-
// Manually trigger the error to verify the From conversion into DescriptorError
7884
let invalid_value = 0;
7985
let abs_lock_result = AbsLockTime::from_consensus(invalid_value);
8086

8187
assert!(abs_lock_result.is_err());
8288
let abs_err = abs_lock_result.unwrap_err();
8389

84-
// Verify the conversion into your custom DescriptorError
85-
let error: descriptor::DescriptorError = abs_err.into();
86-
assert!(matches!(error, descriptor::DescriptorError::AbsLockTime(_)));
90+
// Wrap in the general Miniscript Error enum
91+
let minisc_err = miniscript::Error::AbsoluteLockTime(abs_err);
92+
93+
// Convert to your local Error type using .into()
94+
let error: descriptor::DescriptorError = minisc_err.into();
95+
96+
// Assert it landed in the Miniscript variant
97+
assert!(matches!(error, descriptor::DescriptorError::Miniscript(_)));
8798

88-
// Check that the error message is descriptive
99+
// Verify the error message contains the expected text
89100
let display_string = format!("{}", error);
90101
assert!(
91-
display_string.contains("AbsLockTime"),
92-
"Error message should mention AbsLockTime"
102+
display_string.contains("absolute locktime"),
103+
"Error message '{}' should mention locktime",
104+
display_string
93105
);
94106
}

0 commit comments

Comments
 (0)