Skip to content

Commit

Permalink
close #48
Browse files Browse the repository at this point in the history
  • Loading branch information
sekisamu committed Jul 26, 2019
1 parent d9e464d commit aea03eb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 55 deletions.
12 changes: 6 additions & 6 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
vesting: vec![],
}),
kton: Some(KtonConfig {
ring_balances: endowed_accounts.iter().cloned()
.map(|k| (k, ENDOWMENT, 12))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT, 12)))
balances: endowed_accounts.iter().cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
vesting: vec![],
sys_acc: hex!["984d592d15d930ac36e6716407fbed3f7d1e2e62bc11f8429345f8b8b0dfc107"].unchecked_into(),
Expand Down Expand Up @@ -242,9 +242,9 @@ pub fn testnet_genesis(
vesting: vec![],
}),
kton: Some(KtonConfig {
ring_balances: endowed_accounts.iter().cloned()
.map(|k| (k, ENDOWMENT, 12))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT, 12)))
balances: endowed_accounts.iter().cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
vesting: vec![],
sys_acc: hex!["984d592d15d930ac36e6716407fbed3f7d1e2e62bc11f8429345f8b8b0dfc107"].unchecked_into(),
Expand Down
1 change: 0 additions & 1 deletion node/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions srml/kton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ 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', default-features = false }


[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" }
Expand All @@ -36,6 +37,5 @@ std = [
"system/std",
"timestamp/std",
"substrate-primitives/std",
"runtime_io/std",
"dsupport/std",
]
58 changes: 29 additions & 29 deletions srml/kton/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use primitives::traits::{
};
use rstd::{cmp, convert::{TryFrom, TryInto}, result};
use rstd::prelude::*;

use srml_support::{decl_event, decl_module, decl_storage, ensure, Parameter, StorageMap, StorageValue};
use srml_support::dispatch::Result;
use srml_support::traits::{
Expand All @@ -17,9 +18,6 @@ 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;
use imbalance::{NegativeImbalance, PositiveImbalance};
Expand Down Expand Up @@ -143,40 +141,42 @@ decl_storage! {
// like `existential_deposit`, but always set to 0
pub MinimumBalance get(minimum_balance): T::Balance = 0.into();

pub TotalIssuance get(total_issuance) : T::Balance;
pub TotalIssuance get(total_issuance) build(|config: &GenesisConfig<T>| {
config.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n)
}): T::Balance;

pub FreeBalance get(free_balance) : map T::AccountId => T::Balance;
pub FreeBalance get(free_balance) build(|config: &GenesisConfig<T>| config.balances.clone()):
map T::AccountId => T::Balance;

pub ReservedBalance get(reserved_balance): map T::AccountId => T::Balance;

pub Locks get(locks): map T::AccountId => Vec<BalanceLock<T::Balance, T::BlockNumber>>;

pub TotalLock get(total_lock): T::Balance;

pub Vesting get(vesting): map T::AccountId => Option<VestingSchedule<T::Balance>>;
pub Vesting get(vesting) build(|config: &GenesisConfig<T>| {
config.vesting.iter().filter_map(|&(ref who, begin, length)| {
let begin = <T::Balance as From<T::BlockNumber>>::from(begin);
let length = <T::Balance as From<T::BlockNumber>>::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::<Vec<_>>()
}): map T::AccountId => Option<VestingSchedule<T::Balance>>;
}
add_extra_genesis {
// for ring
config(ring_balances): Vec<(T::AccountId, CurrencyOf<T>, u32)>;
config(vesting): Vec <(T::AccountId, T::BlockNumber, T::BlockNumber)>;
build( |
storage: & mut primitives::StorageOverlay,
_: & mut primitives::ChildrenStorageOverlay,
config: & GenesisConfig<T>
| {
with_storage(storage, || {
for &(ref depositor, balance, months) in &config.ring_balances {
assert!(T::Currency::free_balance(&depositor) >= balance);
let _ = <Module<T>>::deposit(
T::Origin::from(Some(depositor.clone()).into()),
balance,
months
);

}
});
});
}
config(balances): Vec<(T::AccountId, T::Balance)>;
config(vesting): Vec<(T::AccountId, T::BlockNumber, T::BlockNumber)>; // begin, length
}
}

decl_module! {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<T: Trait> Module<T> {
deposit.total,
// u32::max_value().into(),
T::BlockNumber::max_value(),
WithdrawReasons::all()
WithdrawReasons::all(),
);
<DepositLedger<T>>::insert(who, deposit);
}
Expand Down Expand Up @@ -453,7 +453,7 @@ impl<T: Trait> Currency<T::AccountId> for Module<T> {

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);
Expand Down
2 changes: 1 addition & 1 deletion srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl ExtBuilder {

let _ = GenesisConfig::<Test> {
sys_acc: 42,
ring_balances: vec![
balances: vec![
(1, 10 * balance_factor, 12),
(2, 20 * balance_factor, 12),
(3, 300 * balance_factor, 12),
Expand Down
14 changes: 0 additions & 14 deletions srml/kton/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ 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() {
Expand Down
2 changes: 1 addition & 1 deletion srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl ExtBuilder {
vesting: vec![],
}.assimilate_storage(&mut t, &mut c);
let _ = kton::GenesisConfig::<Test> {
ring_balances : vec![
balances : vec![
(1, 10 * balance_factor, 12),
(2, 20 * balance_factor, 12),
(3, 300 * balance_factor, 12),
Expand Down
9 changes: 8 additions & 1 deletion srml/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ fn test_env_build() {
// initial build storage should work
// controller in session.validators
assert_eq!(Session::validators(), vec![10, 1, 20]);
// 21 - the minimum bonded
assert_eq!(Staking::stakers(&21), Exposure { total: 1000, own: 1000, others: vec![IndividualExposure {who: 101, value: 0}]});
assert_eq!(Staking::stakers(&11), Exposure { total: 100 * COIN, own: 100 * COIN, others: vec![]});
// stash in staking.current_elected
assert_eq!(Staking::current_elected(), vec![11, 2, 21]);

Expand Down Expand Up @@ -83,8 +86,12 @@ fn offline_should_slash_and_disable() {
Staking::on_offline_validator(90, 4);

start_era(2);
// acc 21-20 will not be a validator because it failed to meet the standard
assert_eq!(Staking::current_elected(), vec![11, 91, 81]);
// assert_eq!(Session::validators(), vec![11, 91, 81]);
assert_eq!(Staking::stakers(&91), Exposure {total: 21 * COIN, own: 21 * COIN, others: vec![]});
// out of validator set, status related will be cleared
assert_eq!(Staking::stakers(&21), Exposure { total: 0, own: 0, others: vec![]});
assert_eq!(Session::validators(), vec![10, 90, 80]);
});
}

0 comments on commit aea03eb

Please sign in to comment.