10
10
pyth_oracle:: {
11
11
solana_program:: account_info:: AccountInfo , PriceAccount , PriceAccountFlags , PythAccount ,
12
12
} ,
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 ,
15
19
} ,
16
20
solana_sdk:: {
17
21
account:: { AccountSharedData , ReadableAccount , WritableAccount } ,
@@ -38,37 +42,55 @@ fn test_batch_publish() {
38
42
genesis_config. epoch_schedule = EpochSchedule :: new ( slots_in_epoch) ;
39
43
let mut bank = create_new_bank_for_tests_with_index ( & genesis_config) ;
40
44
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 ( ) ;
43
47
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
+ ] ,
46
53
& BATCH_PUBLISH_PID ,
47
54
) ;
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 ) ;
50
71
{
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 ( ) ,
54
75
)
55
76
. 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 ( ) ;
57
78
}
58
- bank. store_account ( & publisher1_prices_key , & publisher1_prices_account ) ;
79
+ bank. store_account ( & publisher_buffer_key , & publisher_buffer_account ) ;
59
80
60
- publisher1_key
81
+ publisher_key
61
82
} ;
62
83
63
84
let publishers = [
64
85
generate_publisher (
65
86
& [ 1u8 ; 32 ] ,
87
+ "seed1" ,
66
88
& [
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 ( ) ,
69
91
// Attempt to publish with price_index == 0,
70
92
// but it will not be applied.
71
- PublisherPrice {
93
+ BufferedPrice {
72
94
trading_status_and_feed_index : 0 ,
73
95
price : 30 ,
74
96
confidence : 35 ,
@@ -77,9 +99,10 @@ fn test_batch_publish() {
77
99
) ,
78
100
generate_publisher (
79
101
& [ 2u8 ; 32 ] ,
102
+ "seed2" ,
80
103
& [
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 ( ) ,
83
106
] ,
84
107
) ,
85
108
] ;
0 commit comments