1010 pyth_oracle:: {
1111 solana_program:: account_info:: AccountInfo , PriceAccount , PriceAccountFlags , PythAccount ,
1212 } ,
13- pyth_price_publisher:: accounts:: publisher_prices:: {
14- self as publisher_prices_account, PublisherPrice ,
13+ pyth_price_store:: {
14+ accounts:: {
15+ buffer:: { self , BufferedPrice } ,
16+ publisher_config,
17+ } ,
18+ instruction:: PUBLISHER_CONFIG_SEED ,
1519 } ,
1620 solana_sdk:: {
1721 account:: { AccountSharedData , ReadableAccount , WritableAccount } ,
@@ -38,37 +42,55 @@ fn test_batch_publish() {
3842 genesis_config. epoch_schedule = EpochSchedule :: new ( slots_in_epoch) ;
3943 let mut bank = create_new_bank_for_tests_with_index ( & genesis_config) ;
4044
41- let generate_publisher = |seed, new_prices| {
42- let publisher1_key = keypair_from_seed ( seed) . unwrap ( ) ;
45+ let generate_publisher = |seed, seed2 , new_prices| {
46+ let publisher_key = keypair_from_seed ( seed) . unwrap ( ) ;
4347
44- let ( publisher1_prices_key, _bump) = Pubkey :: find_program_address (
45- & [ b"BUFFER" , & publisher1_key. pubkey ( ) . to_bytes ( ) ] ,
48+ let ( publisher_config_key, _bump) = Pubkey :: find_program_address (
49+ & [
50+ PUBLISHER_CONFIG_SEED . as_bytes ( ) ,
51+ & publisher_key. pubkey ( ) . to_bytes ( ) ,
52+ ] ,
4653 & BATCH_PUBLISH_PID ,
4754 ) ;
48- let mut publisher1_prices_account =
49- AccountSharedData :: new ( 42 , publisher_prices_account:: size ( 100 ) , & BATCH_PUBLISH_PID ) ;
55+ let publisher_buffer_key =
56+ Pubkey :: create_with_seed ( & leader_pubkey, seed2, & BATCH_PUBLISH_PID ) . unwrap ( ) ;
57+
58+ let mut publisher_config_account =
59+ AccountSharedData :: new ( 42 , publisher_config:: SIZE , & BATCH_PUBLISH_PID ) ;
60+
61+ publisher_config:: create (
62+ publisher_config_account. data_mut ( ) ,
63+ publisher_key. pubkey ( ) . to_bytes ( ) ,
64+ publisher_buffer_key. to_bytes ( ) ,
65+ )
66+ . unwrap ( ) ;
67+ bank. store_account ( & publisher_config_key, & publisher_config_account) ;
68+
69+ let mut publisher_buffer_account =
70+ AccountSharedData :: new ( 42 , buffer:: size ( 100 ) , & BATCH_PUBLISH_PID ) ;
5071 {
51- let ( header, prices) = publisher_prices_account :: create (
52- publisher1_prices_account . data_mut ( ) ,
53- publisher1_key . pubkey ( ) . to_bytes ( ) ,
72+ let ( header, prices) = buffer :: create (
73+ publisher_buffer_account . data_mut ( ) ,
74+ publisher_key . pubkey ( ) . to_bytes ( ) ,
5475 )
5576 . unwrap ( ) ;
56- publisher_prices_account :: extend ( header, prices, cast_slice ( new_prices) ) . unwrap ( ) ;
77+ buffer :: update ( header, prices, bank . slot ( ) , cast_slice ( new_prices) ) . unwrap ( ) ;
5778 }
58- bank. store_account ( & publisher1_prices_key , & publisher1_prices_account ) ;
79+ bank. store_account ( & publisher_buffer_key , & publisher_buffer_account ) ;
5980
60- publisher1_key
81+ publisher_key
6182 } ;
6283
6384 let publishers = [
6485 generate_publisher (
6586 & [ 1u8 ; 32 ] ,
87+ "seed1" ,
6688 & [
67- PublisherPrice :: new ( 1 , 1 , 10 , 2 ) . unwrap ( ) ,
68- PublisherPrice :: new ( 2 , 1 , 20 , 3 ) . unwrap ( ) ,
89+ BufferedPrice :: new ( 1 , 1 , 10 , 2 ) . unwrap ( ) ,
90+ BufferedPrice :: new ( 2 , 1 , 20 , 3 ) . unwrap ( ) ,
6991 // Attempt to publish with price_index == 0,
7092 // but it will not be applied.
71- PublisherPrice {
93+ BufferedPrice {
7294 trading_status_and_feed_index : 0 ,
7395 price : 30 ,
7496 confidence : 35 ,
@@ -77,9 +99,10 @@ fn test_batch_publish() {
7799 ) ,
78100 generate_publisher (
79101 & [ 2u8 ; 32 ] ,
102+ "seed2" ,
80103 & [
81- PublisherPrice :: new ( 1 , 1 , 15 , 2 ) . unwrap ( ) ,
82- PublisherPrice :: new ( 2 , 1 , 25 , 3 ) . unwrap ( ) ,
104+ BufferedPrice :: new ( 1 , 1 , 15 , 2 ) . unwrap ( ) ,
105+ BufferedPrice :: new ( 2 , 1 , 25 , 3 ) . unwrap ( ) ,
83106 ] ,
84107 ) ,
85108 ] ;
0 commit comments