Procházet zdrojové kódy

Proposals: cleaun-up ProposalCreated event

iorveth před 3 roky
rodič
revize
7e289297c9

+ 3 - 1
runtime-modules/proposals/codex/src/benchmarking.rs

@@ -159,7 +159,9 @@ fn create_proposal_verify<T: Trait>(
         "Active proposal count not updated"
     );
 
-    assert_last_event::<T>(RawEvent::ProposalCreated(proposal_parameters, proposal_details).into());
+    assert_last_event::<T>(
+        RawEvent::ProposalCreated(proposal_id, proposal_parameters, proposal_details).into(),
+    );
 
     assert!(
         ThreadIdByProposalId::<T>::contains_key(proposal_id),

+ 4 - 2
runtime-modules/proposals/codex/src/lib.rs

@@ -259,12 +259,14 @@ decl_event! {
     pub enum Event<T> where
         GeneralProposalParameters = GeneralProposalParameters<T>,
         ProposalDetailsOf = ProposalDetailsOf<T>,
+        <T as proposals_engine::Trait>::ProposalId,
     {
         /// A proposal was created
         /// Params:
+        /// - Id of a newly created proposal after it was saved in storage.
         /// - General proposal parameter. Parameters shared by all proposals
         /// - Proposal Details. Parameter of proposal with a variant for each kind of proposal
-        ProposalCreated(GeneralProposalParameters, ProposalDetailsOf),
+        ProposalCreated(ProposalId, GeneralProposalParameters, ProposalDetailsOf),
     }
 }
 
@@ -513,7 +515,7 @@ decl_module! {
 
             <ThreadIdByProposalId<T>>::insert(proposal_id, discussion_thread_id);
 
-            Self::deposit_event(RawEvent::ProposalCreated(general_proposal_parameters, proposal_details));
+            Self::deposit_event(RawEvent::ProposalCreated(proposal_id, general_proposal_parameters, proposal_details));
         }
     }
 }

+ 1 - 0
runtime-modules/proposals/codex/src/tests/mod.rs

@@ -123,6 +123,7 @@ where
         assert_eq!(proposal.parameters, self.proposal_parameters);
         assert_last_event(
             RawEvent::ProposalCreated(
+                proposal_id,
                 self.general_proposal_parameters.clone(),
                 self.proposal_details.clone(),
             )

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

@@ -259,11 +259,6 @@ decl_event!(
         MemberId = MemberId<T>,
         <T as frame_system::Trait>::BlockNumber,
     {
-        /// Emits on proposal creation.
-        /// Params:
-        /// - Member id of a proposer.
-        /// - Id of a newly created proposal after it was saved in storage.
-        ProposalCreated(MemberId, ProposalId),
 
         /// Emits on proposal creation.
         /// Params:
@@ -604,11 +599,6 @@ impl<T: Trait> Module<T> {
         ProposalCount::put(next_proposal_count_value);
         Self::increase_active_proposal_counter();
 
-        Self::deposit_event(RawEvent::ProposalCreated(
-            creation_params.proposer_id,
-            proposal_id,
-        ));
-
         Ok(proposal_id)
     }
 

+ 1 - 18
runtime-modules/proposals/engine/src/tests/mod.rs

@@ -406,7 +406,6 @@ fn proposal_execution_succeeds() {
         run_to_block(2);
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Approve, Vec::new()),
@@ -458,7 +457,6 @@ fn proposal_execution_failed() {
         assert!(!<crate::Proposals<Test>>::contains_key(proposal_id));
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Approve, Vec::new()),
@@ -509,7 +507,6 @@ fn voting_results_calculation_succeeds() {
         run_to_block(block_number);
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Reject, Vec::new()),
@@ -871,15 +868,13 @@ fn veto_proposal_fails_with_insufficient_rights() {
 }
 
 #[test]
-fn create_proposal_event_emitted() {
+fn create_proposal() {
     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));
-
-        EventFixture::assert_events(vec![RawEvent::ProposalCreated(1, 1)]);
     });
 }
 
@@ -896,7 +891,6 @@ fn veto_proposal_event_emitted() {
         veto_proposal.veto_and_assert(Ok(()));
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::ProposalDecisionMade(proposal_id, ProposalDecision::Vetoed),
         ]);
     });
@@ -918,7 +912,6 @@ fn cancel_proposal_event_emitted() {
         cancel_proposal.cancel_and_assert(Ok(()));
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::ProposalDecisionMade(proposal_id, ProposalDecision::Canceled),
             RawEvent::ProposalCancelled(dummy_proposal.account_id, proposal_id),
         ]);
@@ -938,7 +931,6 @@ fn vote_proposal_event_emitted() {
         vote_generator.vote_and_assert_ok(VoteKind::Approve);
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, 1),
             RawEvent::Voted(1, 1, VoteKind::Approve, Vec::new()),
         ]);
     });
@@ -961,13 +953,11 @@ fn create_proposal_and_expire_it() {
         run_to_block_and_finalize(expected_expriration_block - 1);
 
         assert!(<crate::Proposals<Test>>::contains_key(proposal_id));
-        EventFixture::assert_last_crate_event(RawEvent::ProposalCreated(1, proposal_id));
 
         run_to_block_and_finalize(expected_expriration_block);
 
         assert!(!<crate::Proposals<Test>>::contains_key(proposal_id));
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::ProposalDecisionMade(proposal_id, ProposalDecision::Expired),
         ]);
     });
@@ -1091,8 +1081,6 @@ fn cancel_active_and_pending_execution_proposal_by_runtime() {
         ProposalsEngine::cancel_active_and_pending_proposals();
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, pending_execution_proposal_id),
-            RawEvent::ProposalCreated(1, active_proposal_id),
             RawEvent::Voted(
                 1,
                 pending_execution_proposal_id,
@@ -1186,7 +1174,6 @@ fn cancel_pending_constitutionality_proposal_by_runtime() {
         ProposalsEngine::cancel_active_and_pending_proposals();
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Approve, Vec::new()),
@@ -1849,7 +1836,6 @@ fn proposal_with_pending_constitutionality_succeeds() {
         run_to_block_and_finalize(2);
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Approve, Vec::new()),
@@ -1912,7 +1898,6 @@ fn proposal_with_pending_constitutionality_reactivation_succeeds() {
         run_to_block_and_finalize(2);
 
         EventFixture::assert_events(vec![
-            RawEvent::ProposalCreated(1, proposal_id),
             RawEvent::Voted(1, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(2, proposal_id, VoteKind::Approve, Vec::new()),
             RawEvent::Voted(3, proposal_id, VoteKind::Approve, Vec::new()),
@@ -2010,7 +1995,6 @@ fn proposal_with_pending_constitutionality_execution_succeeds() {
         EventFixture::assert_global_events(vec![
             TestEvent::frame_system(frame_system::RawEvent::NewAccount(1)), // because of token transfer
             TestEvent::balances(balances::RawEvent::Endowed(1, total_balance)), // because of token transfer
-            TestEvent::engine(RawEvent::ProposalCreated(1, proposal_id)),
             TestEvent::engine(RawEvent::Voted(
                 1,
                 proposal_id,
@@ -2109,7 +2093,6 @@ fn proposal_with_pending_constitutionality_execution_succeeds() {
             // first chain of event from the creation to the approval
             TestEvent::frame_system(frame_system::RawEvent::NewAccount(1)), // because of token transfer
             TestEvent::balances(balances::RawEvent::Endowed(1, total_balance)), // because of token transfer
-            TestEvent::engine(RawEvent::ProposalCreated(1, proposal_id)),
             TestEvent::engine(RawEvent::Voted(
                 1,
                 proposal_id,