Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 30, 2024
1 parent 8e810fc commit 4ba2740
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
24 changes: 21 additions & 3 deletions pythnet/pythnet_sdk/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use {
wormhole_sdk::{
vaa::{
Body,
Header,
},
Address,
Chain,
Expand Down Expand Up @@ -180,7 +181,7 @@ pub fn create_vaa_from_payload(
emitter_chain: Chain,
sequence: u64,
) -> Vaa<Box<RawMessage>> {
let guardians = create_dummy_guardians();
let guardians = dummy_guardians();

let body: Body<Box<RawMessage>> = Body {
emitter_chain,
Expand All @@ -192,7 +193,7 @@ pub fn create_vaa_from_payload(

let digest = libsecp256k1Message::parse_slice(&body.digest().unwrap().secp256k_hash).unwrap();

let signatures: Vec<(Signature, RecoveryId)> = guardians[0..NUM_SIGNATURES]
let signatures: Vec<(Signature, RecoveryId)> = guardians
.iter()
.map(|x| libsecp256k1::sign(&digest, &x))
.collect();
Expand All @@ -210,13 +211,30 @@ pub fn create_vaa_from_payload(
})
.collect();

let mut wormhole_signatures_subset: Vec<wormhole_sdk::vaa::Signature> = wormhole_signatures
.choose_multiple(&mut thread_rng(), DEFAULT_NUM_SIGNATURES)
.cloned()
.collect();

wormhole_signatures_subset.sort_by(|a, b| a.index.cmp(&b.index));

let header = Header {
version: 1,
signatures: wormhole_signatures,
signatures: wormhole_signatures_subset,
..Default::default()
};


(header, body).into()
}

pub fn trim_vaa_signatures(vaa: Vaa<&RawMessage>, n: u8) -> Vaa<&RawMessage> {
let mut vaa_copy = vaa.clone();
vaa_copy.signatures = vaa
.signatures
.choose_multiple(&mut thread_rng(), n.into())
.cloned()
.collect();
vaa_copy.signatures.sort_by(|a, b| a.index.cmp(&b.index));
vaa_copy
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use {
<<<<<<< HEAD
crate::common::DEFAULT_GUARDIAN_SET_INDEX,
=======
crate::common::{
trim_vaa_signatures,
DEFAULT_GUARDIAN_SET_INDEX,
},
>>>>>>> c6431163 (Go)
common::{
setup_pyth_receiver,
ProgramTestFixtures,
Expand All @@ -29,10 +22,7 @@ use {
test_utils::{
create_accumulator_message,
create_dummy_price_feed_message,
<<<<<<< HEAD
trim_vaa_signatures,
=======
>>>>>>> c6431163 (Go)
},
},
serde_wormhole::RawMessage,
Expand All @@ -53,16 +43,11 @@ async fn test_post_updates_atomic() {
let feed_2 = create_dummy_price_feed_message(200);
let message = create_accumulator_message(&[feed_1, feed_2], &[feed_1, feed_2], false);
let (vaa, merkle_price_updates) = deserialize_accumulator_update_data(message).unwrap();
<<<<<<< HEAD
let vaa = serde_wormhole::to_vec(&trim_vaa_signatures(
serde_wormhole::from_slice(&vaa).unwrap(),
5,
))
.unwrap();
=======

let vaa = trim_vaa_signatures(vaa, 5);
>>>>>>> c6431163 (Go)

let ProgramTestFixtures {
mut program_simulator,
Expand Down Expand Up @@ -154,7 +139,11 @@ async fn test_post_updates_atomic_wrong_vaa() {
let poster = program_simulator.get_funded_keypair().await.unwrap();
let price_update_keypair = Keypair::new();

let vaa_wrong_num_signatures = trim_vaa_signatures(vaa.clone(), 4);
let vaa_wrong_num_signatures = serde_wormhole::to_vec(&trim_vaa_signatures(
serde_wormhole::from_slice(&vaa).unwrap(),
4,
))
.unwrap();
assert_eq!(
program_simulator
.process_ix(
Expand Down

0 comments on commit 4ba2740

Please sign in to comment.