diff --git a/pool/src/pool/pool.rs b/pool/src/pool/pool.rs index 007242bf..e1e5e729 100644 --- a/pool/src/pool/pool.rs +++ b/pool/src/pool/pool.rs @@ -267,7 +267,7 @@ mod tests { let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, - status: 1, + status: 3, }; e.as_contract(&pool, || { storage::set_pool_config(&e, &pool_config); @@ -296,6 +296,45 @@ mod tests { }); } + #[test] + #[should_panic(expected = "Error(Contract, #11)")] + fn test_require_action_allowed_cancel_liquidation_while_on_ice_panics() { + let e = Env::default(); + + let pool = testutils::create_pool(&e); + let oracle = Address::random(&e); + let pool_config = PoolConfig { + oracle, + bstop_rate: 0_200_000_000, + status: 3, + }; + e.as_contract(&pool, || { + storage::set_pool_config(&e, &pool_config); + let pool = Pool::load(&e); + + pool.require_action_allowed(&e, 9); + }); + } + + #[test] + fn test_require_action_allowed_cancel_liquidation_while_active() { + let e = Env::default(); + + let pool = testutils::create_pool(&e); + let oracle = Address::random(&e); + let pool_config = PoolConfig { + oracle, + bstop_rate: 0_200_000_000, + status: 0, + }; + e.as_contract(&pool, || { + storage::set_pool_config(&e, &pool_config); + let pool = Pool::load(&e); + + pool.require_action_allowed(&e, 9); + }); + } + #[test] #[should_panic(expected = "Error(Contract, #11)")] fn test_require_action_allowed_supply_while_frozen() { @@ -306,7 +345,7 @@ mod tests { let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, - status: 2, + status: 5, }; e.as_contract(&pool, || { storage::set_pool_config(&e, &pool_config); @@ -326,7 +365,7 @@ mod tests { let pool_config = PoolConfig { oracle, bstop_rate: 0_200_000_000, - status: 2, + status: 5, }; e.as_contract(&pool, || { storage::set_pool_config(&e, &pool_config); diff --git a/pool/src/pool/status.rs b/pool/src/pool/status.rs index 35376860..cfc5e447 100644 --- a/pool/src/pool/status.rs +++ b/pool/src/pool/status.rs @@ -219,7 +219,7 @@ mod tests { let new_pool_config = storage::get_pool_config(&e); assert_eq!(new_pool_config.status, status); - assert_eq!(status, 0); + assert_eq!(status, 1); }); } @@ -266,7 +266,7 @@ mod tests { let new_pool_config = storage::get_pool_config(&e); assert_eq!(new_pool_config.status, status); - assert_eq!(status, 1); + assert_eq!(status, 3); }); } @@ -304,7 +304,7 @@ mod tests { let pool_config = PoolConfig { oracle: oracle_id, bstop_rate: 0, - status: 0, + status: 1, }; e.as_contract(&pool_id, || { storage::set_admin(&e, &bombadil); @@ -314,7 +314,7 @@ mod tests { let new_pool_config = storage::get_pool_config(&e); assert_eq!(new_pool_config.status, status); - assert_eq!(status, 1); + assert_eq!(status, 3); }); } @@ -352,7 +352,7 @@ mod tests { let pool_config = PoolConfig { oracle: oracle_id, bstop_rate: 0, - status: 0, + status: 1, }; e.as_contract(&pool_id, || { storage::set_admin(&e, &bombadil); @@ -362,16 +362,16 @@ mod tests { let new_pool_config = storage::get_pool_config(&e); assert_eq!(new_pool_config.status, status); - assert_eq!(status, 2); + assert_eq!(status, 5); }); } #[test] - #[should_panic(expected = "Error(Contract, #11)")] + #[should_panic(expected = "Error(Auth, InvalidAction)")] fn test_update_pool_status_admin_frozen() { let e = Env::default(); e.budget().reset_unlimited(); - e.mock_all_auths_allowing_non_root_auth(); + // e.mock_all_auths_allowing_non_root_auth(); let pool_id = create_pool(&e); let oracle_id = Address::random(&e); @@ -400,7 +400,7 @@ mod tests { let pool_config = PoolConfig { oracle: oracle_id, bstop_rate: 0, - status: 3, + status: 4, }; e.as_contract(&pool_id, || { storage::set_admin(&e, &bombadil); @@ -410,6 +410,102 @@ mod tests { }); } + #[test] + fn test_admin_update_pool_status_unfreeze() { + let e = Env::default(); + e.budget().reset_unlimited(); + e.mock_all_auths_allowing_non_root_auth(); + + let pool_id = create_pool(&e); + let oracle_id = Address::random(&e); + + let bombadil = Address::random(&e); + let samwise = Address::random(&e); + + let (blnd, blnd_client) = create_token_contract(&e, &bombadil); + let (usdc, usdc_client) = create_token_contract(&e, &bombadil); + let (lp_token, lp_token_client) = create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); + let (backstop_id, backstop_client) = create_backstop(&e); + setup_backstop(&e, &pool_id, &backstop_id, &lp_token, &usdc, &blnd); + + // mint lp tokens + blnd_client.mint(&samwise, &500_001_0000000); + blnd_client.approve(&samwise, &lp_token, &i128::MAX, &99999); + usdc_client.mint(&samwise, &12_501_0000000); + usdc_client.approve(&samwise, &lp_token, &i128::MAX, &99999); + lp_token_client.join_pool( + &50_000_0000000, + &vec![&e, 500_001_0000000, 12_501_0000000], + &samwise, + ); + backstop_client.deposit(&samwise, &pool_id, &50_000_0000000); + backstop_client.update_tkn_val(); + backstop_client.queue_withdrawal(&samwise, &pool_id, &25_000_0000000); + + let pool_config = PoolConfig { + oracle: oracle_id, + bstop_rate: 0, + status: 5, + }; + e.as_contract(&pool_id, || { + storage::set_admin(&e, &bombadil); + storage::set_pool_config(&e, &pool_config); + + let status = execute_update_pool_status(&e, 0); + + let new_pool_config = storage::get_pool_config(&e); + assert_eq!(new_pool_config.status, status); + assert_eq!(status, 0); + }); + } + + #[test] + fn test_admin_update_pool_status_freeze() { + let e = Env::default(); + e.budget().reset_unlimited(); + e.mock_all_auths_allowing_non_root_auth(); + let pool_id = create_pool(&e); + let oracle_id = Address::random(&e); + + let bombadil = Address::random(&e); + let samwise = Address::random(&e); + + let (blnd, blnd_client) = create_token_contract(&e, &bombadil); + let (usdc, usdc_client) = create_token_contract(&e, &bombadil); + let (lp_token, lp_token_client) = create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); + let (backstop_id, backstop_client) = create_backstop(&e); + setup_backstop(&e, &pool_id, &backstop_id, &lp_token, &usdc, &blnd); + + // mint lp tokens + blnd_client.mint(&samwise, &500_001_0000000); + blnd_client.approve(&samwise, &lp_token, &i128::MAX, &99999); + usdc_client.mint(&samwise, &12_501_0000000); + usdc_client.approve(&samwise, &lp_token, &i128::MAX, &99999); + lp_token_client.join_pool( + &50_000_0000000, + &vec![&e, 500_001_0000000, 12_501_0000000], + &samwise, + ); + backstop_client.deposit(&samwise, &pool_id, &50_000_0000000); + backstop_client.update_tkn_val(); + + let pool_config = PoolConfig { + oracle: oracle_id, + bstop_rate: 0, + status: 1, + }; + e.as_contract(&pool_id, || { + storage::set_admin(&e, &bombadil); + storage::set_pool_config(&e, &pool_config); + + let status = execute_update_pool_status(&e, 4); + + let new_pool_config = storage::get_pool_config(&e); + assert_eq!(new_pool_config.status, status); + assert_eq!(status, 4); + }); + } + #[test] fn test_calc_pool_backstop_threshold() { let e = Env::default(); diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 4a3ec7d2..39d97065 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -717,7 +717,7 @@ fn test_pool_config() { ); // Set status (admin only) - pool_fixture.pool.set_status(&1); + pool_fixture.pool.set_status(&2); assert_eq!( fixture.env.auths()[0], ( @@ -726,14 +726,14 @@ fn test_pool_config() { function: AuthorizedFunction::Contract(( pool_fixture.pool.address.clone(), Symbol::new(&fixture.env, "set_status"), - vec![&fixture.env, 1u32.into_val(&fixture.env)] + vec![&fixture.env, 2u32.into_val(&fixture.env)] )), sub_invocations: std::vec![] } ) ); let new_pool_config = fixture.read_pool_config(0); - assert_eq!(new_pool_config.status, 1); + assert_eq!(new_pool_config.status, 2); let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, @@ -742,7 +742,37 @@ fn test_pool_config() { ( pool_fixture.pool.address.clone(), (Symbol::new(&fixture.env, "set_status"), new_admin.clone()).into_val(&fixture.env), - 1u32.into_val(&fixture.env) + 2u32.into_val(&fixture.env) + ) + ] + ); + //revert to standard status (admin only) + pool_fixture.pool.set_status(&3); + assert_eq!( + fixture.env.auths()[0], + ( + new_admin.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + pool_fixture.pool.address.clone(), + Symbol::new(&fixture.env, "set_status"), + vec![&fixture.env, 3u32.into_val(&fixture.env)] + )), + sub_invocations: std::vec![] + } + ) + ); + let new_pool_config = fixture.read_pool_config(0); + assert_eq!(new_pool_config.status, 3); + let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + assert_eq!( + event, + vec![ + &fixture.env, + ( + pool_fixture.pool.address.clone(), + (Symbol::new(&fixture.env, "set_status"), new_admin.clone()).into_val(&fixture.env), + 3u32.into_val(&fixture.env) ) ] ); @@ -751,7 +781,7 @@ fn test_pool_config() { pool_fixture.pool.update_status(); assert_eq!(fixture.env.auths().len(), 0); let new_pool_config = fixture.read_pool_config(0); - assert_eq!(new_pool_config.status, 0); + assert_eq!(new_pool_config.status, 1); let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, @@ -760,7 +790,7 @@ fn test_pool_config() { ( pool_fixture.pool.address.clone(), (Symbol::new(&fixture.env, "set_status"),).into_val(&fixture.env), - 0u32.into_val(&fixture.env) + 1u32.into_val(&fixture.env) ) ] );