File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ mod test_del_product;
8
8
mod test_del_publisher;
9
9
mod test_init_mapping;
10
10
mod test_init_price;
11
+ mod test_resize_account;
11
12
mod test_set_min_pub;
12
13
mod test_sizes;
13
14
mod test_upd_aggregate;
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ use solana_program::instruction::{
11
11
} ;
12
12
use solana_program:: pubkey:: Pubkey ;
13
13
use solana_program:: rent:: Rent ;
14
- use solana_program:: system_instruction;
14
+ use solana_program:: {
15
+ system_instruction,
16
+ system_program,
17
+ } ;
15
18
use solana_program_test:: {
16
19
processor,
17
20
BanksClient ,
@@ -224,6 +227,27 @@ impl PythSimulator {
224
227
. await
225
228
}
226
229
230
+ /// Resize a price account (using the resize_price_account
231
+ /// instruction).
232
+ pub async fn resize_price_account (
233
+ & mut self ,
234
+ price_keypair : & Keypair ,
235
+ ) -> Result < ( ) , BanksClientError > {
236
+ let cmd: CommandHeader = OracleCommand :: ResizePriceAccount . into ( ) ;
237
+ let instruction = Instruction :: new_with_bytes (
238
+ self . program_id ,
239
+ bytes_of ( & cmd) ,
240
+ vec ! [
241
+ AccountMeta :: new( self . payer. pubkey( ) , true ) ,
242
+ AccountMeta :: new( price_keypair. pubkey( ) , true ) ,
243
+ AccountMeta :: new( system_program:: id( ) , false ) ,
244
+ ] ,
245
+ ) ;
246
+
247
+ self . process_ix ( instruction, & vec ! [ & price_keypair] ) . await
248
+ }
249
+
250
+
227
251
/// Get the account at `key`. Returns `None` if no such account exists.
228
252
pub async fn get_account ( & mut self , key : Pubkey ) -> Option < Account > {
229
253
self . banks_client . get_account ( key) . await . unwrap ( )
Original file line number Diff line number Diff line change
1
+ use solana_sdk:: signer:: Signer ;
2
+ use std:: mem:: size_of;
3
+
4
+ use crate :: c_oracle_header:: pc_price_t;
5
+ use crate :: tests:: pyth_simulator:: PythSimulator ;
6
+ use crate :: time_machine_types:: PriceAccountWrapper ;
7
+
8
+
9
+ /// Warning : This test will fail if you run cargo test instead of cargo test-bpf
10
+ #[ tokio:: test]
11
+ async fn test_resize_account ( ) {
12
+ let mut sim = PythSimulator :: new ( ) . await ;
13
+ let mapping_keypair = sim. init_mapping ( ) . await . unwrap ( ) ;
14
+ let product1 = sim. add_product ( & mapping_keypair) . await . unwrap ( ) ;
15
+ let price1 = sim. add_price ( & product1, -8 ) . await . unwrap ( ) ;
16
+
17
+ // Check size after initialization
18
+ let price1_account = sim. get_account ( price1. pubkey ( ) ) . await . unwrap ( ) ;
19
+ assert_eq ! ( price1_account. data. len( ) , size_of:: <pc_price_t>( ) ) ;
20
+
21
+ // Run the instruction once
22
+ assert ! ( sim. resize_price_account( & price1) . await . is_ok( ) ) ;
23
+ // Check new size
24
+ let price1_account = sim. get_account ( price1. pubkey ( ) ) . await . unwrap ( ) ;
25
+ assert_eq ! ( price1_account. data. len( ) , size_of:: <PriceAccountWrapper >( ) ) ;
26
+
27
+ // Future calls don't change the size
28
+ assert ! ( sim. resize_price_account( & price1) . await . is_ok( ) ) ;
29
+ let price1_account = sim. get_account ( price1. pubkey ( ) ) . await . unwrap ( ) ;
30
+ assert_eq ! ( price1_account. data. len( ) , size_of:: <PriceAccountWrapper >( ) ) ;
31
+ }
You can’t perform that action at this time.
0 commit comments