Browse Source

Fix reset_proposal() in the engine module

- fix reset_proposal() in the engine module: clean VoteExistsByProposalByVoter double map
- add tests
Shamil Gadelshin 5 years ago
parent
commit
6c01c09dc5

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

@@ -469,6 +469,7 @@ impl<T: Trait> Module<T> {
         <ActiveProposalIds<T>>::enumerate().for_each(|(proposal_id, _)| {
             <Proposals<T>>::mutate(proposal_id, |proposal| {
                 proposal.reset_proposal();
+                <VoteExistsByProposalByVoter<T>>::remove_prefix(&proposal_id);
             });
         });
     }

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

@@ -6,7 +6,7 @@ use mock::*;
 use codec::Encode;
 use rstd::rc::Rc;
 use sr_primitives::traits::{DispatchResult, OnFinalize, OnInitialize};
-use srml_support::{StorageMap, StorageValue};
+use srml_support::{StorageDoubleMap, StorageMap, StorageValue};
 use system::RawOrigin;
 use system::{EventRecord, Phase};
 
@@ -1339,6 +1339,10 @@ fn proposal_reset_succeeds() {
         vote_generator.vote_and_assert_ok(VoteKind::Slash);
 
         assert!(<ActiveProposalIds<Test>>::exists(proposal_id));
+        assert_eq!(
+            <VoteExistsByProposalByVoter<Test>>::get(&proposal_id, &2),
+            VoteKind::Abstain
+        );
 
         run_to_block_and_finalize(2);
 
@@ -1367,5 +1371,11 @@ fn proposal_reset_succeeds() {
                 slashes: 0,
             }
         );
+
+        // whole double map prefix was removed (should return default value)
+        assert_eq!(
+            <VoteExistsByProposalByVoter<Test>>::get(&proposal_id, &2),
+            VoteKind::default()
+        );
     });
 }