Browse Source

runtime: Upgrade proposals engine pallet - restore tests.

Shamil Gadelshin 4 years ago
parent
commit
3ea6217925

+ 0 - 34
Cargo.lock

@@ -271,17 +271,6 @@ dependencies = [
  "zeroize",
 ]
 
-[[package]]
-name = "derivative"
-version = "2.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
 [[package]]
 name = "derive_more"
 version = "0.99.9"
@@ -975,28 +964,6 @@ dependencies = [
  "libc",
 ]
 
-[[package]]
-name = "num_enum"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca565a7df06f3d4b485494f25ba05da1435950f4dc263440eda7a6fa9b8e36e4"
-dependencies = [
- "derivative",
- "num_enum_derive",
-]
-
-[[package]]
-name = "num_enum_derive"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d"
-dependencies = [
- "proc-macro-crate",
- "proc-macro2",
- "quote",
- "syn",
-]
-
 [[package]]
 name = "once_cell"
 version = "1.4.0"
@@ -1151,7 +1118,6 @@ dependencies = [
  "frame-support",
  "frame-system",
  "mockall",
- "num_enum",
  "pallet-balances",
  "pallet-common",
  "pallet-membership",

+ 0 - 4
runtime-modules/proposals/engine/Cargo.toml

@@ -39,8 +39,4 @@ std = [
     'common/std',
 ]
 
-[dependencies.num_enum]
-default_features = false
-version = "0.4.2"
-
 

+ 8 - 10
runtime-modules/proposals/engine/src/lib.rs

@@ -57,23 +57,25 @@
 //! ## Usage
 //!
 //! ```
-//! use srml_support::{decl_module, dispatch::Result, print};
+//! use frame_support::{decl_module, print};
 //! use system::ensure_signed;
 //! use codec::Encode;
-//! use substrate_proposals_engine_module::{self as engine, ProposalParameters};
+//! use pallet_proposals_engine::{self as engine, ProposalParameters};
 //!
 //! pub trait Trait: engine::Trait + membership::Trait {}
 //!
 //! decl_module! {
 //!     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
+//!         #[weight = 10_000_000]
 //!         fn executable_proposal(origin) {
 //!             print("executed!");
 //!         }
 //!
+//!         #[weight = 10_000_000]
 //!         pub fn create_spending_proposal(
 //!             origin,
 //!             proposer_id: T::MemberId,
-//!         ) -> Result {
+//!         ) {
 //!             let account_id = ensure_signed(origin)?;
 //!             let parameters = ProposalParameters::default();
 //!             let title = b"Spending proposal".to_vec();
@@ -96,7 +98,6 @@
 //!                 None,
 //!                 encoded_proposal_code
 //!             )?;
-//!             Ok(())
 //!         }
 //!     }
 //! }
@@ -127,13 +128,12 @@ pub(crate) mod types;
 mod tests;
 
 use codec::Decode;
-use frame_support::dispatch::{DispatchError, DispatchResult, Dispatchable};
+use frame_support::dispatch::{DispatchError, DispatchResult, UnfilteredDispatchable};
 use frame_support::storage::IterableStorageMap;
 use frame_support::traits::{Currency, Get};
 use frame_support::{
     decl_error, decl_event, decl_module, decl_storage, ensure, print, Parameter, StorageDoubleMap,
 };
-use rstd::prelude::*;
 use sp_arithmetic::traits::Zero;
 use system::{ensure_root, RawOrigin};
 
@@ -181,9 +181,7 @@ pub trait Trait: system::Trait + timestamp::Trait + stake::Trait + membership::T
     type MaxActiveProposalLimit: Get<u32>;
 
     /// Proposals executable code. Can be instantiated by external module Call enum members.
-    type DispatchableCallCode: Parameter
-        + Dispatchable<Origin = Self::Origin, PostInfo = DispatchError>
-        + Default;
+    type DispatchableCallCode: Parameter + UnfilteredDispatchable<Origin = Self::Origin> + Default;
 }
 
 decl_event!(
@@ -649,7 +647,7 @@ impl<T: Trait> Module<T> {
         let approved_proposal_status = match proposal_code_result {
             Ok(proposal_code) => {
                 if let Err(dispatch_error) =
-                    proposal_code.dispatch(T::Origin::from(RawOrigin::Root))
+                    proposal_code.dispatch_bypass_filter(T::Origin::from(RawOrigin::Root))
                 {
                     ApprovedProposalStatus::failed_execution(Self::parse_dispatch_error(
                         dispatch_error.error,

+ 2 - 2
runtime-modules/proposals/engine/src/tests/mock/balance_manager.rs

@@ -1,7 +1,7 @@
 #![cfg(test)]
 
-pub use sr_primitives::traits::Zero;
-use srml_support::traits::{Currency, Imbalance};
+use frame_support::traits::{Currency, Imbalance};
+pub use sp_arithmetic::traits::Zero;
 
 use super::*;
 

+ 19 - 20
runtime-modules/proposals/engine/src/tests/mock/mod.rs

@@ -7,14 +7,14 @@
 //!
 
 #![cfg(test)]
-pub use primitives::{Blake2Hasher, H256};
-pub use sr_primitives::{
-    testing::{Digest, DigestItem, Header, UintAuthorityId},
-    traits::{BlakeTwo256, Convert, IdentityLookup, OnFinalize, Zero},
-    weights::Weight,
-    BuildStorage, DispatchError, Perbill,
+
+use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
+use sp_core::H256;
+use sp_runtime::{
+    testing::Header,
+    traits::{BlakeTwo256, IdentityLookup},
+    Perbill,
 };
-use srml_support::{impl_outer_event, impl_outer_origin, parameter_types};
 pub use system;
 
 mod balance_manager;
@@ -46,30 +46,20 @@ impl_outer_event! {
         balances<T>,
         engine<T>,
         membership_mod<T>,
+        system<T>,
     }
 }
 
 parameter_types! {
     pub const ExistentialDeposit: u32 = 0;
-    pub const TransferFee: u32 = 0;
-    pub const CreationFee: u32 = 0;
 }
 
 impl balances::Trait for Test {
-    /// The type for recording an account's balance.
     type Balance = u64;
-    /// What to do if an account's free balance gets zeroed.
-    type OnFreeBalanceZero = ();
-    /// What to do if a new account is created.
-    type OnNewAccount = ();
-
-    type TransferPayment = ();
-
     type DustRemoval = ();
     type Event = TestEvent;
     type ExistentialDeposit = ExistentialDeposit;
-    type TransferFee = TransferFee;
-    type CreationFee = CreationFee;
+    type AccountStore = System;
 }
 
 impl common::currency::GovernanceCurrency for Test {
@@ -149,6 +139,7 @@ parameter_types! {
 }
 
 impl system::Trait for Test {
+    type BaseCallFilter = ();
     type Origin = Origin;
     type Call = ();
     type Index = u64;
@@ -161,9 +152,17 @@ impl system::Trait for Test {
     type Event = TestEvent;
     type BlockHashCount = BlockHashCount;
     type MaximumBlockWeight = MaximumBlockWeight;
+    type DbWeight = ();
+    type BlockExecutionWeight = ();
+    type ExtrinsicBaseWeight = ();
+    type MaximumExtrinsicWeight = ();
     type MaximumBlockLength = MaximumBlockLength;
     type AvailableBlockRatio = AvailableBlockRatio;
     type Version = ();
+    type ModuleToIndex = ();
+    type AccountData = balances::AccountData<u64>;
+    type OnNewAccount = ();
+    type OnKilledAccount = ();
 }
 
 impl timestamp::Trait for Test {
@@ -172,7 +171,7 @@ impl timestamp::Trait for Test {
     type MinimumPeriod = MinimumPeriod;
 }
 
-pub fn initial_test_ext() -> runtime_io::TestExternalities {
+pub fn initial_test_ext() -> sp_io::TestExternalities {
     let t = system::GenesisConfig::default()
         .build_storage::<Test>()
         .unwrap();

+ 3 - 2
runtime-modules/proposals/engine/src/tests/mock/proposals.rs

@@ -1,16 +1,17 @@
 //! Contains executable proposal extrinsic mocks
 
-use rstd::prelude::*;
+use frame_support::decl_module;
 use rstd::vec::Vec;
-use srml_support::decl_module;
 pub trait Trait: system::Trait {}
 
 decl_module! {
     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
         /// Working extrinsic test
+        #[weight = 10_000_000]
         pub fn dummy_proposal(_origin, _title: Vec<u8>, _description: Vec<u8>) {}
 
         /// Broken extrinsic test
+        #[weight = 10_000_000]
         pub fn faulty_proposal(_origin, _title: Vec<u8>, _description: Vec<u8>,) {
              Err("ExecutionFailed")?
         }

+ 114 - 91
runtime-modules/proposals/engine/src/tests/mod.rs

@@ -4,14 +4,13 @@ use crate::*;
 use mock::*;
 
 use codec::Encode;
+use frame_support::dispatch::DispatchResult;
+use frame_support::traits::{Currency, OnFinalize, OnInitialize};
+use frame_support::{StorageDoubleMap, StorageMap, StorageValue};
 use rstd::rc::Rc;
-use sr_primitives::traits::{DispatchResult, OnFinalize, OnInitialize};
-use srml_support::{StorageDoubleMap, StorageMap, StorageValue};
 use system::RawOrigin;
 use system::{EventRecord, Phase};
 
-use srml_support::traits::Currency;
-
 pub(crate) fn increase_total_balance_issuance_using_account_id(account_id: u64, balance: u64) {
     let initial_balance = Balances::total_issuance();
     {
@@ -132,7 +131,7 @@ impl DummyProposalFixture {
         }
     }
 
-    fn create_proposal_and_assert(self, result: Result<u32, Error>) -> Option<u32> {
+    fn create_proposal_and_assert(self, result: Result<u32, DispatchError>) -> Option<u32> {
         let proposal_id_result = ProposalsEngine::create_proposal(
             self.account_id,
             self.proposer_id,
@@ -174,7 +173,7 @@ impl CancelProposalFixture {
         }
     }
 
-    fn cancel_and_assert(self, expected_result: DispatchResult<Error>) {
+    fn cancel_and_assert(self, expected_result: DispatchResult) {
         assert_eq!(
             ProposalsEngine::cancel_proposal(
                 self.origin.into(),
@@ -202,7 +201,7 @@ impl VetoProposalFixture {
         VetoProposalFixture { origin, ..self }
     }
 
-    fn veto_and_assert(self, expected_result: DispatchResult<Error>) {
+    fn veto_and_assert(self, expected_result: DispatchResult) {
         assert_eq!(
             ProposalsEngine::veto_proposal(self.origin.into(), self.proposal_id,),
             expected_result
@@ -230,11 +229,11 @@ impl VoteGenerator {
         self.vote_and_assert(vote_kind, Ok(()));
     }
 
-    fn vote_and_assert(&mut self, vote_kind: VoteKind, expected_result: DispatchResult<Error>) {
+    fn vote_and_assert(&mut self, vote_kind: VoteKind, expected_result: DispatchResult) {
         assert_eq!(self.vote(vote_kind.clone()), expected_result);
     }
 
-    fn vote(&mut self, vote_kind: VoteKind) -> DispatchResult<Error> {
+    fn vote(&mut self, vote_kind: VoteKind) -> DispatchResult {
         if self.auto_increment_voter_id {
             self.current_account_id += 1;
             self.current_voter_id += 1;
@@ -255,7 +254,7 @@ impl EventFixture {
         let expected_events = expected_raw_events
             .iter()
             .map(|ev| EventRecord {
-                phase: Phase::ApplyExtrinsic(0),
+                phase: Phase::Initialization,
                 event: TestEvent::engine(ev.clone()),
                 topics: vec![],
             })
@@ -307,7 +306,7 @@ fn vote_fails_with_insufficient_rights() {
     initial_test_ext().execute_with(|| {
         assert_eq!(
             ProposalsEngine::vote(system::RawOrigin::None.into(), 1, 1, VoteKind::Approve),
-            Err(Error::Other("RequireSignedOrigin"))
+            Err(DispatchError::Other("Bad origin"))
         );
     });
 }
@@ -338,8 +337,8 @@ fn proposal_execution_succeeds() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::approved(ApprovedProposalStatus::Executed, 1),
+                created_at: 0,
+                status: ProposalStatus::approved(ApprovedProposalStatus::Executed, 0),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults {
@@ -387,10 +386,10 @@ fn proposal_execution_failed() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
+                created_at: 0,
                 status: ProposalStatus::approved(
                     ApprovedProposalStatus::failed_execution("ExecutionFailed"),
-                    1
+                    0
                 ),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
@@ -457,7 +456,7 @@ fn rejected_voting_results_and_remove_proposal_id_from_active_succeeds() {
         vote_generator.vote_and_assert_ok(VoteKind::Abstain);
         vote_generator.vote_and_assert_ok(VoteKind::Abstain);
 
-        assert!(<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert!(<ActiveProposalIds<Test>>::contains_key(proposal_id));
 
         // internal active proposal counter check
         assert_eq!(<ActiveProposalCount>::get(), 1);
@@ -478,9 +477,9 @@ fn rejected_voting_results_and_remove_proposal_id_from_active_succeeds() {
 
         assert_eq!(
             proposal.status,
-            ProposalStatus::finalized_successfully(ProposalDecisionStatus::Rejected, 1),
+            ProposalStatus::finalized_successfully(ProposalDecisionStatus::Rejected, 0),
         );
-        assert!(!<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert!(!<ActiveProposalIds<Test>>::contains_key(proposal_id));
 
         // internal active proposal counter check
         assert_eq!(<ActiveProposalCount>::get(), 0);
@@ -492,21 +491,22 @@ fn create_proposal_fails_with_invalid_body_or_title() {
     initial_test_ext().execute_with(|| {
         let mut dummy_proposal =
             DummyProposalFixture::default().with_title_and_body(Vec::new(), b"body".to_vec());
-        dummy_proposal.create_proposal_and_assert(Err(Error::EmptyTitleProvided.into()));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::EmptyTitleProvided.into()));
 
         dummy_proposal =
             DummyProposalFixture::default().with_title_and_body(b"title".to_vec(), Vec::new());
-        dummy_proposal.create_proposal_and_assert(Err(Error::EmptyDescriptionProvided.into()));
+        dummy_proposal
+            .create_proposal_and_assert(Err(Error::<Test>::EmptyDescriptionProvided.into()));
 
         let too_long_title = vec![0; 200];
         dummy_proposal =
             DummyProposalFixture::default().with_title_and_body(too_long_title, b"body".to_vec());
-        dummy_proposal.create_proposal_and_assert(Err(Error::TitleIsTooLong.into()));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::TitleIsTooLong.into()));
 
         let too_long_body = vec![0; 11000];
         dummy_proposal =
             DummyProposalFixture::default().with_title_and_body(b"title".to_vec(), too_long_body);
-        dummy_proposal.create_proposal_and_assert(Err(Error::DescriptionIsTooLong.into()));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::DescriptionIsTooLong.into()));
     });
 }
 
@@ -519,7 +519,10 @@ fn vote_fails_with_expired_voting_period() {
         run_to_block_and_finalize(6);
 
         let mut vote_generator = VoteGenerator::new(proposal_id);
-        vote_generator.vote_and_assert(VoteKind::Approve, Err(Error::ProposalFinalized));
+        vote_generator.vote_and_assert(
+            VoteKind::Approve,
+            Err(Error::<Test>::ProposalFinalized.into()),
+        );
     });
 }
 
@@ -538,7 +541,10 @@ fn vote_fails_with_not_active_proposal() {
         run_to_block_and_finalize(2);
 
         let mut vote_generator_to_fail = VoteGenerator::new(proposal_id);
-        vote_generator_to_fail.vote_and_assert(VoteKind::Approve, Err(Error::ProposalFinalized));
+        vote_generator_to_fail.vote_and_assert(
+            VoteKind::Approve,
+            Err(Error::<Test>::ProposalFinalized.into()),
+        );
     });
 }
 
@@ -546,7 +552,10 @@ fn vote_fails_with_not_active_proposal() {
 fn vote_fails_with_absent_proposal() {
     initial_test_ext().execute_with(|| {
         let mut vote_generator = VoteGenerator::new(2);
-        vote_generator.vote_and_assert(VoteKind::Approve, Err(Error::ProposalNotFound));
+        vote_generator.vote_and_assert(
+            VoteKind::Approve,
+            Err(Error::<Test>::ProposalNotFound.into()),
+        );
     });
 }
 
@@ -560,7 +569,7 @@ fn vote_fails_on_double_voting() {
         vote_generator.auto_increment_voter_id = false;
 
         vote_generator.vote_and_assert_ok(VoteKind::Approve);
-        vote_generator.vote_and_assert(VoteKind::Approve, Err(Error::AlreadyVoted));
+        vote_generator.vote_and_assert(VoteKind::Approve, Err(Error::<Test>::AlreadyVoted.into()));
     });
 }
 
@@ -588,8 +597,8 @@ fn cancel_proposal_succeeds() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Canceled, 1),
+                created_at: 0,
+                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Canceled, 0),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults::default(),
@@ -607,7 +616,7 @@ fn cancel_proposal_fails_with_not_active_proposal() {
         run_to_block_and_finalize(6);
 
         let cancel_proposal = CancelProposalFixture::new(proposal_id);
-        cancel_proposal.cancel_and_assert(Err(Error::ProposalFinalized));
+        cancel_proposal.cancel_and_assert(Err(Error::<Test>::ProposalFinalized.into()));
     });
 }
 
@@ -615,7 +624,7 @@ fn cancel_proposal_fails_with_not_active_proposal() {
 fn cancel_proposal_fails_with_not_existing_proposal() {
     initial_test_ext().execute_with(|| {
         let cancel_proposal = CancelProposalFixture::new(2);
-        cancel_proposal.cancel_and_assert(Err(Error::ProposalNotFound));
+        cancel_proposal.cancel_and_assert(Err(Error::<Test>::ProposalNotFound.into()));
     });
 }
 
@@ -628,7 +637,7 @@ fn cancel_proposal_fails_with_insufficient_rights() {
         let cancel_proposal = CancelProposalFixture::new(proposal_id)
             .with_origin(RawOrigin::Signed(2))
             .with_proposer(2);
-        cancel_proposal.cancel_and_assert(Err(Error::NotAuthor));
+        cancel_proposal.cancel_and_assert(Err(Error::<Test>::NotAuthor.into()));
     });
 }
 
@@ -656,8 +665,8 @@ fn veto_proposal_succeeds() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Vetoed, 1),
+                created_at: 0,
+                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Vetoed, 0),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults::default(),
@@ -678,7 +687,7 @@ fn veto_proposal_fails_with_not_active_proposal() {
         run_to_block_and_finalize(6);
 
         let veto_proposal = VetoProposalFixture::new(proposal_id);
-        veto_proposal.veto_and_assert(Err(Error::ProposalFinalized));
+        veto_proposal.veto_and_assert(Err(Error::<Test>::ProposalFinalized.into()));
     });
 }
 
@@ -686,7 +695,7 @@ fn veto_proposal_fails_with_not_active_proposal() {
 fn veto_proposal_fails_with_not_existing_proposal() {
     initial_test_ext().execute_with(|| {
         let veto_proposal = VetoProposalFixture::new(2);
-        veto_proposal.veto_and_assert(Err(Error::ProposalNotFound));
+        veto_proposal.veto_and_assert(Err(Error::<Test>::ProposalNotFound.into()));
     });
 }
 
@@ -697,13 +706,16 @@ fn veto_proposal_fails_with_insufficient_rights() {
         let proposal_id = dummy_proposal.create_proposal_and_assert(Ok(1)).unwrap();
 
         let veto_proposal = VetoProposalFixture::new(proposal_id).with_origin(RawOrigin::Signed(2));
-        veto_proposal.veto_and_assert(Err(Error::RequireRootOrigin));
+        veto_proposal.veto_and_assert(Err(DispatchError::BadOrigin));
     });
 }
 
 #[test]
 fn create_proposal_event_emitted() {
     initial_test_ext().execute_with(|| {
+        // Events start only from 1 first block. No events on block zero.
+        run_to_block_and_finalize(1);
+
         let dummy_proposal = DummyProposalFixture::default();
         dummy_proposal.create_proposal_and_assert(Ok(1));
 
@@ -714,6 +726,9 @@ fn create_proposal_event_emitted() {
 #[test]
 fn veto_proposal_event_emitted() {
     initial_test_ext().execute_with(|| {
+        // Events start only from 1 first block. No events on block zero.
+        run_to_block_and_finalize(1);
+
         let dummy_proposal = DummyProposalFixture::default();
         let proposal_id = dummy_proposal.create_proposal_and_assert(Ok(1)).unwrap();
 
@@ -733,6 +748,9 @@ fn veto_proposal_event_emitted() {
 #[test]
 fn cancel_proposal_event_emitted() {
     initial_test_ext().execute_with(|| {
+        // Events start only from 1 first block. No events on block zero.
+        run_to_block_and_finalize(1);
+
         let dummy_proposal = DummyProposalFixture::default();
         let proposal_id = dummy_proposal.create_proposal_and_assert(Ok(1)).unwrap();
 
@@ -757,6 +775,9 @@ fn cancel_proposal_event_emitted() {
 #[test]
 fn vote_proposal_event_emitted() {
     initial_test_ext().execute_with(|| {
+        // Events start only from 1 first block. No events on block zero.
+        run_to_block_and_finalize(1);
+
         let dummy_proposal = DummyProposalFixture::default();
         let proposal_id = dummy_proposal.create_proposal_and_assert(Ok(1)).unwrap();
 
@@ -787,8 +808,8 @@ fn create_proposal_and_expire_it() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Expired, 4),
+                created_at: 0,
+                status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Expired, 3),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults::default(),
@@ -800,7 +821,7 @@ fn create_proposal_and_expire_it() {
 #[test]
 fn proposal_execution_postponed_because_of_grace_period() {
     initial_test_ext().execute_with(|| {
-        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(2);
+        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(3);
         let dummy_proposal =
             DummyProposalFixture::default().with_parameters(parameters_fixture.params());
 
@@ -815,10 +836,10 @@ fn proposal_execution_postponed_because_of_grace_period() {
         run_to_block_and_finalize(1);
         run_to_block_and_finalize(2);
 
-        // check internal cache for proposal_id presense
-        assert!(<PendingExecutionProposalIds<Test>>::enumerate()
-            .find(|(x, _)| *x == proposal_id)
-            .is_some());
+        // check internal cache for proposal_id presence
+        assert!(<PendingExecutionProposalIds<Test>>::contains_key(
+            proposal_id
+        ));
 
         let proposal = <crate::Proposals<Test>>::get(proposal_id);
 
@@ -827,8 +848,8 @@ fn proposal_execution_postponed_because_of_grace_period() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 1),
+                created_at: 0,
+                status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 0),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults {
@@ -845,7 +866,7 @@ fn proposal_execution_postponed_because_of_grace_period() {
 #[test]
 fn proposal_execution_vetoed_successfully_during_the_grace_period() {
     initial_test_ext().execute_with(|| {
-        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(2);
+        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(3);
         let dummy_proposal =
             DummyProposalFixture::default().with_parameters(parameters_fixture.params());
 
@@ -860,10 +881,10 @@ fn proposal_execution_vetoed_successfully_during_the_grace_period() {
         run_to_block_and_finalize(1);
         run_to_block_and_finalize(2);
 
-        // check internal cache for proposal_id presense
-        assert!(<PendingExecutionProposalIds<Test>>::enumerate()
-            .find(|(x, _)| *x == proposal_id)
-            .is_some());
+        // check internal cache for proposal_id presence
+        assert!(<PendingExecutionProposalIds<Test>>::contains_key(
+            proposal_id
+        ));
 
         let proposal = <crate::Proposals<Test>>::get(proposal_id);
 
@@ -872,8 +893,8 @@ fn proposal_execution_vetoed_successfully_during_the_grace_period() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
-                status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 1),
+                created_at: 0,
+                status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 0),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
                 voting_results: VotingResults {
@@ -895,7 +916,7 @@ fn proposal_execution_vetoed_successfully_during_the_grace_period() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
+                created_at: 0,
                 status: ProposalStatus::finalized_successfully(ProposalDecisionStatus::Vetoed, 2),
                 title: b"title".to_vec(),
                 description: b"description".to_vec(),
@@ -908,17 +929,17 @@ fn proposal_execution_vetoed_successfully_during_the_grace_period() {
             }
         );
 
-        // check internal cache for proposal_id presense
-        assert!(<PendingExecutionProposalIds<Test>>::enumerate()
-            .find(|(x, _)| *x == proposal_id)
-            .is_none());
+        // check internal cache for proposal_id absence
+        assert!(!<PendingExecutionProposalIds<Test>>::contains_key(
+            proposal_id
+        ));
     });
 }
 
 #[test]
 fn proposal_execution_succeeds_after_the_grace_period() {
     initial_test_ext().execute_with(|| {
-        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(1);
+        let parameters_fixture = ProposalParametersFixture::default().with_grace_period(2);
         let dummy_proposal =
             DummyProposalFixture::default().with_parameters(parameters_fixture.params());
         let proposal_id = dummy_proposal.create_proposal_and_assert(Ok(1)).unwrap();
@@ -932,17 +953,17 @@ fn proposal_execution_succeeds_after_the_grace_period() {
         run_to_block_and_finalize(1);
 
         // check internal cache for proposal_id presence
-        assert!(<PendingExecutionProposalIds<Test>>::enumerate()
-            .find(|(x, _)| *x == proposal_id)
-            .is_some());
+        assert!(<PendingExecutionProposalIds<Test>>::contains_key(
+            proposal_id
+        ));
 
         let mut proposal = <crate::Proposals<Test>>::get(proposal_id);
 
         let mut expected_proposal = Proposal {
             parameters: parameters_fixture.params(),
             proposer_id: 1,
-            created_at: 1,
-            status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 1),
+            created_at: 0,
+            status: ProposalStatus::approved(ApprovedProposalStatus::PendingExecution, 0),
             title: b"title".to_vec(),
             description: b"description".to_vec(),
             voting_results: VotingResults {
@@ -959,14 +980,14 @@ fn proposal_execution_succeeds_after_the_grace_period() {
 
         proposal = <crate::Proposals<Test>>::get(proposal_id);
 
-        expected_proposal.status = ProposalStatus::approved(ApprovedProposalStatus::Executed, 1);
+        expected_proposal.status = ProposalStatus::approved(ApprovedProposalStatus::Executed, 0);
 
         assert_eq!(proposal, expected_proposal);
 
-        // check internal cache for proposal_id absense
-        assert!(<PendingExecutionProposalIds<Test>>::enumerate()
-            .find(|(x, _)| *x == proposal_id)
-            .is_none());
+        // check internal cache for proposal_id absence
+        assert!(!<PendingExecutionProposalIds<Test>>::contains_key(
+            proposal_id
+        ));
     });
 }
 
@@ -982,7 +1003,7 @@ fn create_proposal_fails_on_exceeding_max_active_proposals_count() {
 
         let dummy_proposal = DummyProposalFixture::default();
         dummy_proposal
-            .create_proposal_and_assert(Err(Error::MaxActiveProposalNumberExceeded.into()));
+            .create_proposal_and_assert(Err(Error::<Test>::MaxActiveProposalNumberExceeded.into()));
         // internal active proposal counter check
         assert_eq!(<ActiveProposalCount>::get(), 100);
     });
@@ -1004,7 +1025,7 @@ fn voting_internal_cache_exists_after_proposal_finalization() {
         vote_generator.vote_and_assert_ok(VoteKind::Abstain);
 
         // cache exists
-        assert!(<crate::VoteExistsByProposalByVoter<Test>>::exists(
+        assert!(<crate::VoteExistsByProposalByVoter<Test>>::contains_key(
             proposal_id,
             1
         ));
@@ -1012,7 +1033,7 @@ fn voting_internal_cache_exists_after_proposal_finalization() {
         run_to_block_and_finalize(2);
 
         // cache still exists and is not cleared
-        assert!(<crate::VoteExistsByProposalByVoter<Test>>::exists(
+        assert!(<crate::VoteExistsByProposalByVoter<Test>>::contains_key(
             proposal_id,
             1
         ));
@@ -1044,7 +1065,7 @@ fn create_dummy_proposal_succeeds_with_stake() {
             Proposal {
                 parameters: parameters_fixture.params(),
                 proposer_id: 1,
-                created_at: 1,
+                created_at: 0,
                 status: ProposalStatus::Active(Some(ActiveStake {
                     stake_id: 0, // valid stake_id
                     source_account_id: 1
@@ -1070,8 +1091,7 @@ fn create_dummy_proposal_fail_with_stake_on_empty_account() {
             .with_account_id(account_id)
             .with_stake(required_stake);
 
-        dummy_proposal
-            .create_proposal_and_assert(Err(Error::Other("too few free funds in account")));
+        dummy_proposal.create_proposal_and_assert(Err(DispatchError::Other("InsufficientBalance")));
     });
 }
 
@@ -1084,20 +1104,21 @@ fn create_proposal_fais_with_invalid_stake_parameters() {
             .with_parameters(parameters_fixture.params())
             .with_stake(200);
 
-        dummy_proposal.create_proposal_and_assert(Err(Error::StakeShouldBeEmpty.into()));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::StakeShouldBeEmpty.into()));
 
         let parameters_fixture_stake_200 = parameters_fixture.with_required_stake(200);
         dummy_proposal =
             DummyProposalFixture::default().with_parameters(parameters_fixture_stake_200.params());
 
-        dummy_proposal.create_proposal_and_assert(Err(Error::EmptyStake.into()));
+        dummy_proposal.create_proposal_and_assert(Err(Error::<Test>::EmptyStake.into()));
 
         let parameters_fixture_stake_300 = parameters_fixture.with_required_stake(300);
         dummy_proposal = DummyProposalFixture::default()
             .with_parameters(parameters_fixture_stake_300.params())
             .with_stake(200);
 
-        dummy_proposal.create_proposal_and_assert(Err(Error::StakeDiffersFromRequired.into()));
+        dummy_proposal
+            .create_proposal_and_assert(Err(Error::<Test>::StakeDiffersFromRequired.into()));
     });
 }
 
@@ -1141,7 +1162,7 @@ fn finalize_expired_proposal_and_check_stake_removing_with_balance_checks_succee
         let mut expected_proposal = Proposal {
             parameters,
             proposer_id: 1,
-            created_at: 1,
+            created_at: 0,
             status: ProposalStatus::Active(Some(ActiveStake {
                 stake_id: 0,
                 source_account_id: 1,
@@ -1159,7 +1180,7 @@ fn finalize_expired_proposal_and_check_stake_removing_with_balance_checks_succee
 
         expected_proposal.status = ProposalStatus::Finalized(FinalizationData {
             proposal_status: ProposalDecisionStatus::Expired,
-            finalized_at: 4,
+            finalized_at: 3,
             encoded_unstaking_error_due_to_broken_runtime: None,
             stake_data_after_unstaking_error: None,
         });
@@ -1214,7 +1235,7 @@ fn proposal_cancellation_with_slashes_with_balance_checks_succeeds() {
         let mut expected_proposal = Proposal {
             parameters,
             proposer_id: 1,
-            created_at: 1,
+            created_at: 0,
             status: ProposalStatus::Active(Some(ActiveStake {
                 stake_id: 0,
                 source_account_id: 1,
@@ -1234,7 +1255,7 @@ fn proposal_cancellation_with_slashes_with_balance_checks_succeeds() {
 
         expected_proposal.status = ProposalStatus::Finalized(FinalizationData {
             proposal_status: ProposalDecisionStatus::Canceled,
-            finalized_at: 1,
+            finalized_at: 0,
             encoded_unstaking_error_due_to_broken_runtime: None,
             stake_data_after_unstaking_error: None,
         });
@@ -1302,7 +1323,7 @@ fn proposal_slashing_succeeds() {
         vote_generator.vote_and_assert_ok(VoteKind::Slash);
         vote_generator.vote_and_assert_ok(VoteKind::Slash);
 
-        assert!(<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert!(<ActiveProposalIds<Test>>::contains_key(proposal_id));
 
         run_to_block_and_finalize(2);
 
@@ -1323,11 +1344,11 @@ fn proposal_slashing_succeeds() {
             ProposalStatus::Finalized(FinalizationData {
                 proposal_status: ProposalDecisionStatus::Slashed,
                 encoded_unstaking_error_due_to_broken_runtime: None,
-                finalized_at: 1,
+                finalized_at: 0,
                 stake_data_after_unstaking_error: None,
             }),
         );
-        assert!(!<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert!(!<ActiveProposalIds<Test>>::contains_key(proposal_id));
     });
 }
 
@@ -1377,7 +1398,7 @@ fn finalize_proposal_using_stake_mocks_failed() {
                 Proposal {
                     parameters: parameters_fixture.params(),
                     proposer_id: 1,
-                    created_at: 1,
+                    created_at: 0,
                     status: ProposalStatus::finalized(
                         ProposalDecisionStatus::Expired,
                         Some("Cannot remove stake"),
@@ -1385,7 +1406,7 @@ fn finalize_proposal_using_stake_mocks_failed() {
                             stake_id: 1,
                             source_account_id: 1
                         }),
-                        4,
+                        3,
                     ),
                     title: b"title".to_vec(),
                     description: b"description".to_vec(),
@@ -1411,15 +1432,17 @@ fn create_proposal_fails_with_invalid_threshold_parameters() {
 
         let mut dummy_proposal = DummyProposalFixture::default().with_parameters(parameters);
 
-        dummy_proposal
-            .create_proposal_and_assert(Err(Error::InvalidParameterApprovalThreshold.into()));
+        dummy_proposal.create_proposal_and_assert(Err(
+            Error::<Test>::InvalidParameterApprovalThreshold.into(),
+        ));
 
         parameters.approval_threshold_percentage = 60;
         parameters.slashing_threshold_percentage = 0;
         dummy_proposal = DummyProposalFixture::default().with_parameters(parameters);
 
-        dummy_proposal
-            .create_proposal_and_assert(Err(Error::InvalidParameterSlashingThreshold.into()));
+        dummy_proposal.create_proposal_and_assert(Err(
+            Error::<Test>::InvalidParameterSlashingThreshold.into(),
+        ));
     });
 }
 
@@ -1434,7 +1457,7 @@ fn proposal_reset_succeeds() {
         vote_generator.vote_and_assert_ok(VoteKind::Abstain);
         vote_generator.vote_and_assert_ok(VoteKind::Slash);
 
-        assert!(<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert!(<ActiveProposalIds<Test>>::contains_key(proposal_id));
         assert_eq!(
             <VoteExistsByProposalByVoter<Test>>::get(&proposal_id, &2),
             VoteKind::Abstain

+ 0 - 1
runtime-modules/proposals/engine/src/types/proposal_statuses.rs

@@ -1,7 +1,6 @@
 #![warn(missing_docs)]
 
 use codec::{Decode, Encode};
-use rstd::prelude::*;
 
 use crate::ActiveStake;
 #[cfg(feature = "std")]