瀏覽代碼

fix: implement proper Debug and Display traits for PythReceiverError to show meaningful error messages in tests

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
Devin AI 4 月之前
父節點
當前提交
8367d4a34b
共有 1 個文件被更改,包括 60 次插入2 次删除
  1. 60 2
      target_chains/stylus/contracts/pyth-receiver/src/error.rs

+ 60 - 2
target_chains/stylus/contracts/pyth-receiver/src/error.rs

@@ -30,8 +30,66 @@ pub enum PythReceiverError {
 }
 
 impl core::fmt::Debug for PythReceiverError {
-    fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
-        Ok(())
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        match self {
+            PythReceiverError::PriceUnavailable => write!(f, "PriceUnavailable"),
+            PythReceiverError::InvalidUpdateData => write!(f, "InvalidUpdateData"),
+            PythReceiverError::VaaVerificationFailed => write!(f, "VaaVerificationFailed"),
+            PythReceiverError::InvalidVaa => write!(f, "InvalidVaa"),
+            PythReceiverError::InvalidWormholeMessage => write!(f, "InvalidWormholeMessage"),
+            PythReceiverError::InvalidMerkleProof => write!(f, "InvalidMerkleProof"),
+            PythReceiverError::InvalidAccumulatorMessage => write!(f, "InvalidAccumulatorMessage"),
+            PythReceiverError::InvalidMerkleRoot => write!(f, "InvalidMerkleRoot"),
+            PythReceiverError::InvalidMerklePath => write!(f, "InvalidMerklePath"),
+            PythReceiverError::InvalidUnknownSource => write!(f, "InvalidUnknownSource"),
+            PythReceiverError::NewPriceUnavailable => write!(f, "NewPriceUnavailable"),
+            PythReceiverError::InvalidAccumulatorMessageType => write!(f, "InvalidAccumulatorMessageType"),
+            PythReceiverError::InsufficientFee => write!(f, "InsufficientFee"),
+            PythReceiverError::InvalidEmitterAddress => write!(f, "InvalidEmitterAddress"),
+            PythReceiverError::TooManyUpdates => write!(f, "TooManyUpdates"),
+            PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "PriceFeedNotFoundWithinRange"),
+            PythReceiverError::NoFreshUpdate => write!(f, "NoFreshUpdate"),
+            PythReceiverError::PriceFeedNotFound => write!(f, "PriceFeedNotFound"),
+            PythReceiverError::InvalidGovernanceMessage => write!(f, "InvalidGovernanceMessage"),
+            PythReceiverError::InvalidGovernanceTarget => write!(f, "InvalidGovernanceTarget"),
+            PythReceiverError::InvalidGovernanceAction => write!(f, "InvalidGovernanceAction"),
+            PythReceiverError::InvalidGovernanceDataSource => write!(f, "InvalidGovernanceDataSource"),
+            PythReceiverError::OldGovernanceMessage => write!(f, "OldGovernanceMessage"),
+            PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "GovernanceMessageAlreadyExecuted"),
+            PythReceiverError::InvalidWormholeAddressToSet => write!(f, "InvalidWormholeAddressToSet"),
+        }
+    }
+}
+
+impl core::fmt::Display for PythReceiverError {
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        match self {
+            PythReceiverError::PriceUnavailable => write!(f, "Price unavailable"),
+            PythReceiverError::InvalidUpdateData => write!(f, "Invalid update data"),
+            PythReceiverError::VaaVerificationFailed => write!(f, "VAA verification failed"),
+            PythReceiverError::InvalidVaa => write!(f, "Invalid VAA"),
+            PythReceiverError::InvalidWormholeMessage => write!(f, "Invalid Wormhole message"),
+            PythReceiverError::InvalidMerkleProof => write!(f, "Invalid Merkle proof"),
+            PythReceiverError::InvalidAccumulatorMessage => write!(f, "Invalid accumulator message"),
+            PythReceiverError::InvalidMerkleRoot => write!(f, "Invalid Merkle root"),
+            PythReceiverError::InvalidMerklePath => write!(f, "Invalid Merkle path"),
+            PythReceiverError::InvalidUnknownSource => write!(f, "Invalid unknown source"),
+            PythReceiverError::NewPriceUnavailable => write!(f, "New price unavailable"),
+            PythReceiverError::InvalidAccumulatorMessageType => write!(f, "Invalid accumulator message type"),
+            PythReceiverError::InsufficientFee => write!(f, "Insufficient fee"),
+            PythReceiverError::InvalidEmitterAddress => write!(f, "Invalid emitter address"),
+            PythReceiverError::TooManyUpdates => write!(f, "Too many updates"),
+            PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "Price feed not found within range"),
+            PythReceiverError::NoFreshUpdate => write!(f, "No fresh update"),
+            PythReceiverError::PriceFeedNotFound => write!(f, "Price feed not found"),
+            PythReceiverError::InvalidGovernanceMessage => write!(f, "Invalid governance message"),
+            PythReceiverError::InvalidGovernanceTarget => write!(f, "Invalid governance target"),
+            PythReceiverError::InvalidGovernanceAction => write!(f, "Invalid governance action"),
+            PythReceiverError::InvalidGovernanceDataSource => write!(f, "Invalid governance data source"),
+            PythReceiverError::OldGovernanceMessage => write!(f, "Old governance message"),
+            PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "Governance message already executed"),
+            PythReceiverError::InvalidWormholeAddressToSet => write!(f, "Invalid Wormhole address to set"),
+        }
     }
 }