From 650e30d39ceeb821d3ef4d525a49cd5490392020 Mon Sep 17 00:00:00 2001
From: Gav <gavin@parity.io>
Date: Sun, 4 Mar 2018 13:47:36 +0100
Subject: [PATCH] Tests for public referenda.

---
 .../demo/runtime/src/runtime/democracy.rs     | 82 ++++++++++++++++++-
 1 file changed, 79 insertions(+), 3 deletions(-)

diff --git a/substrate/demo/runtime/src/runtime/democracy.rs b/substrate/demo/runtime/src/runtime/democracy.rs
index 5c0db6a3e50..af265e79790 100644
--- a/substrate/demo/runtime/src/runtime/democracy.rs
+++ b/substrate/demo/runtime/src/runtime/democracy.rs
@@ -350,9 +350,6 @@ mod tests {
 
 	// TODO: test VoteThreshold
 
-	// fn proposal_with_deposit_below_minimum_should_panic()
-	// fn poor_seconder_should_panic()
-
 	#[test]
 	fn locked_for_should_work() {
 		let alice = Keyring::Alice.to_raw_public();
@@ -395,6 +392,85 @@ mod tests {
 		});
 	}
 
+	#[test]
+	fn deposit_for_proposals_should_be_taken() {
+		let alice = Keyring::Alice.to_raw_public();
+		let bob = Keyring::Bob.to_raw_public();
+		let eve = Keyring::Eve.to_raw_public();
+		let mut t = new_test_ext();
+
+		with_externalities(&mut t, || {
+			with_env(|e| e.block_number = 1);
+			public::propose(&alice, &Proposal::StakingSetSessionsPerEra(2), 5u64);
+			public::second(&bob, 0);
+			public::second(&eve, 0);
+			public::second(&eve, 0);
+			public::second(&eve, 0);
+			assert_eq!(staking::balance(&alice), 5u64);
+			assert_eq!(staking::balance(&bob), 15u64);
+			assert_eq!(staking::balance(&eve), 35u64);
+		});
+	}
+
+	#[test]
+	fn deposit_for_proposals_should_be_returned() {
+		let alice = Keyring::Alice.to_raw_public();
+		let bob = Keyring::Bob.to_raw_public();
+		let eve = Keyring::Eve.to_raw_public();
+		let mut t = new_test_ext();
+
+		with_externalities(&mut t, || {
+			with_env(|e| e.block_number = 1);
+			public::propose(&alice, &Proposal::StakingSetSessionsPerEra(2), 5u64);
+			public::second(&bob, 0);
+			public::second(&eve, 0);
+			public::second(&eve, 0);
+			public::second(&eve, 0);
+			democracy::internal::end_block();
+			assert_eq!(staking::balance(&alice), 10u64);
+			assert_eq!(staking::balance(&bob), 20u64);
+			assert_eq!(staking::balance(&eve), 50u64);
+		});
+	}
+
+	#[test]
+	#[should_panic]
+	fn proposal_with_deposit_below_minimum_should_panic() {
+		let alice = Keyring::Alice.to_raw_public();
+		let mut t = new_test_ext();
+
+		with_externalities(&mut t, || {
+			with_env(|e| e.block_number = 1);
+			public::propose(&alice, &Proposal::StakingSetSessionsPerEra(2), 0u64);
+		});
+	}
+
+	#[test]
+	#[should_panic]
+	fn poor_proposer_should_panic() {
+		let alice = Keyring::Alice.to_raw_public();
+		let mut t = new_test_ext();
+
+		with_externalities(&mut t, || {
+			with_env(|e| e.block_number = 1);
+			public::propose(&alice, &Proposal::StakingSetSessionsPerEra(2), 11u64);
+		});
+	}
+
+	#[test]
+	#[should_panic]
+	fn poor_seconder_should_panic() {
+		let alice = Keyring::Alice.to_raw_public();
+		let bob = Keyring::Bob.to_raw_public();
+		let mut t = new_test_ext();
+
+		with_externalities(&mut t, || {
+			with_env(|e| e.block_number = 1);
+			public::propose(&bob, &Proposal::StakingSetSessionsPerEra(2), 11u64);
+			public::second(&alice, 0);
+		});
+	}
+
 	#[test]
 	fn runners_up_should_come_after() {
 		let alice = Keyring::Alice.to_raw_public();
-- 
GitLab