Skip to content

Commit

Permalink
Add randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 30, 2024
1 parent d0c10bc commit 01a1b38
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 10 additions & 0 deletions pythnet/pythnet_sdk/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ pub fn create_vaa_from_payload(

(header, body).into()
}

pub fn trim_vaa_signatures(vaa: Vec<u8>, n: u8) -> Vec<u8> {
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use {
dummy_guardians,
DEFAULT_DATA_SOURCE,
},
serde_wormhole::RawMessage,
solana_program::{
keccak,
pubkey::Pubkey,
Expand All @@ -40,7 +39,6 @@ use {
},
ID as BRIDGE_ID,
},
wormhole_sdk::Vaa,
};

pub const DEFAULT_GUARDIAN_SET_INDEX: u32 = 0;
Expand Down Expand Up @@ -170,9 +168,3 @@ pub async fn setup_pyth_receiver(vaas: Vec<Vec<u8>>) -> ProgramTestFixtures {
encoded_vaa_addresses,
}
}

pub fn trim_vaa_signatures(vaa: Vec<u8>, n: u8) -> Vec<u8> {
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()
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,6 +17,7 @@ use {
test_utils::{
create_accumulator_message,
create_dummy_price_feed_message,
trim_vaa_signatures,
},
},
solana_sdk::{
Expand Down

0 comments on commit 01a1b38

Please sign in to comment.