From 9cf784a8cacee82dadc58ac1e2564a4b9f6deb37 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Thu, 25 Jan 2024 12:47:42 +0000 Subject: [PATCH] Factor create_dummy_price_feed_message --- pythnet/pythnet_sdk/src/test_utils/mod.rs | 21 ++++++++++++++++++- .../cosmwasm/contracts/pyth/src/contract.rs | 17 +-------------- .../near/receiver/tests/workspaces.rs | 18 +--------------- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/pythnet/pythnet_sdk/src/test_utils/mod.rs b/pythnet/pythnet_sdk/src/test_utils/mod.rs index cf7974c868..c628142b0b 100644 --- a/pythnet/pythnet_sdk/src/test_utils/mod.rs +++ b/pythnet/pythnet_sdk/src/test_utils/mod.rs @@ -5,7 +5,10 @@ use { Accumulator, }, hashers::keccak256_160::Keccak160, - messages::Message, + messages::{ + Message, + PriceFeedMessage, + }, wire::{ to_vec, v1::{ @@ -51,6 +54,22 @@ pub fn default_wrong_emitter_addr() -> [u8; 32] { [4u8; 32] } +pub fn create_dummy_price_feed_message(value: i64) -> Message { + let mut dummy_id = [0; 32]; + dummy_id[0] = value as u8; + let msg = PriceFeedMessage { + feed_id: dummy_id, + price: value, + conf: value as u64, + exponent: value as i32, + publish_time: value, + prev_publish_time: value, + ema_price: value, + ema_conf: value as u64, + }; + Message::PriceFeedMessage(msg) +} + pub fn create_accumulator_message( all_feeds: &[Message], updates: &[Message], diff --git a/target_chains/cosmwasm/contracts/pyth/src/contract.rs b/target_chains/cosmwasm/contracts/pyth/src/contract.rs index 16250015f4..a44c2b6e88 100644 --- a/target_chains/cosmwasm/contracts/pyth/src/contract.rs +++ b/target_chains/cosmwasm/contracts/pyth/src/contract.rs @@ -838,6 +838,7 @@ mod test { test_utils::{ create_accumulator_message, create_accumulator_message_from_updates, + create_dummy_price_feed_message, create_vaa_from_payload, default_emitter_addr, default_governance_addr, @@ -1163,22 +1164,6 @@ mod test { assert_eq!(new_attestations.len(), 0); } - fn create_dummy_price_feed_message(value: i64) -> Message { - let mut dummy_id = [0; 32]; - dummy_id[0] = value as u8; - let msg = PriceFeedMessage { - feed_id: dummy_id, - price: value, - conf: value as u64, - exponent: value as i32, - publish_time: value, - prev_publish_time: value, - ema_price: value, - ema_conf: value as u64, - }; - Message::PriceFeedMessage(msg) - } - fn check_price_match(deps: &OwnedDeps, msg: &Message) { match msg { Message::PriceFeedMessage(feed_msg) => { diff --git a/target_chains/near/receiver/tests/workspaces.rs b/target_chains/near/receiver/tests/workspaces.rs index 3a56d21e47..23e7fb81f1 100644 --- a/target_chains/near/receiver/tests/workspaces.rs +++ b/target_chains/near/receiver/tests/workspaces.rs @@ -27,7 +27,7 @@ use { }, hashers::keccak256_160::Keccak160, messages::{ Message, PriceFeedMessage, - }, test_utils::create_accumulator_message, wire::{ + }, test_utils::{create_accumulator_message, create_dummy_price_feed_message}, wire::{ to_vec, v1::{ AccumulatorUpdateData, @@ -967,22 +967,6 @@ async fn test_governance_target_fails_if_not_near() { // A test to check accumulator style updates work as intended. #[tokio::test] async fn test_accumulator_updates() { - fn create_dummy_price_feed_message(value: i64) -> Message { - let mut dummy_id = [0; 32]; - dummy_id[0] = value as u8; - let msg = PriceFeedMessage { - feed_id: dummy_id, - price: value, - conf: value as u64, - exponent: value as i32, - publish_time: value, - prev_publish_time: value, - ema_price: value, - ema_conf: value as u64, - }; - Message::PriceFeedMessage(msg) - } - let (_, contract, _) = initialize_chain().await; // Submit a new Source to the contract, this will trigger a cross-contract call to wormhole