3434 Serialize ,
3535 } ,
3636 solana_program:: pubkey:: Pubkey ,
37+ solana_sdk:: account_info:: AccountInfo ,
3738 std:: {
3839 fs:: File ,
3940 mem:: size_of,
4445#[ test]
4546fn test_ema_multiple_publishers_same_slot ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
4647 let mut instruction_data = [ 0u8 ; size_of :: < UpdPriceArgs > ( ) ] ;
47- populate_instruction ( & mut instruction_data, 10 , 1 , 1 ) ;
4848
4949 let program_id = Pubkey :: new_unique ( ) ;
5050
@@ -56,11 +56,7 @@ fn test_ema_multiple_publishers_same_slot() -> Result<(), Box<dyn std::error::Er
5656 price_account. is_signer = false ;
5757 PriceAccount :: initialize ( & price_account, PC_VERSION ) . unwrap ( ) ;
5858
59- {
60- let mut price_data = load_checked :: < PriceAccount > ( & price_account, PC_VERSION ) . unwrap ( ) ;
61- price_data. num_ = 1 ;
62- price_data. comp_ [ 0 ] . pub_ = * funding_account. key ;
63- }
59+ add_publisher ( & mut price_account, funding_account. key , 0 ) ;
6460
6561 let mut clock_setup = AccountSetup :: new_clock ( ) ;
6662 let mut clock_account = clock_setup. as_account_info ( ) ;
@@ -69,6 +65,7 @@ fn test_ema_multiple_publishers_same_slot() -> Result<(), Box<dyn std::error::Er
6965
7066 update_clock_slot ( & mut clock_account, 1 ) ;
7167
68+ populate_instruction ( & mut instruction_data, 10 , 1 , 1 ) ;
7269 process_instruction (
7370 & program_id,
7471 & [
@@ -91,11 +88,7 @@ fn test_ema_multiple_publishers_same_slot() -> Result<(), Box<dyn std::error::Er
9188 let mut funding_setup_two = AccountSetup :: new_funding ( ) ;
9289 let funding_account_two = funding_setup_two. as_account_info ( ) ;
9390
94- {
95- let mut price_data = load_checked :: < PriceAccount > ( & price_account, PC_VERSION ) . unwrap ( ) ;
96- price_data. num_ = 2 ;
97- price_data. comp_ [ 1 ] . pub_ = * funding_account_two. key ;
98- }
91+ add_publisher ( & mut price_account, funding_account_two. key , 1 ) ;
9992
10093 update_clock_slot ( & mut clock_account, 2 ) ;
10194
@@ -331,3 +324,9 @@ fn populate_instruction(instruction_data: &mut [u8], price: i64, conf: u64, pub_
331324 cmd. publishing_slot = pub_slot;
332325 cmd. unused_ = 0 ;
333326}
327+
328+ fn add_publisher ( price_account : & mut AccountInfo , publisher_key : & Pubkey , index : usize ) {
329+ let mut price_data = load_checked :: < PriceAccount > ( price_account, PC_VERSION ) . unwrap ( ) ;
330+ price_data. num_ = ( index + 1 ) as u32 ;
331+ price_data. comp_ [ index] . pub_ = * publisher_key;
332+ }
0 commit comments