Skip to content

Commit

Permalink
Merge pull request #131 from AurevoirXavier/update-and-fix
Browse files Browse the repository at this point in the history
Update and Fix
  • Loading branch information
hackfisher authored Dec 3, 2019
2 parents 39b5af8 + d5a0017 commit bfb901e
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 146 deletions.
6 changes: 3 additions & 3 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ fn load_conf_from_file(cli: &mut RunCmd) -> error::Result<()> {
}

if let Some(shared_params) = conf.shared {
cli.shared_params.dev = shared_params.dev;
cli.shared_params = shared_params;
}
if let Some(validator) = conf.validator {
cli.validator = validator;
Expand Down Expand Up @@ -740,12 +740,12 @@ where
E: ChainSpecExtension,
S: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
{
load_conf_from_file(&mut cli)?;

let spec = load_spec(&cli.shared_params, spec_factory)?;
let base_path = base_path(&cli.shared_params, &version);
let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), Some(base_path));

load_conf_from_file(&mut cli)?;

fill_config_keystore_password(&mut config, &cli)?;

config.impl_name = impl_name;
Expand Down
19 changes: 18 additions & 1 deletion core/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl Default for TransactionPoolParams {

/// Execution strategies parameters.
#[derive(Clone, Debug, StructOpt, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(default, rename_all = "kebab-case")]
pub struct ExecutionStrategies {
/// The means of execution used when calling into the runtime while syncing blocks.
#[structopt(
Expand Down Expand Up @@ -379,6 +379,19 @@ pub struct ExecutionStrategies {
pub execution: Option<ExecutionStrategy>,
}

impl Default for ExecutionStrategies {
fn default() -> Self {
Self {
execution_syncing: ExecutionStrategy::NativeElseWasm,
execution_import_block: ExecutionStrategy::NativeElseWasm,
execution_block_construction: ExecutionStrategy::Wasm,
execution_offchain_worker: ExecutionStrategy::Native,
execution_other: ExecutionStrategy::Native,
execution: None,
}
}
}

/// The `run` command used to run a node.
#[derive(Debug, StructOpt, Clone)]
pub struct RunCmd {
Expand Down Expand Up @@ -981,6 +994,7 @@ pub struct Conf {
pub database_cache_size: Option<u32>,
pub state_cache_size: Option<usize>,

#[serde(flatten)]
pub shared: Option<SharedParams>,
pub validator: Option<bool>,
pub sentry: Option<bool>,
Expand All @@ -994,13 +1008,16 @@ pub struct Conf {
#[serde(rename = "wasm-execution")]
pub wasm_method: Option<WasmExecutionMethod>,

#[serde(flatten)]
pub execution_strategies: Option<ExecutionStrategies>,

pub offchain_worker: Option<OffchainWorkerEnabled>,

pub no_grandpa: Option<bool>,

#[serde(flatten)]
pub network_config: Option<NetworkConfigurationParams>,
#[serde(flatten)]
pub pool_config: Option<TransactionPoolParams>,

pub rpc_external: Option<bool>,
Expand Down
19 changes: 8 additions & 11 deletions darwinia_conf_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@

"wasm-execution": "interpreted",

"execution-strategies": {
"execution-syncing": "native",
"execution-import-block": "native",
"execution-block-construction": "native",
"execution-offchain-worker": "native",
"execution-other": "native",
"execution": "native"
},
"execution": "native-else-wasm",

"offchain-worker": "never",

"no-grandpa": true,

"rpc-external": false,
"rpc-external": true,
"rpc-port": 23333,

"ws-external": false,
"ws-port": 23334
"ws-external": true,
"ws-port": 23334,

"port": 23335,

"base-path": "/tmp"
}
141 changes: 71 additions & 70 deletions node/cli/res/crayfish-fir.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn testnet_genesis(
]
});

const ENDOWMENT: Balance = 1_000_000 * COIN;
const ENDOWMENT: Balance = 10_000_000 * COIN;
const STASH: Balance = 100 * COIN;

GenesisConfig {
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn testnet_genesis(
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
.collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
Expand Down
9 changes: 4 additions & 5 deletions srml/kton/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod imbalance;

use codec::{Codec, Decode, Encode};
use rstd::{cmp, fmt::Debug, prelude::*, result};
#[cfg(feature = "std")]
Expand All @@ -22,14 +24,11 @@ use system::ensure_signed;
use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock, WithdrawReason, WithdrawReasons};
use imbalance::{NegativeImbalance, PositiveImbalance};

#[cfg(test)]
#[cfg(all(feature = "std", test))]
mod mock;

#[cfg(test)]
#[cfg(all(feature = "std", test))]
mod tests;

mod imbalance;

/// Struct to encode the vesting schedule of an individual account.
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default, RuntimeDebug)]
pub struct VestingSchedule<Balance> {
Expand Down
2 changes: 1 addition & 1 deletion srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use node_primitives::Balance;
pub use node_runtime::constants::currency::COIN;

use std::{cell::RefCell, collections::HashSet};
Expand All @@ -13,7 +14,6 @@ use substrate_primitives::H256;

use super::*;
use crate::{GenesisConfig, Module};
use node_primitives::Balance;

thread_local! {
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
Expand Down
104 changes: 58 additions & 46 deletions srml/kton/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
use srml_support::{assert_err, assert_noop, assert_ok, traits::Currency};

use darwinia_support::{LockIdentifier, WithdrawReason, WithdrawReasons};
use darwinia_support::{LockIdentifier, NormalLock, TimeStamp, WithdrawLock, WithdrawReason, WithdrawReasons};

use super::*;
use crate::mock::*;

const ID_1: LockIdentifier = *b"1 ";
const ID_2: LockIdentifier = *b"2 ";
const ID_3: LockIdentifier = *b"3 ";

#[test]
fn transfer_should_work() {
ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
let _ = Kton::deposit_creating(&666, 100);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
assert_eq!(Kton::total_balance(&666), 50);
assert_eq!(Kton::total_balance(&777), 50);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
assert_eq!(Kton::total_balance(&666), 0);
assert_eq!(Kton::total_balance(&777), 100);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 0));
});
}

// TODO
//#[test]
//fn transfer_should_work() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
// let _ = Kton::deposit_creating(&666, 100);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
// assert_eq!(Kton::total_balance(&666), 50);
// assert_eq!(Kton::total_balance(&777), 50);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
// assert_eq!(Kton::total_balance(&666), 0);
// assert_eq!(Kton::total_balance(&777), 100);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 0));
// });
//}
//
//#[test]
//fn transfer_should_fail() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
// let _ = Kton::deposit_creating(&777, 1);
// assert_err!(
// Kton::transfer(Origin::signed(666), 777, 50),
// "balance too low to send value"
// );
//
// let _ = Kton::deposit_creating(&666, u64::max_value());
// assert_err!(
// Kton::transfer(Origin::signed(777), 666, 1),
// "destination balance too high to receive value"
// );
//
// assert_err!(
// Kton::transfer(Origin::signed(1), 777, Kton::vesting_balance(&1)),
// "vesting balance too high to send value"
// );
//
// Kton::set_lock(ID_1, &777, 1, u64::max_value(), WithdrawReasons::all());
// assert_err!(
// Kton::transfer(Origin::signed(777), 1, 1),
// "account liquidity restrictions prevent withdrawal"
// );
// });
//}
//
#[test]
fn transfer_should_fail() {
ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
let _ = Kton::deposit_creating(&777, 1);
assert_err!(
Kton::transfer(Origin::signed(666), 777, 50),
"balance too low to send value",
);

let _ = Kton::deposit_creating(&666, Balance::max_value());
assert_err!(
Kton::transfer(Origin::signed(777), 666, 1),
"destination balance too high to receive value",
);

assert_err!(
Kton::transfer(Origin::signed(1), 777, Kton::vesting_balance(&1)),
"vesting balance too high to send value",
);

Kton::set_lock(
ID_1,
&777,
WithdrawLock::Normal(NormalLock {
amount: Balance::max_value(),
until: TimeStamp::max_value(),
}),
WithdrawReasons::all(),
);
assert_err!(
Kton::transfer(Origin::signed(777), 1, 1),
"account liquidity restrictions prevent withdrawal",
);
});
}

//#[test]
//fn set_lock_should_work() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion srml/staking/src/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn compute_total_payout<T: Trait>(

let maximum = portion * total_left;

let maximum = maximum - maximum * 99_u128.pow(year.integer_sqrt()) / 100_u128.pow(year.integer_sqrt());
// let maximum = maximum - maximum * 99_u128.pow(year.integer_sqrt()) / 100_u128.pow(year.integer_sqrt());

let payout = maximum * 1; // TODO: add treasury ratio: Perbill::from_rational_approximation(npos_token_staked, total_tokens);

Expand Down
2 changes: 1 addition & 1 deletion srml/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod structs {

#[inline]
fn can_withdraw(&self, at: Moment, new_balance: Balance) -> bool {
self.valid_at(at) && self.amount > new_balance
!self.valid_at(at) || self.amount <= new_balance
}
}

Expand Down
6 changes: 1 addition & 5 deletions types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"EpochDuration": "u64",
"EraIndex": "u32",
"TimeStamp": "u64",
"RingBalanceOf": "u128",
"RingBalanceOf": "u128",
"KtonBalanceOf": "u128",
"ExtendedBalance": "u128",
"Address": "H160",
Expand All @@ -13,7 +13,6 @@
"Kton": "KtonBalanceOf"
}
},

"IndividualExposure": {
"who": "AccountId",
"value": "ExtendedBalance"
Expand All @@ -23,13 +22,11 @@
"own": "ExtendedBalance",
"others": "Vec<IndividualExposure>"
},

"ValidatorPrefs": {
"node_name": "Vec<u8>",
"unstake_threshold": "Compact<u32>",
"validator_payment_ratio": "Compact<u32>"
},

"StakingLedger": {
"stash": "AccountId",
"active_ring": "Compact<RingBalanceOf>",
Expand All @@ -44,7 +41,6 @@
"start_time": "Compact<Moment>",
"expire_time": "Compact<Moment>"
},

"BalanceLock": {
"id": "LockIdentifier",
"withdraw_lock": "WithdrawLock",
Expand Down

0 comments on commit bfb901e

Please sign in to comment.