Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 141 additions & 95 deletions controller/program/tests/tests/admin/add_lst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,31 @@ fn add_lst_proptest(
Ok(())
}

fn add_lst_correct_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32])> {
(any_normal_pk(), any_normal_pk()).prop_flat_map(|(payer, mint)| {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
})
.prop_filter("admin cannot be system program", |pool| {
pool.admin != SYS_PROG_ID
}),
any_lst_state_list(Default::default(), None, 0..=0)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
})
}

proptest! {
#[test]
fn add_lst_any(
(pool, lsl, payer, mint) in
(any_normal_pk(), any_normal_pk())
.prop_flat_map(|(payer, mint)| {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}).prop_filter("admin cannot be system program", |pool| pool.admin != SYS_PROG_ID),
any_lst_state_list(Default::default(), None, 0..=0)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
}),
(pool, lsl, payer, mint) in add_lst_correct_strat(),
) {
add_lst_proptest(
pool,
Expand All @@ -371,26 +377,34 @@ proptest! {
}
}

fn add_lst_unauthorized_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32], [u8; 32])> {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}),
any_normal_pk(),
any_normal_pk(),
)
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
any_normal_pk().prop_filter("cannot be eq admin", move |x| *x != pool.admin),
Just(mint),
)
})
}

proptest! {
#[test]
fn add_lst_unauthorized_any(
(pool, lsl, payer, non_admin, mint) in
(any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}), any_normal_pk(), any_normal_pk())
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
any_normal_pk().prop_filter("cannot be eq admin", move |x| *x != pool.admin),
Just(mint),
)
}),
(pool, lsl, payer, non_admin, mint) in add_lst_unauthorized_strat(),
) {
add_lst_proptest(
pool,
Expand All @@ -408,28 +422,40 @@ proptest! {
}
}

fn add_lst_rebalancing_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32])> {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools(
NewPoolStateBoolsBuilder::start()
.with_is_disabled(false)
.with_is_rebalancing(true)
.build()
.0
.map(|x| Some(Just(x).boxed())),
),
..Default::default()
}),
any_normal_pk(),
any_normal_pk(),
)
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
})
}

proptest! {
#[test]
fn add_lst_rebalancing_any(
(pool, lsl, payer, mint) in
(any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools(NewPoolStateBoolsBuilder::start()
.with_is_disabled(false)
.with_is_rebalancing(true)
.build().0.map(|x| Some(Just(x).boxed()))),
..Default::default()
}), any_normal_pk(), any_normal_pk())
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
}),
(pool, lsl, payer, mint) in add_lst_rebalancing_strat(),
) {
add_lst_proptest(
pool,
Expand All @@ -447,28 +473,40 @@ proptest! {
}
}

fn add_lst_disabled_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32])> {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools(
NewPoolStateBoolsBuilder::start()
.with_is_disabled(true)
.with_is_rebalancing(false)
.build()
.0
.map(|x| Some(Just(x).boxed())),
),
..Default::default()
}),
any_normal_pk(),
any_normal_pk(),
)
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
})
}

proptest! {
#[test]
fn add_lst_disabled_any(
(pool, lsl, payer, mint) in
(any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools(NewPoolStateBoolsBuilder::start()
.with_is_disabled(true)
.with_is_rebalancing(false)
.build().0.map(|x| Some(Just(x).boxed()))),
..Default::default()
}), any_normal_pk(), any_normal_pk())
.prop_flat_map(|(pool, payer, mint)| {
(
Just(pool),
any_lst_state_list(Default::default(), None, 0..=MAX_LST_STATES)
.prop_filter("mint must not be in list", move |lsl| {
!lsl.all_pool_reserves.contains_key(&mint)
}),
Just(payer),
Just(mint),
)
}),
(pool, lsl, payer, mint) in add_lst_disabled_strat(),
) {
add_lst_proptest(
pool,
Expand All @@ -486,26 +524,25 @@ proptest! {
}
}

fn add_lst_duplicate_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32])> {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}),
any_lst_state_list(Default::default(), None, 1..=MAX_LST_STATES),
)
.prop_flat_map(|(pool, lsl)| {
let existing_mint = *lsl.all_pool_reserves.keys().next().unwrap();
(Just(pool), Just(lsl), any_normal_pk(), Just(existing_mint))
})
}

proptest! {
#[test]
fn add_lst_duplicate_any(
(pool, lsl, payer, existing_mint) in
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}),
any_lst_state_list(Default::default(), None, 1..=MAX_LST_STATES)
)
.prop_flat_map(|(pool, lsl)| {
let existing_mint = *lsl.all_pool_reserves.keys().next().unwrap();
(
Just(pool),
Just(lsl),
any_normal_pk(),
Just(existing_mint),
)
}),
(pool, lsl, payer, existing_mint) in add_lst_duplicate_strat(),
) {
add_lst_proptest(
pool,
Expand All @@ -523,14 +560,17 @@ proptest! {
}
}

proptest! {
#[test]
fn add_lst_non_exec_svc_any(
(pool, lsl, payer, mint, sol_value_calculator) in
(any_pool_state(AnyPoolStateArgs {
fn add_lst_non_exec_svc_strat(
) -> impl Strategy<Value = (PoolState, LstStateListData, [u8; 32], [u8; 32], [u8; 32])> {
(
any_pool_state(AnyPoolStateArgs {
bools: PoolStateBools::normal(),
..Default::default()
}), any_normal_pk(), any_normal_pk(), any_normal_pk())
}),
any_normal_pk(),
any_normal_pk(),
any_normal_pk(),
)
.prop_flat_map(|(pool, payer, mint, sol_value_calculator)| {
(
Just(pool),
Expand All @@ -542,7 +582,13 @@ proptest! {
Just(mint),
Just(sol_value_calculator),
)
}),
})
}

proptest! {
#[test]
fn add_lst_non_exec_svc_any(
(pool, lsl, payer, mint, sol_value_calculator) in add_lst_non_exec_svc_strat(),
) {
add_lst_proptest(
pool,
Expand Down
Loading