mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 15:07:59 +00:00
Democracy weight (#5828)
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The for various partial storage decoders
|
||||
|
||||
use super::*;
|
||||
use frame_support::storage::{migration, StorageMap, unhashed};
|
||||
|
||||
#[test]
|
||||
fn test_decode_compact_u32_at() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let v = codec::Compact(u64::max_value());
|
||||
migration::put_storage_value(b"test", b"", &[], v);
|
||||
assert_eq!(decode_compact_u32_at(b"test"), None);
|
||||
|
||||
for v in vec![0, 10, u32::max_value()] {
|
||||
let compact_v = codec::Compact(v);
|
||||
unhashed::put(b"test", &compact_v);
|
||||
assert_eq!(decode_compact_u32_at(b"test"), Some(v));
|
||||
}
|
||||
|
||||
unhashed::kill(b"test");
|
||||
assert_eq!(decode_compact_u32_at(b"test"), None);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn len_of_deposit_of() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for l in vec![0, 1, 200, 1000] {
|
||||
let value: (Vec<u64>, u64) = ((0..l).map(|_| Default::default()).collect(), 3u64);
|
||||
DepositOf::<Test>::insert(2, value);
|
||||
assert_eq!(Democracy::len_of_deposit_of(2), Some(l));
|
||||
}
|
||||
|
||||
DepositOf::<Test>::remove(2);
|
||||
assert_eq!(Democracy::len_of_deposit_of(2), None);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_image() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let key = Default::default();
|
||||
let missing = PreimageStatus::Missing(0);
|
||||
Preimages::<Test>::insert(key, missing);
|
||||
assert!(Democracy::pre_image_data_len(key).is_err());
|
||||
assert_eq!(Democracy::check_pre_image_is_missing(key), Ok(()));
|
||||
|
||||
Preimages::<Test>::remove(key);
|
||||
assert!(Democracy::pre_image_data_len(key).is_err());
|
||||
assert!(Democracy::check_pre_image_is_missing(key).is_err());
|
||||
|
||||
for l in vec![0, 10, 100, 1000u32] {
|
||||
let available = PreimageStatus::Available{
|
||||
data: (0..l).map(|i| i as u8).collect(),
|
||||
provider: 0,
|
||||
deposit: 0,
|
||||
since: 0,
|
||||
expiry: None,
|
||||
};
|
||||
|
||||
Preimages::<Test>::insert(key, available);
|
||||
assert_eq!(Democracy::pre_image_data_len(key), Ok(l));
|
||||
assert!(Democracy::check_pre_image_is_missing(key).is_err());
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The tests for migration.
|
||||
|
||||
use super::*;
|
||||
use frame_support::{storage::migration, Hashable, traits::OnRuntimeUpgrade};
|
||||
use substrate_test_utils::assert_eq_uvec;
|
||||
|
||||
#[test]
|
||||
fn migration() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for i in 0..3 {
|
||||
let k = i.twox_64_concat();
|
||||
let v: (BalanceOf<Test>, Vec<u64>) = (i * 1000, vec![i]);
|
||||
migration::put_storage_value(b"Democracy", b"DepositOf", &k, v);
|
||||
}
|
||||
StorageVersion::kill();
|
||||
|
||||
Democracy::on_runtime_upgrade();
|
||||
|
||||
assert_eq!(StorageVersion::get(), Some(Releases::V1));
|
||||
assert_eq_uvec!(
|
||||
DepositOf::<Test>::iter().collect::<Vec<_>>(),
|
||||
vec![
|
||||
(0, (vec![0u64], <BalanceOf<Test>>::from(0u32))),
|
||||
(1, (vec![1u64], <BalanceOf<Test>>::from(1000u32))),
|
||||
(2, (vec![2u64], <BalanceOf<Test>>::from(2000u32))),
|
||||
]
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -77,11 +77,11 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
|
||||
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2)),
|
||||
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2)));
|
||||
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()));
|
||||
|
||||
assert_eq!(Balances::free_balance(6), 60);
|
||||
assert_eq!(Balances::reserved_balance(6), 0);
|
||||
@@ -92,7 +92,7 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
|
||||
fn preimage_deposit_should_be_reapable() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2)),
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()),
|
||||
Error::<Test>::PreimageMissing
|
||||
);
|
||||
|
||||
@@ -104,12 +104,12 @@ fn preimage_deposit_should_be_reapable() {
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2)),
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2)));
|
||||
assert_ok!(Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()));
|
||||
assert_eq!(Balances::reserved_balance(6), 0);
|
||||
assert_eq!(Balances::free_balance(6), 48);
|
||||
assert_eq!(Balances::free_balance(5), 62);
|
||||
@@ -153,6 +153,6 @@ fn reaping_imminent_preimage_should_fail() {
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(Democracy::reap_preimage(Origin::signed(6), h), Error::<Test>::Imminent);
|
||||
assert_noop!(Democracy::reap_preimage(Origin::signed(6), h, u32::max_value()), Error::<Test>::Imminent);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ fn backing_for_should_work() {
|
||||
fn deposit_for_proposals_should_be_taken() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
assert_eq!(Balances::free_balance(1), 5);
|
||||
assert_eq!(Balances::free_balance(2), 15);
|
||||
assert_eq!(Balances::free_balance(5), 35);
|
||||
@@ -49,10 +49,10 @@ fn deposit_for_proposals_should_be_taken() {
|
||||
fn deposit_for_proposals_should_be_returned() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
|
||||
fast_forward_to(3);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
@@ -78,7 +78,21 @@ fn poor_proposer_should_not_work() {
|
||||
fn poor_seconder_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(2, 2, 11));
|
||||
assert_noop!(Democracy::second(Origin::signed(1), 0), BalancesError::<Test, _>::InsufficientBalance);
|
||||
assert_noop!(
|
||||
Democracy::second(Origin::signed(1), 0, u32::max_value()),
|
||||
BalancesError::<Test, _>::InsufficientBalance
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_seconds_upper_bound_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_noop!(
|
||||
Democracy::second(Origin::signed(2), 0, 0),
|
||||
Error::<Test>::WrongUpperBound
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user