Skip to content

Commit

Permalink
project-token: activate/deactive amm disabled when pallet frozen
Browse files Browse the repository at this point in the history
added tests and adjusted the weights for affected dispatch calls
  • Loading branch information
mnaamani committed Jan 9, 2024
1 parent d707c68 commit 13ad3e9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
14 changes: 14 additions & 0 deletions runtime-modules/content/src/tests/creator_tokens/activate_amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
use crate::tests::fixtures::*;
use crate::tests::mock::*;
use crate::*;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use project_token::Error as ProjectTokenError;

#[test]
fn unsuccessful_activate_amm_non_existing_channel() {
Expand Down Expand Up @@ -155,3 +158,14 @@ fn unsuccessful_activate_member_channel_creator_token_amm_with_ongoing_transfer(
.call_and_assert(Err(Error::<Test>::InvalidChannelTransferStatus.into()));
})
}

#[test]
fn unsuccessful_activate_creator_token_amm_with_frozen_pallet() {
with_default_mock_builder(|| {
ContentTest::with_member_channel().setup();
IssueCreatorTokenFixture::default().call_and_assert(Ok(()));
assert_ok!(Token::set_frozen_status(RawOrigin::Root.into(), true));
ActivateAmmFixture::default()
.call_and_assert(Err(ProjectTokenError::<Test>::PalletFrozen.into()));
})
}
15 changes: 15 additions & 0 deletions runtime-modules/content/src/tests/creator_tokens/deactivate_amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
use crate::tests::fixtures::*;
use crate::tests::mock::*;
use crate::*;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use project_token::Error as ProjectTokenError;

#[test]
fn unsuccessful_deactivate_amm_non_existing_channel() {
Expand Down Expand Up @@ -135,3 +138,15 @@ fn successful_deactivate_curator_channel_creator_token_amm_by_lead() {
.call_and_assert(Ok(()));
})
}

#[test]
fn unsuccessful_deactivate_creator_token_amm_with_frozen_pallet() {
with_default_mock_builder(|| {
ContentTest::with_member_channel().setup();
IssueCreatorTokenFixture::default().call_and_assert(Ok(()));
ActivateAmmFixture::default().call_and_assert(Ok(()));
assert_ok!(Token::set_frozen_status(RawOrigin::Root.into(), true));
DeactivateAmmFixture::default()
.call_and_assert(Err(ProjectTokenError::<Test>::PalletFrozen.into()));
})
}
6 changes: 4 additions & 2 deletions runtime-modules/content/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof: Content CuratorGroupById (max_values: None, max_size: Some(1037), added: 3512, mode: MaxEncodedLen)
// Storage: Token TokenInfoById (r:1 w:1)
// Proof: Token TokenInfoById (max_values: None, max_size: Some(352), added: 2827, mode: MaxEncodedLen)
// Storage: Token PalletFrozen (r:1 w:0)
// Storage: Token MinAmmSlopeParameter (r:1 w:0)
// Proof: Token MinAmmSlopeParameter (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen)
// Storage: System Account (r:1 w:1)
Expand All @@ -1321,7 +1322,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 188_296 nanoseconds.
Weight::from_parts(192_189_000, 0u64)
.saturating_add(Weight::from_parts(0, 21427))
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
// Storage: Content ChannelById (r:1 w:0)
Expand All @@ -1332,6 +1333,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof: Content CuratorGroupById (max_values: None, max_size: Some(1037), added: 3512, mode: MaxEncodedLen)
// Storage: Token TokenInfoById (r:1 w:1)
// Proof: Token TokenInfoById (max_values: None, max_size: Some(352), added: 2827, mode: MaxEncodedLen)
// Storage: Token PalletFrozen (r:1 w:0)
// Storage: Token AmmDeactivationThreshold (r:1 w:0)
// Proof: Token AmmDeactivationThreshold (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
// Storage: System Account (r:1 w:0)
Expand All @@ -1343,7 +1345,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 164_519 nanoseconds.
Weight::from_parts(166_906_000, 0u64)
.saturating_add(Weight::from_parts(0, 21415))
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: Content ChannelById (r:1 w:0)
Expand Down
4 changes: 4 additions & 0 deletions runtime-modules/project-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,8 @@ impl<T: Config>
member_id: T::MemberId,
params: AmmParamsOf<T>,
) -> DispatchResult {
Self::ensure_unfrozen_state()?;

let token_data = Self::ensure_token_exists(token_id)?;

ensure!(
Expand Down Expand Up @@ -1624,6 +1626,8 @@ impl<T: Config>
/// - state set to idle
/// - event deposited
fn deactivate_amm(token_id: T::TokenId, member_id: T::MemberId) -> DispatchResult {
Self::ensure_unfrozen_state()?;

let token_data = Self::ensure_token_exists(token_id)?;
Self::ensure_amm_can_be_deactivated(&token_data)?;

Expand Down
9 changes: 6 additions & 3 deletions runtime-modules/project-token/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
// Storage: Token PalletFrozen (r:1 w:0)
// Storage: Membership MembershipById (r:1 w:0)
// Proof: Membership MembershipById (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen)
// Storage: Token TokenInfoById (r:1 w:1)
Expand All @@ -246,9 +247,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 85_398 nanoseconds.
Weight::from_parts(87_934_000, 0u64)
.saturating_add(Weight::from_parts(0, 20547))
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
// Storage: Token PalletFrozen (r:1 w:0)
// Storage: Membership MembershipById (r:1 w:0)
// Proof: Membership MembershipById (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen)
// Storage: Token TokenInfoById (r:1 w:1)
Expand All @@ -268,9 +270,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 86_178 nanoseconds.
Weight::from_parts(88_253_000, 0u64)
.saturating_add(Weight::from_parts(0, 20547))
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
// Storage: Token PalletFrozen (r:1 w:0)
// Storage: Membership MembershipById (r:1 w:0)
// Proof: Membership MembershipById (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen)
// Storage: Token TokenInfoById (r:1 w:1)
Expand All @@ -288,7 +291,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 73_200 nanoseconds.
Weight::from_parts(75_404_000, 0u64)
.saturating_add(Weight::from_parts(0, 19046))
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
}
Expand Down

0 comments on commit 13ad3e9

Please sign in to comment.