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;
88mod test_del_publisher;
99mod test_init_mapping;
1010mod test_init_price;
11+ mod test_resize_account;
1112mod test_set_min_pub;
1213mod test_sizes;
1314mod test_upd_aggregate;
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ use solana_program::instruction::{
1111} ;
1212use solana_program:: pubkey:: Pubkey ;
1313use solana_program:: rent:: Rent ;
14- use solana_program:: system_instruction;
14+ use solana_program:: {
15+ system_instruction,
16+ system_program,
17+ } ;
1518use solana_program_test:: {
1619 processor,
1720 BanksClient ,
@@ -224,6 +227,27 @@ impl PythSimulator {
224227 . await
225228 }
226229
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+
227251 /// Get the account at `key`. Returns `None` if no such account exists.
228252 pub async fn get_account ( & mut self , key : Pubkey ) -> Option < Account > {
229253 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