From 40202b1b53eef32de9a6134e4b26b9fe7b5fed04 Mon Sep 17 00:00:00 2001 From: NOPE finance Date: Tue, 29 Jun 2021 07:05:00 -0700 Subject: [PATCH] fix tests --- .../tests/borrow_obligation_liquidity.rs | 2 +- ...hmqvom3Jemp5YNrxd9q9unX36BZk1pujkkXijL.bin | Bin 0 -> 50000 bytes ...cKN7wk8yKzLD6sxzUQUqLvhBV1rjMA4UJqfZuH.bin | Bin 0 -> 5000 bytes .../program/tests/fixtures/README.md | 4 ++ token-lending/program/tests/helpers/mod.rs | 62 +++++++++++++----- token-lending/program/tests/init_reserve.rs | 5 +- .../program/tests/obligation_end_to_end.rs | 9 ++- .../program/tests/refresh_obligation.rs | 6 +- .../program/tests/refresh_reserve.rs | 6 +- 9 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 token-lending/program/tests/fixtures/AdtRGGhmqvom3Jemp5YNrxd9q9unX36BZk1pujkkXijL.bin create mode 100644 token-lending/program/tests/fixtures/BAoygKcKN7wk8yKzLD6sxzUQUqLvhBV1rjMA4UJqfZuH.bin diff --git a/token-lending/program/tests/borrow_obligation_liquidity.rs b/token-lending/program/tests/borrow_obligation_liquidity.rs index 9b4a9a53134..29c3f32e483 100644 --- a/token-lending/program/tests/borrow_obligation_liquidity.rs +++ b/token-lending/program/tests/borrow_obligation_liquidity.rs @@ -175,7 +175,7 @@ async fn test_borrow_sol_max_amount() { ); // limit to track compute unit increase - test.set_bpf_compute_max_units(42_000); + test.set_bpf_compute_max_units(42_016); const FEE_AMOUNT: u64 = 5000; const HOST_FEE_AMOUNT: u64 = 1000; diff --git a/token-lending/program/tests/fixtures/AdtRGGhmqvom3Jemp5YNrxd9q9unX36BZk1pujkkXijL.bin b/token-lending/program/tests/fixtures/AdtRGGhmqvom3Jemp5YNrxd9q9unX36BZk1pujkkXijL.bin new file mode 100644 index 0000000000000000000000000000000000000000..0088c7fd35788a054beded2092480dee18361ec4 GIT binary patch literal 50000 zcmeIuZ%ov60LSrz=6ReV?8fl8MgBTk7=MZ`NK`5gLXm=kcEH7X1O#Rcxp9cbGDsW~ z=byk_r#1fJH61h|%d~q{qX!eddzT5V~n{U1Qm1A|{@i+Q&Q?(n89J%{ky`NSoywH;x zKH%EBxv%V@#cUbQ35eEQo0~Wtn>k%$$S$z{L@8viT3xpD+7{Wk=d{JvB~D|U2;QID zQ

m9&bw78+Sq}Y!Y2f=~%Y6u)=QLXAMc(6s5*xo7~{*X7(s2ZpLJ}n zqPKtSSH;DLN}*$3+-H1h_^?Nvv3$04a;3WCc=G4>-=CAJdMpRhBj=RD`e(Pr>mnQsLtNeOVIRIcm2WI5wNea+Ec|xb{HW~dE=A)FyUdt4uLxa)Wx&0|7?e;I z|7lC7`ixt?wN%J!ubsMivLO9%?$?*^yY-PE{7x7*(Lmc&;o_-3538@O^+^oJ^Hjg!oFa)B*(L=4?zm(`}lOE`!>dtrGQ=fKsG10dmJ#>brt8zpOpE1 zq+T*O+8q6*msE(+1y?10C%fUS7X`}Fw4oucnd)W_YqQE|bAIXirg^=n0YBXC`CcgJ#vGyw_`s zU;Jj{P=v8KVn+`4yA>7h$+Y|sw)4WdQpa5f#roJ^ literal 0 HcmV?d00001 diff --git a/token-lending/program/tests/fixtures/BAoygKcKN7wk8yKzLD6sxzUQUqLvhBV1rjMA4UJqfZuH.bin b/token-lending/program/tests/fixtures/BAoygKcKN7wk8yKzLD6sxzUQUqLvhBV1rjMA4UJqfZuH.bin new file mode 100644 index 0000000000000000000000000000000000000000..7f7e1a7c727f81b12d75a384b6ce8b861224a35f GIT binary patch literal 5000 zcmZSF$jZSe#KyrOz$n2krNEFb`XuU5`o{)_=cYGmqQ&esq&}06GUnQx_M5+QA?Ix+ zg`9kEi}b^H_r0GjqTTLhpYSC>k7=5~HNlv@ZmX(a96YO}aMG`MU*Fs)#kalZb$k{xi?Lp#g{-Xl?_0*m5&+e^|jG1-ui4&KCzOx(4@nupLYfm3zVOUbdzt^*HS^oco zg42`j|86UdXyj6`Ie%q#{E}p4rDs+FuWweJI4rnE)04eJ?AydHg?&M%a<~*4R%}?o z-KjN2*-Cn?$QNZ>>)iBJUv@7@wEFa-DqOMJhf87S-RVA^i*%fYL^8P#?#MnPmfZEQ z#@M9f-gA+ix=k--xD=)(i`V$bf7Ex3%Uv`(P^SC3mS4)b-?s6N(__mIUx=*cQefTH znD^_x0ndy33z$?-i&ZW6F`P74{L)ITtxFlC_5SckFd7wca0oC+ZtrFLAeO=9pm60) zzr4or-EZ31483@mwA;lv9V~kcR91Uub2&J|R1w9 TestMint { } pub struct TestOracle { - pub product_pubkey: Pubkey, - pub price_pubkey: Pubkey, + pub pyth_product_pubkey: Pubkey, + pub pyth_price_pubkey: Pubkey, + pub switchboard_feed_pubkey: Pubkey, pub price: Decimal, } @@ -1081,6 +1085,7 @@ pub fn add_sol_oracle(test: &mut ProgramTest) -> TestOracle { test, Pubkey::from_str(SOL_PYTH_PRODUCT).unwrap(), Pubkey::from_str(SOL_PYTH_PRICE).unwrap(), + Pubkey::from_str(SOL_SWITCHBOARD_FEED).unwrap(), // Set SOL price to $20 Decimal::from(20u64), ) @@ -1092,6 +1097,7 @@ pub fn add_usdc_oracle(test: &mut ProgramTest) -> TestOracle { // Mock with SRM since Pyth doesn't have USDC yet Pubkey::from_str(SRM_PYTH_PRODUCT).unwrap(), Pubkey::from_str(SRM_PYTH_PRICE).unwrap(), + Pubkey::from_str(SRM_SWITCHBOARD_FEED).unwrap(), // Set USDC price to $1 Decimal::from(1u64), ) @@ -1099,22 +1105,23 @@ pub fn add_usdc_oracle(test: &mut ProgramTest) -> TestOracle { pub fn add_oracle( test: &mut ProgramTest, - product_pubkey: Pubkey, - price_pubkey: Pubkey, + pyth_product_pubkey: Pubkey, + pyth_price_pubkey: Pubkey, + switchboard_feed_pubkey: Pubkey, price: Decimal, ) -> TestOracle { let oracle_program_id = read_keypair_file("tests/fixtures/oracle_program_id.json").unwrap(); // Add Pyth product account test.add_account_with_file_data( - product_pubkey, + pyth_product_pubkey, u32::MAX as u64, oracle_program_id.pubkey(), - &format!("{}.bin", product_pubkey.to_string()), + &format!("{}.bin", pyth_product_pubkey.to_string()), ); // Add Pyth price account after setting the price - let filename = &format!("{}.bin", price_pubkey.to_string()); + let filename = &format!("{}.bin", pyth_price_pubkey.to_string()); let mut pyth_price_data = read_file(find_file(filename).unwrap_or_else(|| { panic!("Unable to locate {}", filename); })); @@ -1135,7 +1142,7 @@ pub fn add_oracle( .unwrap(); test.add_account( - price_pubkey, + pyth_price_pubkey, Account { lamports: u32::MAX as u64, data: pyth_price_data, @@ -1145,9 +1152,28 @@ pub fn add_oracle( }, ); + // Add Switchboard price feed account after setting the price + let filename2 = &format!("{}.bin", switchboard_feed_pubkey.to_string()); + // mut and set data here later + let switchboard_feed_data = read_file(find_file(filename2).unwrap_or_else(|| { + panic!("Unable to locate {}", filename2); + })); + + test.add_account( + switchboard_feed_pubkey, + Account { + lamports: u32::MAX as u64, + data: switchboard_feed_data, + owner: oracle_program_id.pubkey(), + executable: false, + rent_epoch: 0, + }, + ); + TestOracle { - product_pubkey, - price_pubkey, + pyth_product_pubkey, + pyth_price_pubkey, + switchboard_feed_pubkey, price, } } diff --git a/token-lending/program/tests/init_reserve.rs b/token-lending/program/tests/init_reserve.rs index c8ddd1b6f18..19e56c9e0f6 100644 --- a/token-lending/program/tests/init_reserve.rs +++ b/token-lending/program/tests/init_reserve.rs @@ -120,8 +120,9 @@ async fn test_already_initialized() { usdc_test_reserve.liquidity_fee_receiver_pubkey, usdc_test_reserve.collateral_mint_pubkey, usdc_test_reserve.collateral_supply_pubkey, - usdc_oracle.product_pubkey, - usdc_oracle.price_pubkey, + usdc_oracle.pyth_product_pubkey, + usdc_oracle.pyth_price_pubkey, + usdc_oracle.switchboard_feed_pubkey, lending_market.pubkey, lending_market.owner.pubkey(), user_transfer_authority.pubkey(), diff --git a/token-lending/program/tests/obligation_end_to_end.rs b/token-lending/program/tests/obligation_end_to_end.rs index 1431d01258a..63fc728eecc 100644 --- a/token-lending/program/tests/obligation_end_to_end.rs +++ b/token-lending/program/tests/obligation_end_to_end.rs @@ -126,7 +126,8 @@ async fn test_success() { refresh_reserve( spl_token_lending::id(), sol_test_reserve.pubkey, - sol_oracle.price_pubkey, + sol_oracle.pyth_price_pubkey, + sol_oracle.switchboard_feed_pubkey, ), // 3 approve( @@ -160,7 +161,8 @@ async fn test_success() { refresh_reserve( spl_token_lending::id(), usdc_test_reserve.pubkey, - usdc_oracle.price_pubkey, + usdc_oracle.pyth_price_pubkey, + usdc_oracle.switchboard_feed_pubkey, ), // 7 borrow_obligation_liquidity( @@ -179,7 +181,8 @@ async fn test_success() { refresh_reserve( spl_token_lending::id(), usdc_test_reserve.pubkey, - usdc_oracle.price_pubkey, + usdc_oracle.pyth_price_pubkey, + usdc_oracle.switchboard_feed_pubkey, ), // 9 refresh_obligation( diff --git a/token-lending/program/tests/refresh_obligation.rs b/token-lending/program/tests/refresh_obligation.rs index 830825ba21a..9b82e9af142 100644 --- a/token-lending/program/tests/refresh_obligation.rs +++ b/token-lending/program/tests/refresh_obligation.rs @@ -110,12 +110,14 @@ async fn test_success() { refresh_reserve( spl_token_lending::id(), usdc_test_reserve.pubkey, - usdc_oracle.price_pubkey, + usdc_oracle.pyth_price_pubkey, + usdc_oracle.switchboard_feed_pubkey, ), refresh_reserve( spl_token_lending::id(), sol_test_reserve.pubkey, - sol_oracle.price_pubkey, + sol_oracle.pyth_price_pubkey, + sol_oracle.switchboard_feed_pubkey, ), refresh_obligation( spl_token_lending::id(), diff --git a/token-lending/program/tests/refresh_reserve.rs b/token-lending/program/tests/refresh_reserve.rs index a400218ca29..651bfe22ff7 100644 --- a/token-lending/program/tests/refresh_reserve.rs +++ b/token-lending/program/tests/refresh_reserve.rs @@ -93,12 +93,14 @@ async fn test_success() { refresh_reserve( spl_token_lending::id(), usdc_test_reserve.pubkey, - usdc_oracle.price_pubkey, + usdc_oracle.pyth_price_pubkey, + usdc_oracle.switchboard_feed_pubkey, ), refresh_reserve( spl_token_lending::id(), sol_test_reserve.pubkey, - sol_oracle.price_pubkey, + sol_oracle.pyth_price_pubkey, + sol_oracle.switchboard_feed_pubkey, ), ], Some(&payer.pubkey()),