From 01a1b3869110445d128ced2b6780e8a0fcb7ad97 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 30 Jan 2024 12:12:17 +0000 Subject: [PATCH] Add randomness --- pythnet/pythnet_sdk/src/test_utils/mod.rs | 10 ++++++++++ .../programs/pyth-solana-receiver/tests/common/mod.rs | 8 -------- .../tests/test_post_updates_atomic.rs | 6 ++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pythnet/pythnet_sdk/src/test_utils/mod.rs b/pythnet/pythnet_sdk/src/test_utils/mod.rs index 04a50012d5..1fdbb039cf 100644 --- a/pythnet/pythnet_sdk/src/test_utils/mod.rs +++ b/pythnet/pythnet_sdk/src/test_utils/mod.rs @@ -228,3 +228,13 @@ pub fn create_vaa_from_payload( (header, body).into() } + +pub fn trim_vaa_signatures(vaa: Vec, n: u8) -> Vec { + let mut parsed_vaa: Vaa<&RawMessage> = serde_wormhole::from_slice(vaa.as_slice()).unwrap(); + parsed_vaa.signatures = parsed_vaa + .signatures + .choose_multiple(&mut thread_rng(), n.into()) + .cloned() + .collect(); + serde_wormhole::to_vec(&parsed_vaa).unwrap() +} diff --git a/target_chains/solana/programs/pyth-solana-receiver/tests/common/mod.rs b/target_chains/solana/programs/pyth-solana-receiver/tests/common/mod.rs index 41d72f128e..18aadaf04d 100644 --- a/target_chains/solana/programs/pyth-solana-receiver/tests/common/mod.rs +++ b/target_chains/solana/programs/pyth-solana-receiver/tests/common/mod.rs @@ -19,7 +19,6 @@ use { dummy_guardians, DEFAULT_DATA_SOURCE, }, - serde_wormhole::RawMessage, solana_program::{ keccak, pubkey::Pubkey, @@ -40,7 +39,6 @@ use { }, ID as BRIDGE_ID, }, - wormhole_sdk::Vaa, }; pub const DEFAULT_GUARDIAN_SET_INDEX: u32 = 0; @@ -170,9 +168,3 @@ pub async fn setup_pyth_receiver(vaas: Vec>) -> ProgramTestFixtures { encoded_vaa_addresses, } } - -pub fn trim_vaa_signatures(vaa: Vec, n: u8) -> Vec { - let mut parsed_vaa: Vaa<&RawMessage> = serde_wormhole::from_slice(vaa.as_slice()).unwrap(); - parsed_vaa.signatures = parsed_vaa.signatures[0..n as usize].to_vec(); - serde_wormhole::to_vec(&parsed_vaa).unwrap() -} diff --git a/target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates_atomic.rs b/target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates_atomic.rs index eea97fea5c..7b8ba3085b 100644 --- a/target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates_atomic.rs +++ b/target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates_atomic.rs @@ -1,8 +1,5 @@ use { - crate::common::{ - trim_vaa_signatures, - DEFAULT_GUARDIAN_SET_INDEX, - }, + crate::common::DEFAULT_GUARDIAN_SET_INDEX, common::{ setup_pyth_receiver, ProgramTestFixtures, @@ -20,6 +17,7 @@ use { test_utils::{ create_accumulator_message, create_dummy_price_feed_message, + trim_vaa_signatures, }, }, solana_sdk::{