@@ -195,7 +195,7 @@ pub enum ErrorCode {
195195 Deprecated = 5000 ,
196196}
197197
198- #[ derive( Debug ) ]
198+ #[ derive( Debug , PartialEq , Eq ) ]
199199pub enum Error {
200200 AnchorError ( AnchorError ) ,
201201 ProgramError ( ProgramErrorWithOrigin ) ,
@@ -302,6 +302,14 @@ pub struct ProgramErrorWithOrigin {
302302 pub compared_values : Option < ComparedValues > ,
303303}
304304
305+ // Two ProgramErrors are equal when they have the same error code
306+ impl PartialEq for ProgramErrorWithOrigin {
307+ fn eq ( & self , other : & Self ) -> bool {
308+ self . program_error == other. program_error
309+ }
310+ }
311+ impl Eq for ProgramErrorWithOrigin { }
312+
305313impl Display for ProgramErrorWithOrigin {
306314 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
307315 Display :: fmt ( & self . program_error , f)
@@ -458,6 +466,15 @@ impl Display for AnchorError {
458466 }
459467}
460468
469+ /// Two `AnchorError`s are equal when they have the same error code
470+ impl PartialEq for AnchorError {
471+ fn eq ( & self , other : & Self ) -> bool {
472+ self . error_code_number == other. error_code_number
473+ }
474+ }
475+
476+ impl Eq for AnchorError { }
477+
461478impl std:: convert:: From < Error > for anchor_lang:: solana_program:: program_error:: ProgramError {
462479 fn from ( e : Error ) -> anchor_lang:: solana_program:: program_error:: ProgramError {
463480 match e {
0 commit comments