Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: sync tests and runtime primitives #102

Merged
merged 50 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8c800d1
update: sync tests and runtime primitives
AurevoirXavier Nov 22, 2019
a6a3ef1
fix: `clear_mature_deposits` logic
AurevoirXavier Nov 22, 2019
ec53209
hanging: bakcup
AurevoirXavier Nov 22, 2019
4c847fd
Merge remote-tracking branch 'upstream/develop' into update-test
AurevoirXavier Nov 22, 2019
77852bb
hanging: backup
AurevoirXavier Nov 22, 2019
fe248b7
hanging: backup
AurevoirXavier Nov 22, 2019
c4de14b
Merge remote-tracking branch 'upstream/develop' into update-test
AurevoirXavier Nov 22, 2019
ecafdd0
fix: `normal_unbond_should_work`
AurevoirXavier Nov 22, 2019
a30ff73
hanging: backup
AurevoirXavier Nov 22, 2019
a652a20
Merge remote-tracking branch 'upstream/develop' into update-test
AurevoirXavier Nov 22, 2019
9f80a33
update: currency primitives
AurevoirXavier Nov 23, 2019
af5d88d
remove: useless import
AurevoirXavier Nov 23, 2019
e7064cc
remove: useless lifetime bound
AurevoirXavier Nov 23, 2019
2f6ff75
hanging: backup
AurevoirXavier Nov 23, 2019
7202e66
fix: `punished_claim_should_work`
AurevoirXavier Nov 23, 2019
928a1aa
remove: clone on copy, useless field
AurevoirXavier Nov 23, 2019
3f67e3a
hanging: bakcup
AurevoirXavier Nov 23, 2019
1b780cf
fix: `transform_to_deposited_ring_should_work`
AurevoirXavier Nov 23, 2019
1c7ea90
hanging: backup
AurevoirXavier Nov 23, 2019
e9bd448
fix: `expired_ring_should_capable_to_promise_again`
AurevoirXavier Nov 23, 2019
48ba6c2
fix: `inflation_should_be_correct`
AurevoirXavier Nov 23, 2019
93cff5d
add: TODO
AurevoirXavier Nov 23, 2019
ab0cb5a
add: comment for `reward_validator`
AurevoirXavier Nov 25, 2019
2bb337f
fix: `set_controller_should_not_change_ledger`
AurevoirXavier Nov 25, 2019
77219c0
fix: remove dangling comma
AurevoirXavier Nov 25, 2019
5d728eb
rename: `set_controller_should_remove_old_ledger` to `set_controller_…
AurevoirXavier Nov 25, 2019
f82d4b0
fix: `check_stash_already_bonded_and_controller_already_paired`
AurevoirXavier Nov 25, 2019
333db3a
fix: `bond_over_max_promise_month_should_fail`
AurevoirXavier Nov 25, 2019
a93aba2
add: comment for `slash_validator`
AurevoirXavier Nov 25, 2019
ac33c71
fix: typo
AurevoirXavier Nov 25, 2019
a8a9b98
update: `set_controller_should_work`
AurevoirXavier Nov 25, 2019
08f95cc
fix: `pool_should_be_increased_and_decreased_correctly`
AurevoirXavier Nov 25, 2019
eaab535
fix: typo
AurevoirXavier Nov 25, 2019
d76be29
hanging: backup
AurevoirXavier Nov 25, 2019
0c0aca9
Merge remote-tracking branch 'upstream/develop' into update-test
AurevoirXavier Nov 25, 2019
8619dfc
fix: `unbond_over_max_unbondings_chunks_should_fail`
AurevoirXavier Nov 25, 2019
920b338
fix: bug with `ensure!` parser
AurevoirXavier Nov 25, 2019
9dcdcef
add: `unbond_zero`
AurevoirXavier Nov 26, 2019
bb332ba
fix: `promise_extra_should_not_remove_unexpired_items`
AurevoirXavier Nov 26, 2019
b0cdc1e
update: avoid unnecessary `insert` operation
AurevoirXavier Nov 26, 2019
46be1dd
remove: `total_deposit_should_be_increased_and_decreased_correctly`
AurevoirXavier Nov 26, 2019
d4b6eb2
remove: `unlock_value_should_be_increased_and_decreased_correctly`
AurevoirXavier Nov 26, 2019
7ad23af
fix: `yakio_q1`
AurevoirXavier Nov 26, 2019
129416a
update: `ValidatorPrefs`
AurevoirXavier Nov 26, 2019
b77c505
fix: `yakio_q2`
AurevoirXavier Nov 26, 2019
8fefeb9
fix: `pool_should_be_increased_and_decreased_correctly`
AurevoirXavier Nov 26, 2019
840be95
fix: `slash_should_not_touch_unbondings`
AurevoirXavier Nov 26, 2019
9fb732f
udpate: format
AurevoirXavier Nov 26, 2019
5dc44fd
add: `FIXME: slash strategy`
AurevoirXavier Nov 26, 2019
45729fd
Merge remote-tracking branch 'upstream/develop' into update-test
AurevoirXavier Nov 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

23 changes: 10 additions & 13 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate chain configurations.
pub use node_runtime::GenesisConfig;

use babe_primitives::AuthorityId as BabeId;
use chain_spec::ChainSpecExtension;
use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_primitives::{AccountId, Balance};
use node_runtime::constants::currency::*;
use node_runtime::Block;
pub use node_runtime::GenesisConfig;
use node_runtime::{
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, GrandpaConfig, ImOnlineConfig,
IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, COIN,
WASM_BINARY,
constants::currency::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, Block, ContractsConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, WASM_BINARY,
};
use primitives::{crypto::UncheckedInto, Pair, Public};
use serde::{Deserialize, Serialize};
use serde_json::de::ParserNumber;
use serde_json::Number;
use serde_json::{de::ParserNumber, Number};
use sr_primitives::Perbill;
use substrate_service;
use substrate_service::Properties;
use substrate_telemetry::TelemetryEndpoints;

Expand Down Expand Up @@ -195,8 +192,8 @@ pub fn testnet_genesis(
]
});

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

GenesisConfig {
system: Some(SystemConfig {
Expand Down Expand Up @@ -230,7 +227,7 @@ pub fn testnet_genesis(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MICRO,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand Down Expand Up @@ -385,7 +382,7 @@ pub fn darwinia_genesis_verbose(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MICRO,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand Down
7 changes: 4 additions & 3 deletions node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
pub mod currency {
use node_primitives::Balance;

pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
pub const NANO: Balance = 1;
pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const COIN: Balance = 1_000 * MILLI;
}

/// Time.
Expand Down
108 changes: 44 additions & 64 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,51 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]

use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
pub use balances::Call as BalancesCall;
use codec::{Decode, Encode};
/// Constant values used within the runtime.
pub mod constants;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;

pub use contracts::Gas;
use sr_api::impl_runtime_apis;
pub use timestamp::Call as TimestampCall;

//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
//use im_online::sr25519::AuthorityId as ImOnlineId;
pub use balances::Call as BalancesCall;
pub use staking::StakerStatus;

use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
use codec::{Decode, Encode};
use grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList};
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature};
use rstd::prelude::*;
use sr_primitives::traits::{
self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup,
use sr_api::impl_runtime_apis;
use sr_primitives::{
create_runtime_str, generic, impl_opaque_keys,
traits::{self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup},
transaction_validity::TransactionValidity,
weights::Weight,
ApplyResult, Perbill,
};
use sr_primitives::transaction_validity::TransactionValidity;
use sr_primitives::weights::Weight;
#[cfg(any(feature = "std", test))]
pub use sr_primitives::BuildStorage;

use sr_primitives::{create_runtime_str, generic, impl_opaque_keys, ApplyResult, Perbill};
use substrate_primitives::u32_trait::{_1, _4};

use support::traits::OnUnbalanced;
pub use support::StorageValue;
use substrate_primitives::OpaqueMetadata;
use support::{
construct_runtime, parameter_types,
traits::{Currency, Randomness, SplitTwoWays},
traits::{Currency, OnUnbalanced, Randomness, SplitTwoWays},
};

pub use timestamp::Call as TimestampCall;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use version::RuntimeVersion;
//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
//use im_online::sr25519::AuthorityId as ImOnlineId;

use grandpa::fg_primitives;
use grandpa::AuthorityList as GrandpaAuthorityList;
use im_online::sr25519::AuthorityId as ImOnlineId;
use substrate_primitives::OpaqueMetadata;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;

use constants::{currency::*, time::*};
use darwinia_support::TimeStamp;
use staking::EraIndex;
pub use staking::StakerStatus;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};

/// Constant values used within the runtime.
pub mod constants;
use constants::time::*;
use staking::EraIndex;

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand All @@ -96,12 +87,15 @@ pub fn native_version() -> NativeVersion {
}
}

pub const NANO: Balance = 1;
pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const COIN: Balance = 1_000 * MILLI;

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
type DealWithFees = SplitTwoWays<
Balance,
NegativeImbalance,
_4,
MockTreasury, // 4 parts (80%) goes to the treasury.
_1,
Author, // 1 part (20%) goes to the block author.
>;

//pub struct Author;
//
Expand All @@ -118,20 +112,6 @@ impl OnUnbalanced<NegativeImbalance> for MockTreasury {
}
}

pub type DealWithFees = SplitTwoWays<
Balance,
NegativeImbalance,
_4,
MockTreasury, // 4 parts (80%) goes to the treasury.
_1,
Author, // 1 part (20%) goes to the block author.
>;

pub const SECS_PER_BLOCK: BlockNumber = 6;
pub const MINUTES: BlockNumber = 60 / SECS_PER_BLOCK;
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1_000_000_000;
Expand Down Expand Up @@ -171,8 +151,8 @@ impl indices::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * COIN;
pub const TransferFee: Balance = 1 * MILLI;
pub const CreationFee: Balance = 1 * MILLI;
pub const TransferFee: Balance = 1 * MICRO;
pub const CreationFee: Balance = 1 * MICRO;
}
impl balances::Trait for Runtime {
type Balance = Balance;
Expand All @@ -187,7 +167,7 @@ impl balances::Trait for Runtime {
}

parameter_types! {
pub const TransactionBaseFee: Balance = 1 * MILLI;
pub const TransactionBaseFee: Balance = 1 * MICRO;
pub const TransactionByteFee: Balance = 10 * MICRO;
// setting this to zero will disable the weight fee.
pub const WeightFeeCoefficient: Balance = 1_000;
Expand Down Expand Up @@ -309,11 +289,11 @@ impl finality_tracker::Trait for Runtime {
}

parameter_types! {
pub const ContractTransferFee: Balance = 1 * MILLI;
pub const ContractCreationFee: Balance = 1 * MILLI;
pub const ContractTransactionBaseFee: Balance = 1 * MILLI;
pub const ContractTransferFee: Balance = 1 * MICRO;
pub const ContractCreationFee: Balance = 1 * MICRO;
pub const ContractTransactionBaseFee: Balance = 1 * MICRO;
pub const ContractTransactionByteFee: Balance = 10 * MICRO;
pub const ContractFee: Balance = 1 * MILLI;
pub const ContractFee: Balance = 1 * MICRO;
pub const TombstoneDeposit: Balance = 1 * COIN;
pub const RentByteFee: Balance = 1 * COIN;
pub const RentDepositOffset: Balance = 1000 * COIN;
Expand Down
3 changes: 3 additions & 0 deletions srml/kton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ darwinia-support = { path = "../support", default-features = false }
runtime_io = { package = "sr-io", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }
substrate-primitives = { git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }

node-runtime = { path = "../../node/runtime" }
node-primitives = { path = "../../node/primitives" }

[features]
default = ["std"]
std = [
Expand Down
2 changes: 0 additions & 2 deletions srml/kton/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Codec, Decode, Encode};
#[cfg(not(feature = "std"))]
use rstd::borrow::ToOwned;
use rstd::{cmp, fmt::Debug, prelude::*, result};
#[cfg(feature = "std")]
use sr_primitives::traits::One;
Expand Down
22 changes: 14 additions & 8 deletions srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
pub use node_runtime::constants::currency::COIN;

use std::{cell::RefCell, collections::HashSet};

use sr_primitives::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
weights::Weight,
Perbill,
};
use srml_support::{impl_outer_origin, parameter_types};
use substrate_primitives::H256;

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

pub const COIN: u64 = 1_000_000_000;
use node_primitives::Balance;

thread_local! {
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0);
static EXISTENTIAL_DEPOSIT: RefCell<Balance> = RefCell::new(0);
}

/// The AccountId alias in this test module.
pub type AccountId = u64;
// FIXME:
// replace
// testing::Header.number: u64
// with
// node_primitives::BlockNumber
pub type BlockNumber = u64;
pub type Balance = u64;

impl_outer_origin! {
pub enum Origin for Test {}
Expand All @@ -31,8 +37,8 @@ impl_outer_origin! {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down Expand Up @@ -71,7 +77,7 @@ impl Trait for Test {
}

pub struct ExtBuilder {
existential_deposit: u64,
existential_deposit: Balance,
}

impl Default for ExtBuilder {
Expand All @@ -81,7 +87,7 @@ impl Default for ExtBuilder {
}

impl ExtBuilder {
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
pub fn existential_deposit(mut self, existential_deposit: Balance) -> Self {
self.existential_deposit = existential_deposit;
self
}
Expand Down
3 changes: 2 additions & 1 deletion srml/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ substrate-primitives = { git = "https://github.com/darwinia-network/substrate.gi
timestamp = { package = "srml-timestamp", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }
rand = "0.7.2"

balances = { package = "darwinia-balances", path = '../balances', default-features = false }
balances = { package = "darwinia-balances", path = '../balances' }
kton = { package = "darwinia-kton", path = "../kton" }
node-runtime = { path = "../../node/runtime" }
node-primitives = { path = "../../node/primitives" }

[features]
equalize = []
Expand Down
4 changes: 2 additions & 2 deletions srml/staking/src/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use substrate_primitives::U256;

// 1 - (99 /100)^sqrt(year)
// <T: Trait + 'static>() -> RingBalanceOf<T>
pub fn compute_total_payout<T: Trait + 'static>(
pub fn compute_total_payout<T: Trait>(
era_duration: u64,
living_time: u64,
total_left: u128,
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn compute_total_payout<T: Trait + 'static>(

// consistent with the formula in smart contract in evolution land which can be found in
// https://github.com/evolutionlandorg/bank/blob/master/contracts/GringottsBank.sol#L280
pub fn compute_kton_return<T: Trait + 'static>(value: RingBalanceOf<T>, months: u32) -> KtonBalanceOf<T> {
pub fn compute_kton_return<T: Trait>(value: RingBalanceOf<T>, months: u32) -> KtonBalanceOf<T> {
let value = value.saturated_into::<u64>();
let no = U256::from(67).pow(U256::from(months));
let de = U256::from(66).pow(U256::from(months));
Expand Down
Loading