Jayant Krishnamurthy 2 年之前
父節點
當前提交
e4dcb066ba

+ 3 - 2
target_chains/solana/programs/solana-receiver/src/lib.rs

@@ -19,12 +19,13 @@ use wormhole_solana::instructions::PostVAAData;
 
 use crate::error::ReceiverError::*;
 
+declare_id!("pythKkWXoywbvTQVcWrNDz5ENvWteF7tem7xzW52NBK");
+
 #[program]
 pub mod pyth_solana_receiver {
     use super::*;
 
     pub const PROGRAM_ID: &str = "pythKkWXoywbvTQVcWrNDz5ENvWteF7tem7xzW52NBK";
-    declare_id!("pythKkWXoywbvTQVcWrNDz5ENvWteF7tem7xzW52NBK");
 
     pub fn decode_posted_vaa(ctx: Context<DecodePostedVaa>) -> Result<()> {
         let posted_vaa = &ctx.accounts.posted_vaa.payload;
@@ -49,7 +50,7 @@ pub mod pyth_solana_receiver {
         Ok(())
     }
 
-    pub fn update_price(ctx: Context<UpdatePrice>, data: Vec<u8>) -> Result<()> {
+    pub fn update(ctx: Context<UpdatePrice>, data: Vec<u8>) -> Result<()> {
         // FIXME: more security checks
         // ctx.accounts.guardian_set.index == vaa_data.index;
 

+ 2 - 1
target_chains/solana/programs/solana-receiver/src/tests/simulator.rs

@@ -4,6 +4,7 @@ use {
             self,
             UpgradeableLoaderState,
         },
+        hash::hash,
         hash::Hash,
         instruction::{
             AccountMeta,
@@ -384,6 +385,6 @@ pub fn sighash(namespace: &str, name: &str) -> [u8; 8] {
     let preimage = format!("{namespace}:{name}");
 
     let mut sighash = [0u8; 8];
-    sighash.copy_from_slice(&hashv(&[preimage.as_bytes()]).to_bytes()[..8]);
+    sighash.copy_from_slice(&hash(preimage.as_bytes()).to_bytes()[..8]);
     sighash
 }

+ 4 - 14
target_chains/solana/programs/solana-receiver/src/tests/test_update_price.rs

@@ -1,33 +1,23 @@
-use pyth_solana_receiver::PythSolanaReceiver;
-use solana_program_test::processor;
-
 use {
     solana_program::{
         program_error::ProgramError,
         pubkey::Pubkey,
         instruction::Instruction,
     },
-    anchor_client,
+    crate::pyth_solana_receiver
 };
-use crate::pyth_solana_receiver;
 use anchor_lang::prelude::*;
+use anchor_lang::Discriminator;
 
 use crate::tests::simulator::PythSimulator;
+use crate::tests::simulator::sighash;
 
 #[tokio::test]
 async fn test_add_price() {
 
     let mut sim = PythSimulator::new().await;
 
-    let instruction_data = vec![crate::sighash("global", "update_price")];
-
-    let instruction = solana_sdk::instruction::Instruction {
-        program_id,
-        accounts: vec![],
-        data: instruction_data,
-    };
-
-    let instruction = Instruction::new_with_bytes(sim.program_id, &discriminator, vec![]);
+    let instruction = Instruction::new_with_bytes(sim.program_id, &(pyth_solana_receiver::instruction::Update.data()), vec![]);
 
     let result = sim.process_ix(instruction, &vec![], &sim.genesis_keypair.insecure_clone()).await.unwrap();