|
@@ -195,7 +195,7 @@ pub enum ErrorCode {
|
|
|
Deprecated = 5000,
|
|
|
}
|
|
|
|
|
|
-#[derive(Debug)]
|
|
|
+#[derive(Debug, PartialEq, Eq)]
|
|
|
pub enum Error {
|
|
|
AnchorError(AnchorError),
|
|
|
ProgramError(ProgramErrorWithOrigin),
|
|
@@ -302,6 +302,14 @@ pub struct ProgramErrorWithOrigin {
|
|
|
pub compared_values: Option<ComparedValues>,
|
|
|
}
|
|
|
|
|
|
+// Two ProgramErrors are equal when they have the same error code
|
|
|
+impl PartialEq for ProgramErrorWithOrigin {
|
|
|
+ fn eq(&self, other: &Self) -> bool {
|
|
|
+ self.program_error == other.program_error
|
|
|
+ }
|
|
|
+}
|
|
|
+impl Eq for ProgramErrorWithOrigin {}
|
|
|
+
|
|
|
impl Display for ProgramErrorWithOrigin {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
Display::fmt(&self.program_error, f)
|
|
@@ -458,6 +466,15 @@ impl Display for AnchorError {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// Two `AnchorError`s are equal when they have the same error code
|
|
|
+impl PartialEq for AnchorError {
|
|
|
+ fn eq(&self, other: &Self) -> bool {
|
|
|
+ self.error_code_number == other.error_code_number
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Eq for AnchorError {}
|
|
|
+
|
|
|
impl std::convert::From<Error> for anchor_lang::solana_program::program_error::ProgramError {
|
|
|
fn from(e: Error) -> anchor_lang::solana_program::program_error::ProgramError {
|
|
|
match e {
|