From 7c4e258f13b46ff0cdf90bca0fd91adba3d0a23e Mon Sep 17 00:00:00 2001 From: hammeWang Date: Wed, 24 Jul 2019 14:28:43 +0800 Subject: [PATCH] add kton storage initialization --- Cargo.lock | 8 +++ node/cli/src/chain_spec.rs | 12 ++-- srml/kton/Cargo.toml | 3 +- srml/kton/src/lib.rs | 94 ++++++++++++++----------------- srml/kton/src/mock.rs | 8 ++- srml/kton/src/tests.rs | 25 +++++++-- srml/staking/src/lib.rs | 4 +- srml/staking/src/mock.rs | 5 +- srml/staking/src/tests.rs | 5 ++ srml/try/Cargo.toml | 13 +++++ srml/try/src/finality_tests.rs | 100 +++++++++++++++++++++++++++++++++ srml/try/src/lib.rs | 9 ++- srml/try/src/tests.rs | 13 ++++- 13 files changed, 227 insertions(+), 72 deletions(-) create mode 100644 srml/try/src/finality_tests.rs diff --git a/Cargo.lock b/Cargo.lock index 967bf601d..b13fc4f3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4903,8 +4903,16 @@ dependencies = [ "sr-io 2.0.0 (git+https://github.com/paritytech/substrate.git)", "sr-primitives 2.0.0 (git+https://github.com/paritytech/substrate.git)", "sr-std 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-authorship 0.1.0 (git+https://github.com/paritytech/substrate.git)", + "srml-balances 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-executive 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-finality-tracker 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-grandpa 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-indices 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-session 2.0.0 (git+https://github.com/paritytech/substrate.git)", "srml-support 2.0.0 (git+https://github.com/paritytech/substrate.git)", "srml-system 2.0.0 (git+https://github.com/paritytech/substrate.git)", + "srml-timestamp 2.0.0 (git+https://github.com/paritytech/substrate.git)", "substrate-keyring 2.0.0 (git+https://github.com/paritytech/substrate.git)", "substrate-primitives 2.0.0 (git+https://github.com/paritytech/substrate.git)", ] diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index acd13a68b..d5db35409 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -109,9 +109,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig { vesting: vec![], }), kton: Some(KtonConfig { - balances: endowed_accounts.iter().cloned() - .map(|k| (k, ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT))) + ring_balances: endowed_accounts.iter().cloned() + .map(|k| (k, ENDOWMENT, 12)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT, 12))) .collect(), vesting: vec![], sys_acc: hex!["984d592d15d930ac36e6716407fbed3f7d1e2e62bc11f8429345f8b8b0dfc107"].unchecked_into(), @@ -242,9 +242,9 @@ pub fn testnet_genesis( vesting: vec![], }), kton: Some(KtonConfig { - balances: endowed_accounts.iter().cloned() - .map(|k| (k, ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT))) + ring_balances: endowed_accounts.iter().cloned() + .map(|k| (k, ENDOWMENT, 12)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT, 12))) .collect(), vesting: vec![], sys_acc: hex!["984d592d15d930ac36e6716407fbed3f7d1e2e62bc11f8429345f8b8b0dfc107"].unchecked_into(), diff --git a/srml/kton/Cargo.toml b/srml/kton/Cargo.toml index 64980f474..f8907b15d 100644 --- a/srml/kton/Cargo.toml +++ b/srml/kton/Cargo.toml @@ -16,9 +16,9 @@ system = { package = "srml-system", git = 'https://github.com/paritytech/substra timestamp = { package = "srml-timestamp", git = 'https://github.com/paritytech/substrate.git', default-features = false } substrate-primitives = { git = 'https://github.com/paritytech/substrate.git', default-features = false } dsupport = { package = "evo-support", path = "../support", default-features = false } +runtime_io = { package = "sr-io", git = 'https://github.com/paritytech/substrate.git' } [dev-dependencies] -runtime_io = { package = "sr-io", git = 'https://github.com/paritytech/substrate.git' } substrate-primitives = { git = 'https://github.com/paritytech/substrate.git' } balances = { package = "srml-balances", git = 'https://github.com/paritytech/substrate.git' } node-runtime = { path = "../../node/runtime" } @@ -36,5 +36,6 @@ std = [ "system/std", "timestamp/std", "substrate-primitives/std", + "runtime_io/std", "dsupport/std", ] diff --git a/srml/kton/src/lib.rs b/srml/kton/src/lib.rs index 69118470c..fbcba5597 100644 --- a/srml/kton/src/lib.rs +++ b/srml/kton/src/lib.rs @@ -2,13 +2,12 @@ use parity_codec::{Codec, Decode, Encode}; use primitives::traits::{ - CheckedAdd, CheckedSub, MaybeSerializeDebug, Member, Saturating, SimpleArithmetic, - StaticLookup, Zero, Bounded + Bounded, CheckedAdd, CheckedSub, MaybeSerializeDebug, Member, Saturating, + SimpleArithmetic, StaticLookup, Zero, }; - +use rstd::{cmp, convert::{TryFrom, TryInto}, result}; use rstd::prelude::*; -use rstd::{cmp, result, convert::{ TryInto, TryFrom}}; -use srml_support::{decl_event, decl_module, decl_storage, Parameter, StorageMap, StorageValue, ensure}; +use srml_support::{decl_event, decl_module, decl_storage, ensure, Parameter, StorageMap, StorageValue}; use srml_support::dispatch::Result; use srml_support::traits::{ Currency, ExistenceRequirement, Imbalance, LockableCurrency, LockIdentifier, @@ -18,11 +17,14 @@ use srml_support::traits::{ use substrate_primitives::U256; use system::ensure_signed; +#[cfg(feature = "std")] +use runtime_io::with_storage; + // customed use dsupport::traits::SystemCurrency; -mod imbalance; use imbalance::{NegativeImbalance, PositiveImbalance}; +mod imbalance; mod mock; mod tests; @@ -141,11 +143,9 @@ decl_storage! { // like `existential_deposit`, but always set to 0 pub MinimumBalance get(minimum_balance): T::Balance = 0.into(); - pub TotalIssuance get(total_issuance) build(|config: &GenesisConfig| { - config.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n) - }): T::Balance; + pub TotalIssuance get(total_issuance) : T::Balance; - pub FreeBalance get(free_balance) build(|config: &GenesisConfig| config.balances.clone()): map T::AccountId => T::Balance; + pub FreeBalance get(free_balance) : map T::AccountId => T::Balance; pub ReservedBalance get(reserved_balance): map T::AccountId => T::Balance; @@ -153,29 +153,30 @@ decl_storage! { pub TotalLock get(total_lock): T::Balance; - pub Vesting get(vesting) build(|config: &GenesisConfig| { - config.vesting.iter().filter_map(|&(ref who, begin, length)| { - let begin = >::from(begin); - let length = >::from(length); - - config.balances.iter() - .find(|&&(ref w, _)| w == who) - .map(|&(_, balance)| { - // <= begin it should be >= balance - // >= begin+length it should be <= 0 - - let per_block = balance / length.max(primitives::traits::One::one()); - let offset = begin * per_block + balance; - - (who.clone(), VestingSchedule { offset, per_block }) - }) - }).collect::>() - }): map T::AccountId => Option>; + pub Vesting get(vesting): map T::AccountId => Option>; } add_extra_genesis { - config(balances): Vec<(T::AccountId, T::Balance)>; - config(vesting): Vec<(T::AccountId, T::BlockNumber, T::BlockNumber)>; - } + // for ring + config(ring_balances): Vec<(T::AccountId, CurrencyOf, u32)>; + config(vesting): Vec <(T::AccountId, T::BlockNumber, T::BlockNumber)>; + build( | + storage: & mut primitives::StorageOverlay, + _: & mut primitives::ChildrenStorageOverlay, + config: & GenesisConfig + | { + with_storage(storage, || { + for &(ref depositor, balance, months) in &config.ring_balances { + assert!(T::Currency::free_balance(&depositor) >= balance); + let _ = >::deposit( + T::Origin::from(Some(depositor.clone()).into()), + balance, + months + ); + + } + }); + }); + } } decl_module! { @@ -259,7 +260,6 @@ decl_module! { } impl Module { - fn update_deposit(who: &T::AccountId, deposit: &Deposit, T::Balance, T::Moment>) { T::Currency::set_lock( DEPOSIT_ID, @@ -267,7 +267,7 @@ impl Module { deposit.total, // u32::max_value().into(), T::BlockNumber::max_value(), - WithdrawReasons::all() + WithdrawReasons::all(), ); >::insert(who, deposit); } @@ -275,7 +275,7 @@ impl Module { fn convert_to_paid_out(value: T::Balance) -> CurrencyOf { let value: u64 = value.try_into().unwrap_or_default() as u64; - let additional_reward_paid_out: CurrencyOf = Self::reward_per_share() * value.try_into().unwrap_or_default(); + let additional_reward_paid_out: CurrencyOf = Self::reward_per_share() * value.try_into().unwrap_or_default(); additional_reward_paid_out } @@ -285,7 +285,7 @@ impl Module { if !months.is_zero() { let no = U256::from(67_u128).pow(U256::from(months)); - let de = U256::from(66_u128). pow(U256::from(months)); + let de = U256::from(66_u128).pow(U256::from(months)); let quotient = no / de; let remainder = no % de; @@ -295,7 +295,6 @@ impl Module { } else { None } - } pub fn vesting_balance(who: &T::AccountId) -> T::Balance { @@ -374,7 +373,7 @@ impl Currency for Module { } let locks = Self::locks(who); if locks.is_empty() { - return Ok(()) + return Ok(()); } let now = >::block_number(); @@ -394,7 +393,6 @@ impl Currency for Module { // TODO: add fee fn transfer(transactor: &T::AccountId, dest: &T::AccountId, value: Self::Balance) -> Result { - let from_balance = Self::free_balance(transactor); let to_balance = Self::free_balance(dest); @@ -416,7 +414,7 @@ impl Currency for Module { // settle transactor reward let from_should_withdraw = Self::convert_to_paid_out(value); #[cfg(test)] - runtime_io::print(from_should_withdraw.try_into().unwrap_or_default() as u64); + runtime_io::print(from_should_withdraw.try_into().unwrap_or_default() as u64); Self::update_reward_paid_out(transactor, from_should_withdraw, true); // settle dest reward Self::update_reward_paid_out(dest, from_should_withdraw, false); @@ -424,7 +422,7 @@ impl Currency for Module { Self::set_free_balance(transactor, new_from_balance); Self::set_free_balance(dest, new_to_balance); - Self::deposit_event(RawEvent:: TokenTransfer(transactor.clone(), dest.clone(), value)); + Self::deposit_event(RawEvent::TokenTransfer(transactor.clone(), dest.clone(), value)); } Ok(()) @@ -439,7 +437,7 @@ impl Currency for Module { ) -> result::Result { if let Some(new_balance) = Self::free_balance(who).checked_sub(&value) { if liveness == ExistenceRequirement::KeepAlive && new_balance < Self::minimum_balance() { - return Err("payment would kill account") + return Err("payment would kill account"); } let additional_reward_paid_out = Self::convert_to_paid_out(value); Self::update_reward_paid_out(who, additional_reward_paid_out, true); @@ -450,13 +448,12 @@ impl Currency for Module { } else { Err("too few free funds in account") } - } fn slash( who: &T::AccountId, - value: Self::Balance + value: Self::Balance, ) -> (Self::NegativeImbalance, Self::Balance) { let free_balance = Self::free_balance(who); let free_slash = cmp::min(free_balance, value); @@ -479,7 +476,7 @@ impl Currency for Module { fn deposit_into_existing( who: &T::AccountId, - value: Self::Balance + value: Self::Balance, ) -> result::Result { if Self::total_balance(who).is_zero() { return Err("beneficiary account must pre-exist"); @@ -494,7 +491,6 @@ impl Currency for Module { who: &T::AccountId, value: Self::Balance, ) -> Self::PositiveImbalance { - let (imbalance, _) = Self::make_free_balance_be(who, Self::free_balance(who) + value); if let SignedImbalance::Positive(p) = imbalance { @@ -553,7 +549,6 @@ impl Currency for Module { ); NegativeImbalance::new(amount) } - } @@ -659,14 +654,13 @@ impl SystemCurrency> for Module { fn reward_can_withdraw(who: &T::AccountId) -> CurrencyOf { let free_balance = Self::free_balance(who); let max_should_withdraw = Self::convert_to_paid_out(free_balance); - let max_should_withdraw: u64 = max_should_withdraw.try_into().unwrap_or_default() as u64; + let max_should_withdraw: u64 = max_should_withdraw.try_into().unwrap_or_default() as u64; let should_withdraw = i128::from(max_should_withdraw) - Self::reward_paid_out(who); if should_withdraw <= 0 { 0.into() } else { u64::try_from(should_withdraw).unwrap_or_default().try_into().unwrap_or_default() } - } /// pay system fee with reward @@ -674,7 +668,6 @@ impl SystemCurrency> for Module { who: &T::AccountId, value: CurrencyOf) -> result::Result<(Self::NegativeImbalanceOf, Self::NegativeImbalanceOf), &'static str> { - let can_withdraw_value = Self::reward_can_withdraw(who); let mut system_imbalance = Self::NegativeImbalanceOf::zero(); @@ -702,9 +695,6 @@ impl SystemCurrency> for Module { } Ok((system_imbalance, acc_imbalance)) - } - - } diff --git a/srml/kton/src/mock.rs b/srml/kton/src/mock.rs index 706e61a21..be56b28fc 100644 --- a/srml/kton/src/mock.rs +++ b/srml/kton/src/mock.rs @@ -182,10 +182,14 @@ impl ExtBuilder { let _ = GenesisConfig:: { sys_acc: 42, - balances: vec![], + ring_balances: vec![ + (1, 10 * balance_factor, 12), + (2, 20 * balance_factor, 12), + (3, 300 * balance_factor, 12), + (4, 400 * balance_factor, 12), + ], vesting: vec![], }.assimilate_storage(&mut t, &mut c); - t.into() } diff --git a/srml/kton/src/tests.rs b/srml/kton/src/tests.rs index ade1a8a5e..555ea5a99 100644 --- a/srml/kton/src/tests.rs +++ b/srml/kton/src/tests.rs @@ -29,6 +29,21 @@ fn deposit_with_decimals_pre() { Kton::deposit(Origin::signed(21), 1_000_000_000 * COIN, 36); } +#[test] +fn build_genesis_storage_should_work() { + with_externalities(&mut ExtBuilder::default() + .existential_deposit(1).build(), || { + + assert_eq!(Kton::free_balance(&1), 1 * COIN); + assert_eq!(Kton::free_balance(&2), 2 * COIN); + assert_eq!(Kton::free_balance(&3), 30 * COIN); + assert_eq!(Kton::free_balance(&4), 40 * COIN); + + assert_eq!(Kton::total_issuance(), (40 + 30 + 2 + 1) * COIN); + }); + +} + #[test] fn ext_builer_should_work() { // test existential_deposit setting @@ -79,11 +94,12 @@ fn reward_per_share_not_zero() { // acc 91 and 92 deposit 10k ring for 12 months // in return, acc 91 and 92 will get 1 kton + let old_total_issuance = Kton::total_issuance(); Kton::deposit(Origin::signed(91), 10_000 * COIN, 12); Kton::deposit(Origin::signed(92), 10_000 * COIN, 12); - assert_eq!(Kton::total_issuance(), 2 * COIN); + assert_eq!(Kton::total_issuance(), old_total_issuance + 2 * COIN); - Kton::reward_to_pot(6000 * COIN); + Kton::reward_to_pot(225000 * COIN); assert_eq!(Kton::reward_per_share(), 3000); } @@ -124,8 +140,9 @@ fn transfer_should_work() { // new things happen! // reward_per_share now change to - Kton::reward_to_pot(3000 * COIN); - assert_eq!(Ring::free_balance(&Kton::sys_acc()), 9000 * COIN); + assert_eq!(Kton::total_issuance(), 76 * COIN); + Kton::reward_to_pot(76000 * COIN); + assert_eq!(Ring::free_balance(&Kton::sys_acc()), 301000 * COIN); assert_eq!(Kton::reward_per_share(), 4000); assert_eq!(Kton::reward_can_withdraw(&93), 1000 * COIN); diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index 6d2396ddf..b84580f9c 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -374,6 +374,8 @@ decl_storage! { if let (_, Some(validators)) = >::select_validators() { >::put(&validators); + // initialize current_elected + >::put(&validators); } }); }); @@ -604,7 +606,7 @@ impl Module { // exposure) let slash = slash.min(exposure.total); // The amount we'll slash from the validator's stash directly. - let mut own_slash = exposure.own.min(slash); + let own_slash = exposure.own.min(slash); // // customed // // for validator, first slash bonded value diff --git a/srml/staking/src/mock.rs b/srml/staking/src/mock.rs index aec3dea60..517ce76fb 100644 --- a/srml/staking/src/mock.rs +++ b/srml/staking/src/mock.rs @@ -137,7 +137,7 @@ parameter_types! { pub const COIN: u64 = 1_000_000_000; parameter_types! { // decimal 9 - pub const CAP: Balance = 10_000_000_000_000 * COIN; + pub const CAP: Balance = 10_000_000_000 * COIN; } @@ -225,7 +225,8 @@ impl ExtBuilder { let validators = if self.validator_pool { vec![10, 20, 30, 40] } else { vec![10, 20] }; let _ = session::GenesisConfig::{ // NOTE: if config.nominate == false then 100 is also selected in the initial round. - validators, +// validators, + validators: vec![], keys: vec![], }.assimilate_storage(&mut t, &mut c); let _ = balances::GenesisConfig::{ diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index b86a0b64d..64d21aeea 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -50,6 +50,11 @@ fn test_env_build() { build_basic_env(); check_exposure_all(); + + System::set_block_number(1); + Session::on_initialize(System::block_number()); + assert_eq!(Session::validators(), vec![10, 20]); + assert_eq!(Staking::current_elected(), vec![10, 20]); }); } diff --git a/srml/try/Cargo.toml b/srml/try/Cargo.toml index 7c53ca4f9..a99584636 100644 --- a/srml/try/Cargo.toml +++ b/srml/try/Cargo.toml @@ -19,6 +19,19 @@ support = { package = "srml-support", git = "https://github.com/paritytech/subst system = { package = "srml-system", git = "https://github.com/paritytech/substrate", default-features = false } sr-io = { git = "https://github.com/paritytech/substrate", default-features = false } +[dev-dependencies] +support = { package = "srml-support", git = 'https://github.com/paritytech/substrate.git' } +balances = { package = "srml-balances", git = 'https://github.com/paritytech/substrate.git' } +executive = { package = "srml-executive", git = 'https://github.com/paritytech/substrate.git' } +authorship = { package = "srml-authorship", git = 'https://github.com/paritytech/substrate.git' } +finality-tracker = { package = "srml-finality-tracker", git = 'https://github.com/paritytech/substrate.git' } +grandpa = { package = "srml-grandpa", git = 'https://github.com/paritytech/substrate.git' } +indices = { package = "srml-indices", git = 'https://github.com/paritytech/substrate.git' } +session = { package = "srml-session", git = 'https://github.com/paritytech/substrate.git' } +system = { package = "srml-system", git = 'https://github.com/paritytech/substrate.git' } +timestamp = { package = "srml-timestamp", git = 'https://github.com/paritytech/substrate.git' } +sr-primitives = { git = 'https://github.com/paritytech/substrate.git' } + [features] default = ["std"] diff --git a/srml/try/src/finality_tests.rs b/srml/try/src/finality_tests.rs new file mode 100644 index 000000000..36f8fd3ee --- /dev/null +++ b/srml/try/src/finality_tests.rs @@ -0,0 +1,100 @@ + +#![cfg(test)] +use sr_io::{with_externalities, TestExternalities}; +use primitives::H256; +use sr_primitives::traits::{BlakeTwo256, IdentityLookup, OnFinalize, Header as HeaderT}; +use sr_primitives::testing::Header; +use support::{assert_ok, impl_outer_origin, parameter_types}; +use std::cell::RefCell; +use finality_tracker::*; + +#[derive(Clone, PartialEq, Debug)] +pub struct StallEvent { + at: u64, + further_wait: u64, +} + +#[derive(Clone, Eq, PartialEq)] +pub struct Test; + +impl_outer_origin! { + pub enum Origin for Test {} + } + +thread_local! { + static NOTIFICATIONS: RefCell> = Default::default(); + } + +pub struct StallTracker; +impl OnFinalizationStalled for StallTracker { + fn on_stalled(further_wait: u64, _median: u64) { + let now = System::block_number(); + NOTIFICATIONS.with(|v| v.borrow_mut().push(StallEvent { at: now, further_wait })); + } +} + + +impl system::Trait for Test { + type Origin = Origin; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type Event = (); +} +parameter_types! { + pub const WindowSize: u64 = 11; + pub const ReportLatency: u64 = 100; + } +impl finality_tracker::Trait for Test { + type OnFinalizationStalled = StallTracker; + type WindowSize = WindowSize; + type ReportLatency = ReportLatency; +} + +type System = system::Module; +type FinalityTracker = finality_tracker::Module; + + + +#[test] +fn notifies_when_stalled() { + let t = system::GenesisConfig::default().build_storage::().unwrap().0; + with_externalities(&mut TestExternalities::new(t), || { + let mut parent_hash = System::parent_hash(); + for i in 2..106 { + System::initialize(&i, &parent_hash, &Default::default(), &Default::default()); + FinalityTracker::on_finalize(i); + let hdr = System::finalize(); + parent_hash = hdr.hash(); + } + + assert_eq!( + NOTIFICATIONS.with(|n| n.borrow().clone()), + vec![StallEvent { at: 105, further_wait: 10 }] + ) + }); +} + +#[test] +fn recent_notifications_prevent_stalling() { + let t = system::GenesisConfig::default().build_storage::().unwrap().0; + with_externalities(&mut TestExternalities::new(t), || { + let mut parent_hash = System::parent_hash(); + for i in 2..106 { + System::initialize(&i, &parent_hash, &Default::default(), &Default::default()); + assert_ok!(FinalityTracker::dispatch( + Call::final_hint(i-1), + Origin::NONE, + )); + FinalityTracker::on_finalize(i); + let hdr = System::finalize(); + parent_hash = hdr.hash(); + } + + assert!(NOTIFICATIONS.with(|n| n.borrow().is_empty())); + }); +} diff --git a/srml/try/src/lib.rs b/srml/try/src/lib.rs index 752661e7d..b3900057f 100644 --- a/srml/try/src/lib.rs +++ b/srml/try/src/lib.rs @@ -3,12 +3,16 @@ // DONE: test initial value in Store // DONE: test Option value in Store // DONE: test visibility of functions in `decl_module!` and `impl Module` block +// DONE: check the priority between configs set in chain_spec or in module + // TODO: test difference between dispatch::Result & rstd::result::Result -// TODO: check the priority between configs set in chain_spec or in module // TODO: try out add_extra_genesis // TODO: check tests in executor + +//! Tests in `try` mod is to test origin-module in SRML + #![cfg_attr(not(feature = "std"), no_std)] use rstd::{cmp, result}; @@ -18,6 +22,7 @@ use support::dispatch::Result; use system::ensure_signed; mod tests; +mod finality_tests; pub trait Trait: system::Trait { /// The overarching event type. @@ -32,7 +37,7 @@ decl_event!( decl_storage! { trait Store for Module as TemplateModule { - SomeOption get(someoption) config(): Option; + SomeOption get(some_option) config(): Option = Some(1); Something get(something): u32; MapOption get(map_option): map u32 => Option; Map get(map): map u32 => T::AccountId; diff --git a/srml/try/src/tests.rs b/srml/try/src/tests.rs index 76aa7f5af..ea93cdd96 100644 --- a/srml/try/src/tests.rs +++ b/srml/try/src/tests.rs @@ -59,7 +59,7 @@ type Try = Module; fn new_test_ext() -> sr_io::TestExternalities { let mut t = system::GenesisConfig::default().build_storage::().unwrap().0; t.extend(GenesisConfig { - someoption: 42, + some_option: 42, }.build_storage().unwrap().0); t.into() @@ -70,7 +70,7 @@ fn it_works_for_default_value() { with_externalities(&mut new_test_ext(), || { assert_eq!(Try::something(), 0); - assert_eq!(Try::someoption(), Some(42)); + assert_eq!(Try::some_option(), Some(42)); }); } @@ -100,4 +100,13 @@ fn check_delete() { Try::update_list(2, true); assert_eq!(Try::list(1), vec![1, 2]); }); +} + +#[test] +fn check_genesis_privilege() { + with_externalities(&mut new_test_ext(), || { + assert_eq!(Try::some_option(), Some(42)); + SomeOption::kill(); + assert_eq!(Try::some_option(), Some(1)); + }); } \ No newline at end of file