Skip to content

Commit

Permalink
Factor create_dummy_price_feed_message
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 25, 2024
1 parent 611eb5e commit 9cf784a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
21 changes: 20 additions & 1 deletion pythnet/pythnet_sdk/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use {
Accumulator,
},
hashers::keccak256_160::Keccak160,
messages::Message,
messages::{
Message,
PriceFeedMessage,
},
wire::{
to_vec,
v1::{
Expand Down Expand Up @@ -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],
Expand Down
17 changes: 1 addition & 16 deletions target_chains/cosmwasm/contracts/pyth/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<MockStorage, MockApi, MockQuerier>, msg: &Message) {
match msg {
Message::PriceFeedMessage(feed_msg) => {
Expand Down
18 changes: 1 addition & 17 deletions target_chains/near/receiver/tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cf784a

Please sign in to comment.