Bläddra i källkod

fix: resolve function selector mismatches in proxy delegation tests

- Add conditional InnerTypes trait implementation to PythReceiverError
- Fix main.rs to use correct print_abi call for ABI generation
- Update sol! macro function signatures to match generated ABI
- Fix type conversions in test calls (FixedBytes -> [u8; 32], Vec<Bytes> -> Vec<Vec<u8>>)
- All 20 tests now passing: 9 end-to-end + 8 integration + 3 receiver proxy tests

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
Devin AI 3 månader sedan
förälder
incheckning
ff51d3187f

+ 10 - 28
target_chains/stylus/contracts/pyth-proxy/src/end_to_end_proxy_tests.rs

@@ -8,23 +8,10 @@ mod end_to_end_proxy_tests {
     use wormhole_contract::WormholeContract;
 
     sol! {
-        struct Price {
-            int64 price;
-            uint64 conf;
-            int32 expo;
-            uint publish_time;
-        }
-
-        struct PriceFeed {
-            bytes32 id;
-            Price price;
-            Price ema_price;
-        }
-
-        function getPriceUnsafe(bytes32 id) external view returns (int64,uint64,int32,uint);
-        function updatePriceFeeds(bytes[] calldata updateData) external payable;
-        function queryPriceFeed(bytes32 id) public view returns (PriceFeed[] memory priceFeeds);
-        function priceFeedExists(bytes32 id) public view returns (PriceFeed[] memory priceFeeds);
+        function getPriceUnsafe(uint8[32] calldata id) external view returns (int64,uint64,int32,uint64);
+        function updatePriceFeeds(uint8[][] memory update_data) external payable;
+        function queryPriceFeed(uint8[32] calldata id) external view returns (bytes32,uint64,int32,int64,uint64,int64,uint64);
+        function priceFeedExists(uint8[32] calldata id) external view returns (bool);
     }
 
     const OWNER: Address = address!("beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe");
@@ -88,7 +75,7 @@ mod end_to_end_proxy_tests {
         let direct_result = receiver.sender(alice).get_price_unsafe(test_id);
         assert!(direct_result.is_err(), "Direct call should fail with no price data");
 
-        let call_data = getPriceUnsafeCall::new((FixedBytes::from(test_id),)).abi_encode();
+        let call_data = getPriceUnsafeCall::new((test_id,)).abi_encode();
         let proxy_result = proxy.sender(OWNER).relay_to_implementation(call_data);
         
         assert!(proxy_result.is_err(), "Proxy call should also fail with no price data");
@@ -111,7 +98,7 @@ mod end_to_end_proxy_tests {
         let direct_exists = receiver.sender(alice).price_feed_exists(test_id);
         assert!(!direct_exists, "Price feed should not exist initially");
 
-        let call_data = priceFeedExistsCall::new((FixedBytes::from(test_id),)).abi_encode();
+        let call_data = priceFeedExistsCall::new((test_id,)).abi_encode();
         let proxy_result = proxy.sender(OWNER).relay_to_implementation(call_data);
         
         if proxy_result.is_err() {
@@ -134,19 +121,14 @@ mod end_to_end_proxy_tests {
         setup_proxy_with_receiver(&proxy, &receiver, &wormhole, &alice);
 
         let update_data = ban_usd_update();
-        let update_data_bytes: Vec<alloy_primitives::Bytes> = update_data
-            .into_iter()
-            .map(|data| alloy_primitives::Bytes::from(data))
-            .collect();
+        let update_data_bytes: Vec<Vec<u8>> = update_data;
         
         let call_data = updatePriceFeedsCall::new((update_data_bytes.clone(),)).abi_encode();
         let proxy_result = proxy.sender(OWNER).relay_to_implementation(call_data);
         
         assert!(proxy_result.is_err(), "Proxy call should fail due to insufficient fee");
         
-        let direct_result = receiver.sender(alice).update_price_feeds(
-            update_data_bytes.into_iter().map(|b| b.to_vec()).collect()
-        );
+        let direct_result = receiver.sender(alice).update_price_feeds(update_data_bytes.clone());
         assert!(direct_result.is_err(), "Direct call should also fail with insufficient fee");
     }
 
@@ -161,7 +143,7 @@ mod end_to_end_proxy_tests {
 
         let test_id = ban_usd_feed_id();
         
-        let exists_call = priceFeedExistsCall::new((FixedBytes::from(test_id),)).abi_encode();
+        let exists_call = priceFeedExistsCall::new((test_id,)).abi_encode();
         let exists_result = proxy.sender(OWNER).relay_to_implementation(exists_call);
         
         if exists_result.is_err() {
@@ -169,7 +151,7 @@ mod end_to_end_proxy_tests {
         }
         assert!(exists_result.is_ok(), "Price feed exists check should work through proxy");
 
-        let price_call = getPriceUnsafeCall::new((FixedBytes::from(test_id),)).abi_encode();
+        let price_call = getPriceUnsafeCall::new((test_id,)).abi_encode();
         let price_result = proxy.sender(OWNER).relay_to_implementation(price_call);
         assert!(price_result.is_err(), "Get price should fail when no data exists");
 

+ 6 - 0
target_chains/stylus/contracts/pyth-receiver/src/error.rs

@@ -1,5 +1,8 @@
 use alloc::vec::Vec;
 
+#[cfg(feature = "export-abi")]
+use stylus_sdk::abi::export::internal::InnerTypes;
+
 #[derive(PartialEq)]
 pub enum PythReceiverError {
     PriceUnavailable,
@@ -122,6 +125,9 @@ impl core::fmt::Display for PythReceiverError {
     }
 }
 
+#[cfg(feature = "export-abi")]
+impl InnerTypes for PythReceiverError {}
+
 impl From<PythReceiverError> for Vec<u8> {
     fn from(error: PythReceiverError) -> Vec<u8> {
         vec![match error {

+ 2 - 1
target_chains/stylus/contracts/pyth-receiver/src/main.rs

@@ -6,5 +6,6 @@ pub extern "C" fn main() {}
 
 #[cfg(feature = "export-abi")]
 fn main() {
-    stylus_hello_world::print_from_args();
+    use pyth_receiver_stylus::PythReceiver;
+    stylus_sdk::abi::export::print_abi::<PythReceiver>("pyth-receiver-stylus", include_str!("../Cargo.toml"));
 }