mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Implement PartialEq for DispatchError. (#8407)
This commit is contained in:
@@ -450,7 +450,7 @@ pub type DispatchResult = sp_std::result::Result<(), DispatchError>;
|
||||
pub type DispatchResultWithInfo<T> = sp_std::result::Result<T, DispatchErrorWithPostInfo<T>>;
|
||||
|
||||
/// Reason why a dispatch call failed.
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, RuntimeDebug)]
|
||||
#[derive(Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum DispatchError {
|
||||
/// Some error occurred.
|
||||
@@ -589,6 +589,27 @@ impl<T> traits::Printable for DispatchErrorWithPostInfo<T> where
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for DispatchError {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
use DispatchError::*;
|
||||
|
||||
match (self, other) {
|
||||
(CannotLookup, CannotLookup) |
|
||||
(BadOrigin, BadOrigin) |
|
||||
(ConsumerRemaining, ConsumerRemaining) |
|
||||
(NoProviders, NoProviders) => true,
|
||||
|
||||
(Other(l), Other(r)) => l == r,
|
||||
(
|
||||
Module { index: index_l, error: error_l, .. },
|
||||
Module { index: index_r, error: error_r, .. },
|
||||
) => (index_l == index_r) && (error_l == error_r),
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This type specifies the outcome of dispatching a call to a module.
|
||||
///
|
||||
/// In case of failure an error specific to the module is returned.
|
||||
@@ -826,6 +847,38 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_error_equality() {
|
||||
use DispatchError::*;
|
||||
|
||||
let variants = vec![
|
||||
Other("foo"),
|
||||
Other("bar"),
|
||||
CannotLookup,
|
||||
BadOrigin,
|
||||
Module { index: 1, error: 1, message: None },
|
||||
Module { index: 1, error: 2, message: None },
|
||||
Module { index: 2, error: 1, message: None },
|
||||
ConsumerRemaining,
|
||||
NoProviders,
|
||||
];
|
||||
for (i, variant) in variants.iter().enumerate() {
|
||||
for (j, other_variant) in variants.iter().enumerate() {
|
||||
if i == j {
|
||||
assert_eq!(variant, other_variant);
|
||||
} else {
|
||||
assert_ne!(variant, other_variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ignores `message` field in `Module` variant.
|
||||
assert_eq!(
|
||||
Module { index: 1, error: 1, message: Some("foo") },
|
||||
Module { index: 1, error: 1, message: None},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_signature_ecdsa_verify_works() {
|
||||
let msg = &b"test-message"[..];
|
||||
|
||||
Reference in New Issue
Block a user