Skip to content

Commit 4a8adcb

Browse files
committed
add vaults for seer tests only
1 parent 7f4b437 commit 4a8adcb

File tree

4 files changed

+196
-66
lines changed

4 files changed

+196
-66
lines changed

src/tests/purger/utils.cairo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod purger_utils {
1111
use opus::interfaces::IGate::{IGateDispatcher, IGateDispatcherTrait};
1212
use opus::interfaces::IOracle::{IOracleDispatcher, IOracleDispatcherTrait};
1313
use opus::interfaces::IPurger::{IPurgerDispatcher, IPurgerDispatcherTrait};
14-
use opus::interfaces::ISeer::{ISeerDispatcher, ISeerDispatcherTrait};
14+
use opus::interfaces::ISeer::{ISeerV2Dispatcher, ISeerV2DispatcherTrait};
1515
use opus::interfaces::IShrine::{IShrineDispatcher, IShrineDispatcherTrait};
1616
use opus::mock::flash_liquidator::{flash_liquidator, IFlashLiquidatorDispatcher, IFlashLiquidatorDispatcherTrait};
1717
use opus::mock::mock_pragma::{IMockPragmaDispatcher, IMockPragmaDispatcherTrait};
@@ -327,7 +327,7 @@ pub mod purger_utils {
327327
) -> (
328328
IShrineDispatcher,
329329
IAbbotDispatcher,
330-
ISeerDispatcher,
330+
ISeerV2Dispatcher,
331331
IAbsorberDispatcher,
332332
IPurgerDispatcher,
333333
Span<ContractAddress>,
@@ -405,7 +405,7 @@ pub mod purger_utils {
405405
) -> (
406406
IShrineDispatcher,
407407
IAbbotDispatcher,
408-
ISeerDispatcher,
408+
ISeerV2Dispatcher,
409409
IAbsorberDispatcher,
410410
IPurgerDispatcher,
411411
Span<ContractAddress>,
@@ -493,7 +493,7 @@ pub mod purger_utils {
493493

494494
// Helper function to decrease yang prices by the given percentage
495495
pub fn decrease_yang_prices_by_pct(
496-
shrine: IShrineDispatcher, seer: ISeerDispatcher, mut yangs: Span<ContractAddress>, pct_decrease: Ray,
496+
shrine: IShrineDispatcher, seer: ISeerV2Dispatcher, mut yangs: Span<ContractAddress>, pct_decrease: Ray,
497497
) {
498498
start_prank(CheatTarget::One(shrine.contract_address), shrine_utils::admin());
499499
loop {
@@ -514,7 +514,7 @@ pub mod purger_utils {
514514
// yang prices
515515
pub fn lower_prices_to_raise_trove_ltv(
516516
shrine: IShrineDispatcher,
517-
seer: ISeerDispatcher,
517+
seer: ISeerV2Dispatcher,
518518
yangs: Span<ContractAddress>,
519519
value: Wad,
520520
debt: Wad,
@@ -528,7 +528,7 @@ pub mod purger_utils {
528528

529529
pub fn trigger_recovery_mode(
530530
shrine: IShrineDispatcher,
531-
seer: ISeerDispatcher,
531+
seer: ISeerV2Dispatcher,
532532
yangs: Span<ContractAddress>,
533533
rm_setup_type: common::RecoveryModeSetupType
534534
) {

src/tests/seer/test_seer.cairo

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,21 @@ mod test_seer {
140140

141141
#[test]
142142
fn test_toggle_yang_price_conversion() {
143+
let gate_class = declare("gate").unwrap();
143144
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
144-
Option::None, Option::None, Option::None, Option::None, Option::None
145+
Option::None, Option::None, Option::Some(gate_class), Option::None
145146
);
147+
let eth_addr: ContractAddress = *yangs.at(0);
148+
let wbtc_addr: ContractAddress = *yangs.at(1);
149+
150+
let (vaults, _vault_gates) = sentinel_utils::add_vaults_to_sentinel(
151+
shrine, sentinel, gate_class, Option::None, eth_addr, wbtc_addr
152+
);
153+
146154
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
147-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
155+
Option::None, shrine.contract_address, sentinel.contract_address
148156
);
157+
seer_utils::toggle_vaults_in_seer(seer, vaults);
149158

150159
let mut spy = spy_events(SpyOn::One(seer.contract_address));
151160

@@ -155,7 +164,7 @@ mod test_seer {
155164
pragma_utils::add_yangs_v2(*oracles.at(0), yangs);
156165

157166
let eth = *yangs.at(0);
158-
let eth_vault = *yangs.at(2);
167+
let eth_vault = *vaults.at(0);
159168
let conversion_rate_info = ConversionRateInfo { asset: eth, conversion_rate_scale: 1_u128 };
160169

161170
assert(
@@ -204,24 +213,6 @@ mod test_seer {
204213
seer.toggle_yang_price_conversion(seer_utils::dummy_eth());
205214
}
206215

207-
// This is commented out because we are unable to catch the exception of an entry point selector that
208-
// cannot be found.
209-
// #[test]
210-
// #[should_panic]
211-
// fn test_toggle_yang_not_vault_asset() {
212-
// let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
213-
// Option::None, Option::None, Option::None, Option::None, Option::None
214-
// );
215-
// let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
216-
// Option::None, shrine.contract_address, sentinel.contract_address, yangs
217-
// );
218-
219-
// let eth = *yangs.at(0);
220-
221-
// start_prank(CheatTarget::One(seer.contract_address), seer_utils::admin());
222-
// seer.toggle_yang_price_conversion(eth);
223-
// }
224-
225216
#[test]
226217
#[should_panic(expected: ('SEER: Zero conversion rate',))]
227218
fn test_toggle_yang_zero_conversion_rate() {
@@ -276,12 +267,21 @@ mod test_seer {
276267

277268
#[test]
278269
fn test_update_prices_successful() {
270+
let gate_class = declare("gate").unwrap();
279271
let (sentinel, shrine, yangs, gates) = sentinel_utils::deploy_sentinel_with_gates(
280-
Option::None, Option::None, Option::None, Option::None, Option::None
272+
Option::None, Option::None, Option::Some(gate_class), Option::None
273+
);
274+
let eth_addr: ContractAddress = *yangs.at(0);
275+
let wbtc_addr: ContractAddress = *yangs.at(1);
276+
277+
let (vaults, vault_gates) = sentinel_utils::add_vaults_to_sentinel(
278+
shrine, sentinel, gate_class, Option::None, eth_addr, wbtc_addr
281279
);
280+
282281
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
283-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
282+
Option::None, shrine.contract_address, sentinel.contract_address
284283
);
284+
seer_utils::toggle_vaults_in_seer(seer, vaults);
285285

286286
let mut spy = spy_events(SpyOn::One(seer.contract_address));
287287

@@ -293,14 +293,12 @@ mod test_seer {
293293
let mut eth_price: Wad = seer_utils::ETH_INIT_PRICE.into();
294294
let mut wbtc_price: Wad = seer_utils::WBTC_INIT_PRICE.into();
295295

296-
let eth_addr: ContractAddress = *yangs.at(0);
297-
let wbtc_addr: ContractAddress = *yangs.at(1);
298-
let eth_vault_addr: ContractAddress = *yangs.at(2);
299-
let wbtc_vault_addr: ContractAddress = *yangs.at(3);
296+
let eth_vault_addr: ContractAddress = *vaults.at(0);
297+
let wbtc_vault_addr: ContractAddress = *vaults.at(1);
300298
let eth_gate: IGateDispatcher = *gates.at(0);
301299
let wbtc_gate: IGateDispatcher = *gates.at(1);
302-
let eth_vault_gate: IGateDispatcher = *gates.at(2);
303-
let wbtc_vault_gate: IGateDispatcher = *gates.at(3);
300+
let eth_vault_gate: IGateDispatcher = *vault_gates.at(0);
301+
let wbtc_vault_gate: IGateDispatcher = *vault_gates.at(1);
304302
let pragma: ContractAddress = *(oracles[0]);
305303
let switchboard: ContractAddress = *(oracles[1]);
306304

@@ -350,19 +348,19 @@ mod test_seer {
350348
let expected_missing_seer = array![
351349
(
352350
seer.contract_address,
353-
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: *yangs[0] })
351+
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: eth_addr })
354352
),
355353
(
356354
seer.contract_address,
357-
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: *yangs[1] })
355+
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: wbtc_addr })
358356
),
359357
(
360358
seer.contract_address,
361-
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: *yangs[2] })
359+
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: eth_vault_addr })
362360
),
363361
(
364362
seer.contract_address,
365-
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: *yangs[3] })
363+
seer_contract::Event::PriceUpdateMissed(seer_contract::PriceUpdateMissed { yang: wbtc_vault_addr })
366364
),
367365
(
368366
seer.contract_address,
@@ -491,13 +489,21 @@ mod test_seer {
491489

492490
#[test]
493491
fn test_update_prices_from_fallback_oracle_successful() {
492+
let gate_class = declare("gate").unwrap();
494493
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
495-
Option::None, Option::None, Option::None, Option::None, Option::None
494+
Option::None, Option::None, Option::Some(gate_class), Option::None
495+
);
496+
let eth_addr: ContractAddress = *yangs[0];
497+
let wbtc_addr: ContractAddress = *yangs[1];
498+
499+
let (vaults, _vault_gates) = sentinel_utils::add_vaults_to_sentinel(
500+
shrine, sentinel, gate_class, Option::None, eth_addr, wbtc_addr
496501
);
497502

498503
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
499-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
504+
Option::None, shrine.contract_address, sentinel.contract_address
500505
);
506+
seer_utils::toggle_vaults_in_seer(seer, vaults);
501507

502508
let oracles: Span<ContractAddress> = seer_utils::add_oracles(
503509
seer, Option::None, Option::None, Option::None, Option::None
@@ -507,7 +513,6 @@ mod test_seer {
507513

508514
// mock an ETH price update of spot Pragma that will fail due to too few sources,
509515
// causing Seer to use Switchboard
510-
let eth_addr: ContractAddress = *yangs[0];
511516
let eth_price: Wad = seer_utils::ETH_INIT_PRICE.into();
512517
let pragma = IOracleDispatcher { contract_address: *oracles[0] };
513518
let mock_pragma = IMockPragmaDispatcher { contract_address: *pragma.get_oracles().at(0) };
@@ -533,7 +538,6 @@ mod test_seer {
533538

534539
let pragma: ContractAddress = *oracles.at(0);
535540
let switchboard: ContractAddress = *oracles.at(1);
536-
let wbtc_addr: ContractAddress = *yangs[1];
537541
// asserting that PriceUpdate event for ETH coming from Switchboard,
538542
// but for WBTC coming from Pragma
539543
let expected_events_seer = array![
@@ -558,12 +562,21 @@ mod test_seer {
558562

559563
#[test]
560564
fn test_update_prices_via_execute_task_successful() {
565+
let gate_class = declare("gate").unwrap();
561566
let (sentinel, shrine, yangs, _) = sentinel_utils::deploy_sentinel_with_gates(
562-
Option::None, Option::None, Option::None, Option::None, Option::None
567+
Option::None, Option::None, Option::Some(gate_class), Option::None
568+
);
569+
let eth_addr: ContractAddress = *yangs.at(0);
570+
let wbtc_addr: ContractAddress = *yangs.at(1);
571+
572+
let (vaults, _vault_gates) = sentinel_utils::add_vaults_to_sentinel(
573+
shrine, sentinel, gate_class, Option::None, eth_addr, wbtc_addr
563574
);
575+
564576
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
565-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
577+
Option::None, shrine.contract_address, sentinel.contract_address
566578
);
579+
seer_utils::toggle_vaults_in_seer(seer, vaults);
567580

568581
let mut spy = spy_events(SpyOn::One(seer.contract_address));
569582

@@ -619,11 +632,11 @@ mod test_seer {
619632
#[test]
620633
#[should_panic(expected: ('PGM: Unknown yang',))]
621634
fn test_update_prices_fails_with_no_yangs_in_seer() {
622-
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
623-
Option::None, Option::None, Option::None, Option::None, Option::None
635+
let (sentinel, shrine, _yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
636+
Option::None, Option::None, Option::None, Option::None
624637
);
625638
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
626-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
639+
Option::None, shrine.contract_address, sentinel.contract_address
627640
);
628641
seer_utils::add_oracles(seer, Option::None, Option::None, Option::None, Option::None);
629642
start_prank(CheatTarget::One(seer.contract_address), seer_utils::admin());
@@ -634,11 +647,11 @@ mod test_seer {
634647
#[should_panic]
635648
fn test_update_prices_fails_with_wrong_yang_in_seer() {
636649
let token_class = Option::Some(declare("erc20_mintable").unwrap());
637-
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
638-
Option::None, token_class, Option::None, Option::None, Option::None
650+
let (sentinel, shrine, _yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
651+
Option::None, token_class, Option::None, Option::None
639652
);
640653
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
641-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
654+
Option::None, shrine.contract_address, sentinel.contract_address
642655
);
643656
let oracles: Span<ContractAddress> = seer_utils::add_oracles(
644657
seer, Option::None, Option::None, Option::None, Option::None
@@ -663,10 +676,10 @@ mod test_seer {
663676
#[test]
664677
fn test_update_prices_missed_updates() {
665678
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
666-
Option::None, Option::None, Option::None, Option::None, Option::None
679+
Option::None, Option::None, Option::None, Option::None
667680
);
668681
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
669-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
682+
Option::None, shrine.contract_address, sentinel.contract_address
670683
);
671684

672685
let mut spy = spy_events(SpyOn::One(seer.contract_address));
@@ -730,12 +743,22 @@ mod test_seer {
730743

731744
#[test]
732745
fn test_probe_task() {
746+
let gate_class = declare("gate").unwrap();
733747
let (sentinel, shrine, yangs, _gates) = sentinel_utils::deploy_sentinel_with_gates(
734-
Option::None, Option::None, Option::None, Option::None, Option::None
748+
Option::None, Option::None, Option::Some(gate_class), Option::None
749+
);
750+
let eth_addr: ContractAddress = *yangs.at(0);
751+
let wbtc_addr: ContractAddress = *yangs.at(1);
752+
753+
let (vaults, _vault_gates) = sentinel_utils::add_vaults_to_sentinel(
754+
shrine, sentinel, gate_class, Option::None, eth_addr, wbtc_addr
735755
);
756+
736757
let seer: ISeerV2Dispatcher = seer_utils::deploy_seer_using(
737-
Option::None, shrine.contract_address, sentinel.contract_address, yangs
758+
Option::None, shrine.contract_address, sentinel.contract_address
738759
);
760+
seer_utils::toggle_vaults_in_seer(seer, vaults);
761+
739762
let oracles: Span<ContractAddress> = seer_utils::add_oracles(
740763
seer, Option::None, Option::None, Option::None, Option::None
741764
);

src/tests/seer/utils.cairo

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ pub mod seer_utils {
7070
}
7171

7272
pub fn deploy_seer_using(
73-
seer_class: Option<ContractClass>,
74-
shrine: ContractAddress,
75-
sentinel: ContractAddress,
76-
yangs: Span<ContractAddress>
73+
seer_class: Option<ContractClass>, shrine: ContractAddress, sentinel: ContractAddress,
7774
) -> ISeerV2Dispatcher {
7875
let mut calldata: Array<felt252> = array![
7976
admin().into(), shrine.into(), sentinel.into(), UPDATE_FREQUENCY.into()
@@ -92,14 +89,18 @@ pub mod seer_utils {
9289
shrine_ac.grant_role(shrine_roles::seer(), seer_addr);
9390
stop_prank(CheatTarget::One(shrine));
9491

95-
let seer = ISeerV2Dispatcher { contract_address: seer_addr };
96-
97-
start_prank(CheatTarget::One(seer_addr), admin());
98-
seer.toggle_yang_price_conversion(*yangs.at(2));
99-
seer.toggle_yang_price_conversion(*yangs.at(3));
100-
stop_prank(CheatTarget::One(seer_addr));
92+
ISeerV2Dispatcher { contract_address: seer_addr }
93+
}
10194

102-
seer
95+
pub fn toggle_vaults_in_seer(seer: ISeerV2Dispatcher, mut vaults: Span<ContractAddress>) {
96+
start_prank(CheatTarget::One(seer.contract_address), admin());
97+
loop {
98+
match vaults.pop_front() {
99+
Option::Some(vault) => { seer.toggle_yang_price_conversion(*vault); },
100+
Option::None => { break; },
101+
};
102+
};
103+
stop_prank(CheatTarget::One(seer.contract_address));
103104
}
104105

105106
pub fn add_oracles(

0 commit comments

Comments
 (0)