mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities` - `Externalities` now support generic extensions - Split of `primtives-storage` for storage primitive types * Move the externalities scoping into `substrate-externalities` * Fix compilation * Review feedback * Adds macro for declaring extensions * Fix benchmarks * Introduce `ExtensionStore` trait * Last review comments * Implement it for `ExtensionStore`
This commit is contained in:
@@ -355,13 +355,11 @@ impl<T: Trait> OnDilution<BalanceOf<T>> for Module<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::with_externalities;
|
||||
use support::{assert_noop, assert_ok, impl_outer_origin, parameter_types};
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use primitives::H256;
|
||||
use sr_primitives::{
|
||||
traits::{BlakeTwo256, OnFinalize, IdentityLookup},
|
||||
testing::Header,
|
||||
assert_eq_error_rate,
|
||||
traits::{BlakeTwo256, OnFinalize, IdentityLookup}, set_and_run_with_externalities,
|
||||
testing::Header, assert_eq_error_rate,
|
||||
};
|
||||
|
||||
impl_outer_origin! {
|
||||
@@ -437,7 +435,7 @@ mod tests {
|
||||
type Balances = balances::Module<Test>;
|
||||
type Treasury = Module<Test>;
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
balances::GenesisConfig::<Test>{
|
||||
balances: vec![(0, 100), (1, 99), (2, 1)],
|
||||
@@ -448,7 +446,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn genesis_config_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(Treasury::pot(), 0);
|
||||
assert_eq!(Treasury::proposal_count(), 0);
|
||||
});
|
||||
@@ -456,7 +454,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn minting_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
Treasury::on_dilution(100, 100);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
@@ -467,7 +465,7 @@ mod tests {
|
||||
fn minting_works_2() {
|
||||
let tests = [(1, 10), (1, 20), (40, 130), (2, 66), (2, 67), (2, 100), (2, 101), (2, 134)];
|
||||
for &(minted, portion) in &tests {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
let init_total_issuance = Balances::total_issuance();
|
||||
Treasury::on_dilution(minted, portion);
|
||||
|
||||
@@ -491,7 +489,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn spend_proposal_takes_min_deposit() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
|
||||
assert_eq!(Balances::free_balance(&0), 99);
|
||||
assert_eq!(Balances::reserved_balance(&0), 1);
|
||||
@@ -500,7 +498,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn spend_proposal_takes_proportional_deposit() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_eq!(Balances::free_balance(&0), 95);
|
||||
assert_eq!(Balances::reserved_balance(&0), 5);
|
||||
@@ -509,14 +507,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn spend_proposal_fails_when_proposer_poor() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_noop!(Treasury::propose_spend(Origin::signed(2), 100, 3), "Proposer's balance too low");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepted_spend_proposal_ignored_outside_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
@@ -530,7 +528,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn unused_pot_should_diminish() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
let init_total_issuance = Balances::total_issuance();
|
||||
Treasury::on_dilution(100, 100);
|
||||
assert_eq!(Balances::total_issuance(), init_total_issuance + 100);
|
||||
@@ -543,7 +541,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rejected_spend_proposal_ignored_on_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
@@ -557,7 +555,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reject_already_rejected_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
@@ -568,21 +566,21 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reject_non_existant_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0), "No proposal at that index");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accept_non_existant_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0), "No proposal at that index");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accept_already_rejected_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
@@ -593,7 +591,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn accepted_spend_proposal_enacted_on_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
@@ -608,7 +606,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn pot_underflow_should_not_diminish() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
|
||||
|
||||
Reference in New Issue
Block a user