From 13ad3e9ea1bc9eb712411525055f97ae67ba5049 Mon Sep 17 00:00:00 2001 From: Mokhtar Naamani Date: Tue, 9 Jan 2024 10:06:48 +0400 Subject: [PATCH] project-token: activate/deactive amm disabled when pallet frozen added tests and adjusted the weights for affected dispatch calls --- .../src/tests/creator_tokens/activate_amm.rs | 14 ++++++++++++++ .../src/tests/creator_tokens/deactivate_amm.rs | 15 +++++++++++++++ runtime-modules/content/src/weights.rs | 6 ++++-- runtime-modules/project-token/src/lib.rs | 4 ++++ runtime-modules/project-token/src/weights.rs | 9 ++++++--- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/runtime-modules/content/src/tests/creator_tokens/activate_amm.rs b/runtime-modules/content/src/tests/creator_tokens/activate_amm.rs index 23c1fe3d4b..5fcbe324ab 100644 --- a/runtime-modules/content/src/tests/creator_tokens/activate_amm.rs +++ b/runtime-modules/content/src/tests/creator_tokens/activate_amm.rs @@ -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() { @@ -155,3 +158,14 @@ fn unsuccessful_activate_member_channel_creator_token_amm_with_ongoing_transfer( .call_and_assert(Err(Error::::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::::PalletFrozen.into())); + }) +} diff --git a/runtime-modules/content/src/tests/creator_tokens/deactivate_amm.rs b/runtime-modules/content/src/tests/creator_tokens/deactivate_amm.rs index 57eb9954f4..f7f5b352a1 100644 --- a/runtime-modules/content/src/tests/creator_tokens/deactivate_amm.rs +++ b/runtime-modules/content/src/tests/creator_tokens/deactivate_amm.rs @@ -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() { @@ -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::::PalletFrozen.into())); + }) +} diff --git a/runtime-modules/content/src/weights.rs b/runtime-modules/content/src/weights.rs index ec644ffb54..96020124b9 100644 --- a/runtime-modules/content/src/weights.rs +++ b/runtime-modules/content/src/weights.rs @@ -1310,6 +1310,7 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -1321,7 +1322,7 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -1332,6 +1333,7 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -1343,7 +1345,7 @@ impl WeightInfo for SubstrateWeight { // 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) diff --git a/runtime-modules/project-token/src/lib.rs b/runtime-modules/project-token/src/lib.rs index 5fba7a5ab3..0cf4af9906 100644 --- a/runtime-modules/project-token/src/lib.rs +++ b/runtime-modules/project-token/src/lib.rs @@ -1581,6 +1581,8 @@ impl member_id: T::MemberId, params: AmmParamsOf, ) -> DispatchResult { + Self::ensure_unfrozen_state()?; + let token_data = Self::ensure_token_exists(token_id)?; ensure!( @@ -1624,6 +1626,8 @@ impl /// - 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)?; diff --git a/runtime-modules/project-token/src/weights.rs b/runtime-modules/project-token/src/weights.rs index 3c0981dd0c..1cfdcd86b5 100644 --- a/runtime-modules/project-token/src/weights.rs +++ b/runtime-modules/project-token/src/weights.rs @@ -227,6 +227,7 @@ impl WeightInfo for SubstrateWeight { .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) @@ -246,9 +247,10 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -268,9 +270,10 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -288,7 +291,7 @@ impl WeightInfo for SubstrateWeight { // 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)) } }