From 8c800d146b375287f00d3bdbe5518a056be53c9b Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 22 Nov 2019 12:12:45 +0800 Subject: [PATCH 1/2] update: sync tests and runtime primitives --- Cargo.lock | 3 + node/cli/src/chain_spec.rs | 14 +- node/runtime/src/constants.rs | 5 +- node/runtime/src/lib.rs | 99 +++++----- srml/kton/Cargo.toml | 3 + srml/kton/src/mock.rs | 26 +-- srml/staking/Cargo.toml | 3 +- srml/staking/src/mock.rs | 45 +++-- srml/staking/src/tests.rs | 329 +++++++++++++++++----------------- 9 files changed, 270 insertions(+), 257 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 800fd8123..c69013b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -718,6 +718,8 @@ name = "darwinia-kton" version = "0.1.0" dependencies = [ "darwinia-support 0.1.0", + "node-primitives 2.0.0", + "node-runtime 0.1.0", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", @@ -738,6 +740,7 @@ dependencies = [ "darwinia-balances 2.0.0", "darwinia-kton 0.1.0", "darwinia-support 0.1.0", + "node-primitives 2.0.0", "node-runtime 0.1.0", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index bb9a82001..b6fb9af20 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -25,9 +25,9 @@ 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::MILLICENTS, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, + GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, + SudoConfig, SystemConfig, WASM_BINARY, }; use primitives::{crypto::UncheckedInto, Pair, Public}; use serde::{Deserialize, Serialize}; @@ -249,7 +249,7 @@ pub fn testnet_genesis( }), staking: Some(StakingConfig { current_era: 0, - // current_era_total_reward: 80_000_000 * COIN / 63720, + // current_era_total_reward: 80_000_000 * MILLICENTS / 63720, // offline_slash: Perbill::from_parts(1_000_000), session_reward: Perbill::from_percent(90), validator_count: 7, @@ -350,8 +350,8 @@ pub fn darwinia_genesis_verbose( ] }); - const ENDOWMENT: Balance = 100_000_000 * COIN; - const STASH: Balance = 100 * COIN; + const ENDOWMENT: Balance = 100_000_000 * MILLICENTS; + const STASH: Balance = 100 * MILLICENTS; GenesisConfig { system: Some(SystemConfig { @@ -404,7 +404,7 @@ pub fn darwinia_genesis_verbose( }), staking: Some(StakingConfig { current_era: 0, - // current_era_total_reward: 80_000_000 * COIN / 63720, + // current_era_total_reward: 80_000_000 * MILLICENTS / 63720, // offline_slash: Perbill::from_parts(1_000_000), session_reward: Perbill::from_percent(90), validator_count: 7, diff --git a/node/runtime/src/constants.rs b/node/runtime/src/constants.rs index 489934045..39dc0dc7b 100644 --- a/node/runtime/src/constants.rs +++ b/node/runtime/src/constants.rs @@ -20,7 +20,10 @@ pub mod currency { use node_primitives::Balance; - pub const MILLICENTS: Balance = 1_000_000_000; + pub const NANO: Balance = 1; + pub const MICRO: Balance = 1_000 * NANO; + pub const MILLI: Balance = 1_000 * MICRO; + pub const MILLICENTS: Balance = 1_000 * MILLI; pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. pub const DOLLARS: Balance = 100 * CENTS; } diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 29eda15b1..5b0de4faf 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -19,60 +19,52 @@ #![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}; 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::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 grandpa::fg_primitives; +//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight}; +//use im_online::sr25519::AuthorityId as ImOnlineId; use darwinia_support::TimeStamp; use staking::EraIndex; -pub use staking::StakerStatus; +/// Constant values used within the runtime. +pub mod constants; /// 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 constants::{currency::*, time::*}; +use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment}; // Make the WASM binary available. #[cfg(feature = "std")] @@ -96,12 +88,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 = >::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; // @@ -118,20 +113,6 @@ impl OnUnbalanced 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; @@ -170,7 +151,7 @@ impl indices::Trait for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * COIN; + pub const ExistentialDeposit: Balance = 1 * MILLICENTS; pub const TransferFee: Balance = 1 * MILLI; pub const CreationFee: Balance = 1 * MILLI; } @@ -314,10 +295,10 @@ parameter_types! { pub const ContractTransactionBaseFee: Balance = 1 * MILLI; pub const ContractTransactionByteFee: Balance = 10 * MICRO; pub const ContractFee: Balance = 1 * MILLI; - pub const TombstoneDeposit: Balance = 1 * COIN; - pub const RentByteFee: Balance = 1 * COIN; - pub const RentDepositOffset: Balance = 1000 * COIN; - pub const SurchargeReward: Balance = 150 * COIN; + pub const TombstoneDeposit: Balance = 1 * MILLICENTS; + pub const RentByteFee: Balance = 1 * MILLICENTS; + pub const RentDepositOffset: Balance = 1000 * MILLICENTS; + pub const SurchargeReward: Balance = 150 * MILLICENTS; } impl contracts::Trait for Runtime { type Currency = Balances; @@ -394,7 +375,7 @@ parameter_types! { // 365 days * 24 hours * 60 minutes / 5 minutes pub const ErasPerEpoch: EraIndex = 105120; // decimal 9 - pub const HardCap: Balance = 10_000_000_000 * COIN; + pub const HardCap: Balance = 10_000_000_000 * MILLICENTS; pub const GenesisTime: Moment = 1_574_156_000_000; } impl staking::Trait for Runtime { diff --git a/srml/kton/Cargo.toml b/srml/kton/Cargo.toml index a63398c03..af999e3f0 100644 --- a/srml/kton/Cargo.toml +++ b/srml/kton/Cargo.toml @@ -22,6 +22,9 @@ darwinia-support = { path = "../support", default-features = false } runtime_io = { package = "sr-io", git = 'https://github.com/darwinia-network/substrate.git' } substrate-primitives = { git = 'https://github.com/darwinia-network/substrate.git' } +node-runtime = { path = "../../node/runtime" } +node-primitives = { path = "../../node/primitives" } + [features] default = ["std"] std = [ diff --git a/srml/kton/src/mock.rs b/srml/kton/src/mock.rs index 60aed4901..1b24b4f1c 100644 --- a/srml/kton/src/mock.rs +++ b/srml/kton/src/mock.rs @@ -1,8 +1,11 @@ +pub use node_runtime::constants::currency::MILLICENTS; + 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}; @@ -10,18 +13,21 @@ 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, HashSet)> = RefCell::new(Default::default()); - static EXISTENTIAL_DEPOSIT: RefCell = RefCell::new(0); + static EXISTENTIAL_DEPOSIT: RefCell = 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 {} @@ -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(); } @@ -71,7 +77,7 @@ impl Trait for Test { } pub struct ExtBuilder { - existential_deposit: u64, + existential_deposit: Balance, } impl Default for ExtBuilder { @@ -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 } @@ -94,9 +100,9 @@ impl ExtBuilder { self.set_associated_consts(); let mut t = system::GenesisConfig::default().build_storage::().unwrap(); let balance_factor = if self.existential_deposit > 0 { - 1_000 * COIN + 1_000 * MILLICENTS } else { - 1 * COIN + 1 * MILLICENTS }; let _ = GenesisConfig:: { diff --git a/srml/staking/Cargo.toml b/srml/staking/Cargo.toml index 193e0f687..a79aaba12 100644 --- a/srml/staking/Cargo.toml +++ b/srml/staking/Cargo.toml @@ -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' } 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 = [] diff --git a/srml/staking/src/mock.rs b/srml/staking/src/mock.rs index 019e4f16f..55d1b2c2d 100644 --- a/srml/staking/src/mock.rs +++ b/srml/staking/src/mock.rs @@ -1,8 +1,11 @@ +pub use node_runtime::constants::currency::MILLICENTS; + use std::{cell::RefCell, collections::HashSet}; use sr_primitives::{ testing::{Header, UintAuthorityId}, traits::{BlakeTwo256, Convert, IdentityLookup, OnInitialize, OpaqueKeys}, + weights::Weight, KeyTypeId, Perbill, }; use sr_staking_primitives::SessionIndex; @@ -15,12 +18,17 @@ use substrate_primitives::{crypto::key_types, H256}; use crate::{EraIndex, GenesisConfig, Module, Nominators, RewardDestination, StakerStatus, StakingBalance, Trait}; use darwinia_support::TimeStamp; +use node_primitives::Balance; use phragmen::ExtendedBalance; /// 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; /// Module alias pub type System = system::Module; @@ -50,7 +58,7 @@ impl Convert for CurrencyToVoteHandler { thread_local! { static SESSION: RefCell<(Vec, HashSet)> = RefCell::new(Default::default()); - static EXISTENTIAL_DEPOSIT: RefCell = RefCell::new(0); + static EXISTENTIAL_DEPOSIT: RefCell = RefCell::new(0); } pub struct TestSessionHandler; @@ -81,8 +89,8 @@ pub fn is_disabled(validator: AccountId) -> bool { } pub struct ExistentialDeposit; -impl Get for ExistentialDeposit { - fn get() -> u64 { +impl Get for ExistentialDeposit { + fn get() -> Balance { EXISTENTIAL_DEPOSIT.with(|v| *v.borrow()) } } @@ -95,8 +103,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(); } @@ -177,10 +185,9 @@ parameter_types! { pub const BondingDuration: TimeStamp = 60; pub const ErasPerEpoch: EraIndex = 10; } -pub const COIN: u64 = 1_000_000_000; parameter_types! { // decimal 9 - pub const CAP: Balance = 10_000_000_000 * COIN; + pub const CAP: Balance = 10_000_000_000 * MILLICENTS; } impl Trait for Test { type Ring = Ring; @@ -202,9 +209,9 @@ impl Trait for Test { } pub struct ExtBuilder { - existential_deposit: u64, + existential_deposit: Balance, current_era: EraIndex, - reward: u64, + reward: Balance, validator_pool: bool, nominate: bool, validator_count: u32, @@ -228,7 +235,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 } @@ -263,9 +270,9 @@ impl ExtBuilder { self.set_associated_consts(); let mut storage = system::GenesisConfig::default().build_storage::().unwrap(); let balance_factor = if self.existential_deposit > 0 { - 1_000 * COIN + 1_000 * MILLICENTS } else { - 1 * COIN + 1 * MILLICENTS }; let validators = if self.validator_pool { vec![10, 20, 30, 40] @@ -315,10 +322,10 @@ impl ExtBuilder { let nominated = if self.nominate { vec![11, 21] } else { vec![] }; let _ = GenesisConfig:: { current_era: self.current_era, - // current_era_total_reward: 80_000_000 * COIN / ErasPerEpoch::get() as u64, + // current_era_total_reward: 80_000_000 * MILLICENTS / ErasPerEpoch::get() as u64, stakers: vec![ - // (2, 1, 1 * COIN, StakerStatus::::Validator), - (11, 10, 100 * COIN, StakerStatus::::Validator), + // (2, 1, 1 * MILLICENTS, StakerStatus::::Validator), + (11, 10, 100 * MILLICENTS, StakerStatus::::Validator), (21, 20, stake_21, StakerStatus::::Validator), (31, 30, stake_31, StakerStatus::::Validator), (41, 40, balance_factor * 1000, status_41), @@ -393,7 +400,7 @@ pub fn check_nominator_exposure(stash: u64) { ); } -pub fn assert_total_expo(stash: u64, val: u128) { +pub fn assert_total_expo(stash: u64, val: Balance) { let expo = Staking::stakers(&stash); assert_eq!(expo.total, val); } @@ -402,7 +409,7 @@ pub fn assert_is_stash(acc: u64) { assert!(Staking::bonded(&acc).is_some(), "Not a stash."); } -pub fn bond_validator(acc: u64, val: u64) { +pub fn bond_validator(acc: u64, val: Balance) { // a = controller // a + 1 = stash let _ = Ring::make_free_balance_be(&(acc + 1), val); @@ -421,7 +428,7 @@ pub fn bond_validator(acc: u64, val: u64) { )); } -pub fn bond_nominator(acc: u64, val: u64, target: Vec) { +pub fn bond_nominator(acc: u64, val: Balance, target: Vec) { // a = controller // a + 1 = stash let _ = Ring::make_free_balance_be(&(acc + 1), val); diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index aef213669..c5d7e1a3b 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -17,55 +17,55 @@ use darwinia_support::{BalanceLock, NormalLock, StakingLock, WithdrawLock}; // ($stash:ident($stash_id:expr), $controller:ident($controller_id:expr), $promise_month:ident($how_long:expr)) => { // #[allow(non_snake_case, unused)] // let $stash = $stash_id; -// let _ = Ring::deposit_creating(&$stash, 100 * COIN); -// Kton::deposit_creating(&$stash, 100 * COIN); +// let _ = Ring::deposit_creating(&$stash, 100 * MILLICENTS); +// Kton::deposit_creating(&$stash, 100 * MILLICENTS); // #[allow(non_snake_case, unused)] // let $controller = $controller_id; -// let _ = Ring::deposit_creating(&$controller, COIN); +// let _ = Ring::deposit_creating(&$controller, MILLICENTS); // #[allow(non_snake_case, unused)] // let $promise_month = $how_long; // assert_ok!(Staking::bond( // Origin::signed($stash), // $controller, -// StakingBalance::Ring(50 * COIN), +// StakingBalance::Ring(50 * MILLICENTS), // RewardDestination::Stash, // $how_long // )); // assert_ok!(Staking::bond_extra( // Origin::signed($stash), -// StakingBalance::Kton(50 * COIN), +// StakingBalance::Kton(50 * MILLICENTS), // $how_long // )); // }; // ($stash:ident($stash_id:expr), $controller:ident($controller_id:expr), $how_long:expr) => { // #[allow(non_snake_case, unused)] // let $stash = $stash_id; -// let _ = Ring::deposit_creating(&$stash, 100 * COIN); -// Kton::deposit_creating(&$stash, 100 * COIN); +// let _ = Ring::deposit_creating(&$stash, 100 * MILLICENTS); +// Kton::deposit_creating(&$stash, 100 * MILLICENTS); // #[allow(non_snake_case, unused)] // let $controller = $controller_id; -// let _ = Ring::deposit_creating(&$controller, COIN); +// let _ = Ring::deposit_creating(&$controller, MILLICENTS); // assert_ok!(Staking::bond( // Origin::signed($stash), // $controller, -// StakingBalance::Ring(50 * COIN), +// StakingBalance::Ring(50 * MILLICENTS), // RewardDestination::Stash, // $how_long // )); // assert_ok!(Staking::bond_extra( // Origin::signed($stash), -// StakingBalance::Kton(50 * COIN), +// StakingBalance::Kton(50 * MILLICENTS), // $how_long // )); // }; // ($stash:ident($stash_id:expr), $controller:ident($controller_id:expr)) => { // #[allow(non_snake_case, unused)] // let $stash = $stash_id; -// let _ = Ring::deposit_creating(&$stash, 100 * COIN); -// Kton::deposit_creating(&$stash, 100 * COIN); +// let _ = Ring::deposit_creating(&$stash, 100 * MILLICENTS); +// Kton::deposit_creating(&$stash, 100 * MILLICENTS); // #[allow(non_snake_case, unused)] // let $controller = $controller_id; -// let _ = Ring::deposit_creating(&$controller, COIN); +// let _ = Ring::deposit_creating(&$controller, MILLICENTS); // }; //} @@ -79,16 +79,16 @@ fn test_env_build() { Staking::ledger(&10).unwrap(), StakingLedger { stash: 11, - active_ring: 100 * COIN, - active_deposit_ring: 100 * COIN, + active_ring: 100 * MILLICENTS, + active_deposit_ring: 100 * MILLICENTS, active_kton: 0, deposit_items: vec![TimeDepositItem { - value: 100 * COIN, + value: 100 * MILLICENTS, start_time: 0, expire_time: 12 * MONTH_IN_SECONDS as u64 }], ring_staking_lock: StakingLock { - staking_amount: 100 * COIN, + staking_amount: 100 * MILLICENTS, unbondings: vec![] }, kton_staking_lock: StakingLock { @@ -98,37 +98,37 @@ fn test_env_build() { } ); - assert_eq!(Kton::free_balance(&11), COIN / 100); - assert_eq!(Kton::total_issuance(), 16 * COIN / 100); + assert_eq!(Kton::free_balance(&11), MILLICENTS / 100); + assert_eq!(Kton::total_issuance(), 16 * MILLICENTS / 100); let origin_ledger = Staking::ledger(&10).unwrap(); - let _ = Ring::deposit_creating(&11, 100 * COIN); + let _ = Ring::deposit_creating(&11, 100 * MILLICENTS); assert_ok!(Staking::bond_extra( Origin::signed(11), - StakingBalance::Ring(20 * COIN), + StakingBalance::Ring(20 * MILLICENTS), 13 )); assert_eq!( Staking::ledger(&10).unwrap(), StakingLedger { stash: 11, - active_ring: origin_ledger.active_ring + 20 * COIN, - active_deposit_ring: origin_ledger.active_deposit_ring + 20 * COIN, + active_ring: origin_ledger.active_ring + 20 * MILLICENTS, + active_deposit_ring: origin_ledger.active_deposit_ring + 20 * MILLICENTS, active_kton: 0, deposit_items: vec![ TimeDepositItem { - value: 100 * COIN, + value: 100 * MILLICENTS, start_time: 0, expire_time: 12 * MONTH_IN_SECONDS as u64 }, TimeDepositItem { - value: 20 * COIN, + value: 20 * MILLICENTS, start_time: 0, expire_time: 13 * MONTH_IN_SECONDS as u64 } ], ring_staking_lock: StakingLock { - staking_amount: origin_ledger.active_ring + 20 * COIN, + staking_amount: origin_ledger.active_ring + 20 * MILLICENTS, unbondings: vec![] }, kton_staking_lock: StakingLock { @@ -143,11 +143,11 @@ fn test_env_build() { #[test] fn normal_kton_should_work() { ExtBuilder::default().existential_deposit(0).build().execute_with(|| { - Kton::deposit_creating(&1001, 10 * COIN); + Kton::deposit_creating(&1001, 10 * MILLICENTS); assert_ok!(Staking::bond( Origin::signed(1001), 1000, - StakingBalance::Kton(10 * COIN), + StakingBalance::Kton(10 * MILLICENTS), RewardDestination::Stash, 0 )); @@ -157,14 +157,14 @@ fn normal_kton_should_work() { stash: 1001, active_ring: 0, active_deposit_ring: 0, - active_kton: 10 * COIN, + active_kton: 10 * MILLICENTS, deposit_items: vec![], ring_staking_lock: StakingLock { staking_amount: 0, unbondings: vec![] }, kton_staking_lock: StakingLock { - staking_amount: 10 * COIN, + staking_amount: 10 * MILLICENTS, unbondings: vec![] }, } @@ -174,7 +174,7 @@ fn normal_kton_should_work() { vec![BalanceLock { id: STAKING_ID, withdraw_lock: WithdrawLock::WithStaking(StakingLock { - staking_amount: 10 * COIN, + staking_amount: 10 * MILLICENTS, unbondings: vec![], }), reasons: WithdrawReasons::all() @@ -182,11 +182,11 @@ fn normal_kton_should_work() { ); // promise_month should not work for kton - Kton::deposit_creating(&2001, 10 * COIN); + Kton::deposit_creating(&2001, 10 * MILLICENTS); assert_ok!(Staking::bond( Origin::signed(2001), 2000, - StakingBalance::Kton(10 * COIN), + StakingBalance::Kton(10 * MILLICENTS), RewardDestination::Stash, 12 )); @@ -196,14 +196,14 @@ fn normal_kton_should_work() { stash: 2001, active_ring: 0, active_deposit_ring: 0, - active_kton: 10 * COIN, + active_kton: 10 * MILLICENTS, deposit_items: vec![], ring_staking_lock: StakingLock { staking_amount: 0, unbondings: vec![] }, kton_staking_lock: StakingLock { - staking_amount: 10 * COIN, + staking_amount: 10 * MILLICENTS, unbondings: vec![] }, } @@ -217,7 +217,10 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { Timestamp::set_timestamp(13 * MONTH_IN_SECONDS as u64); let ledger = Staking::ledger(&10).unwrap(); - assert_ok!(Staking::unbond(Origin::signed(10), StakingBalance::Ring(10 * COIN))); + assert_ok!(Staking::unbond( + Origin::signed(10), + StakingBalance::Ring(10 * MILLICENTS) + )); // Only active normal ring can be unbond assert_eq!(&Staking::ledger(&10).unwrap(), &ledger,); assert_eq!( @@ -225,28 +228,31 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { vec![BalanceLock { id: STAKING_ID, withdraw_lock: WithdrawLock::WithStaking(StakingLock { - staking_amount: 100 * COIN, + staking_amount: 100 * MILLICENTS, unbondings: vec![], }), reasons: WithdrawReasons::all() }] ); - assert_ok!(Staking::unbond(Origin::signed(10), StakingBalance::Ring(20 * COIN))); + assert_ok!(Staking::unbond( + Origin::signed(10), + StakingBalance::Ring(20 * MILLICENTS) + )); assert_eq!( Staking::ledger(&10).unwrap(), StakingLedger { stash: 11, - active_ring: 100 * COIN, - active_deposit_ring: 70 * COIN, + active_ring: 100 * MILLICENTS, + active_deposit_ring: 70 * MILLICENTS, active_kton: 0, deposit_items: vec![TimeDepositItem { - value: 70 * COIN, + value: 70 * MILLICENTS, start_time: 0, expire_time: 12 * MONTH_IN_SECONDS as u64 }], ring_staking_lock: StakingLock { - staking_amount: 100 * COIN, + staking_amount: 100 * MILLICENTS, unbondings: vec![] }, kton_staking_lock: StakingLock { @@ -257,24 +263,27 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { ); // unbondings: vec![ // NormalLock { - // value: StakingBalance::Ring(10 * COIN), + // value: StakingBalance::Ring(10 * MILLICENTS), // era: 3, // is_time_deposit: true // }, // NormalLock { - // value: StakingBalance::Ring(20 * COIN), + // value: StakingBalance::Ring(20 * MILLICENTS), // era: 3, // is_time_deposit: true // } // ] // more than active ring - assert_ok!(Staking::unbond(Origin::signed(10), StakingBalance::Ring(120 * COIN))); + assert_ok!(Staking::unbond( + Origin::signed(10), + StakingBalance::Ring(120 * MILLICENTS) + )); assert_eq!( Staking::ledger(&10).unwrap(), StakingLedger { stash: 11, - active_ring: 100 * COIN, + active_ring: 100 * MILLICENTS, active_deposit_ring: 0, active_kton: 0, deposit_items: vec![], @@ -290,17 +299,17 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { ); // unbondings: vec![ // NormalLock { - // value: StakingBalance::Ring(10 * COIN), + // value: StakingBalance::Ring(10 * MILLICENTS), // era: 3, // is_time_deposit: true // }, // NormalLock { - // value: StakingBalance::Ring(20 * COIN), + // value: StakingBalance::Ring(20 * MILLICENTS), // era: 3, // is_time_deposit: true // }, // NormalLock { - // value: StakingBalance::Ring(70 * COIN), + // value: StakingBalance::Ring(70 * MILLICENTS), // era: 3, // is_time_deposit: true // }, @@ -354,10 +363,10 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { // let stash = 11; // let controller = 10; -// let value = 200 * COIN; +// let value = 200 * MILLICENTS; // let promise_month = 12; // // unbond normal ring -// let _ = Ring::deposit_creating(&stash, 1000 * COIN); +// let _ = Ring::deposit_creating(&stash, 1000 * MILLICENTS); // // { // let kton_free_balance = Kton::free_balance(&stash); @@ -392,7 +401,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // bond += 0.03 // assert_ok!(Staking::bond_extra( // Origin::signed(stash), -// StakingBalance::Kton(COIN), +// StakingBalance::Kton(MILLICENTS), // 0 // )); // ledger.active_kton += kton_free_balance; @@ -420,15 +429,15 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // let controller = 1000; // let promise_month = 36; // -// let _ = Ring::deposit_creating(&stash, 100 * COIN); -// Kton::deposit_creating(&stash, COIN / 100000); +// let _ = Ring::deposit_creating(&stash, 100 * MILLICENTS); +// Kton::deposit_creating(&stash, MILLICENTS / 100000); // // // timestamp now is 0. // // free balance of kton is too low to work // assert_ok!(Staking::bond( // Origin::signed(stash), // controller, -// StakingBalance::Ring(10 * COIN), +// StakingBalance::Ring(10 * MILLICENTS), // RewardDestination::Stash, // promise_month // )); @@ -436,12 +445,12 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Staking::ledger(&controller), // Some(StakingLedger { // stash, -// total_deposit_ring: 10 * COIN, -// active_deposit_ring: 10 * COIN, -// active_ring: 10 * COIN, +// total_deposit_ring: 10 * MILLICENTS, +// active_deposit_ring: 10 * MILLICENTS, +// active_ring: 10 * MILLICENTS, // active_kton: 0, // deposit_items: vec![TimeDepositItem { -// value: 10 * COIN, +// value: 10 * MILLICENTS, // start_time: 0, // expire_time: promise_month as u64 * MONTH_IN_SECONDS as u64 // }], // should be cleared @@ -453,16 +462,16 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // kton is 0, skip unbond_with_punish // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 10 * COIN, +// 10 * MILLICENTS, // promise_month as u64 * MONTH_IN_SECONDS as u64 // )); // assert_eq!(&Staking::ledger(&controller).unwrap(), &ledger); // assert_eq!(Kton::free_balance(&stash), kton_free_balance); // // // set more kton balance to make it work -// Kton::deposit_creating(&stash, 10 * COIN); +// Kton::deposit_creating(&stash, 10 * MILLICENTS); // let kton_free_balance = Kton::free_balance(&stash); -// let unbond_value = 5 * COIN; +// let unbond_value = 5 * MILLICENTS; // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), // unbond_value, @@ -485,7 +494,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // the whole item should be be dropped // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 5 * COIN, +// 5 * MILLICENTS, // promise_month as u64 * MONTH_IN_SECONDS as u64 // )); // assert!(Staking::ledger(&controller).unwrap().deposit_items.is_empty()); @@ -495,29 +504,29 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { //#[test] //fn transform_to_promised_ring_should_work() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -// let _ = Ring::deposit_creating(&1001, 100 * COIN); +// let _ = Ring::deposit_creating(&1001, 100 * MILLICENTS); // assert_ok!(Staking::bond( // Origin::signed(1001), // 1000, -// StakingBalance::Ring(10 * COIN), +// StakingBalance::Ring(10 * MILLICENTS), // RewardDestination::Stash, // 0 // )); // let origin_ledger = Staking::ledger(&1000).unwrap(); // let kton_free_balance = Kton::free_balance(&1001); // -// assert_ok!(Staking::promise_extra(Origin::signed(1000), 5 * COIN, 12)); +// assert_ok!(Staking::promise_extra(Origin::signed(1000), 5 * MILLICENTS, 12)); // // assert_eq!( // Staking::ledger(&1000), // Some(StakingLedger { // stash: 1001, -// total_deposit_ring: origin_ledger.total_deposit_ring + 5 * COIN, -// active_deposit_ring: origin_ledger.active_deposit_ring + 5 * COIN, +// total_deposit_ring: origin_ledger.total_deposit_ring + 5 * MILLICENTS, +// active_deposit_ring: origin_ledger.active_deposit_ring + 5 * MILLICENTS, // active_ring: origin_ledger.active_ring, // active_kton: origin_ledger.active_kton, // deposit_items: vec![TimeDepositItem { -// value: 5 * COIN, +// value: 5 * MILLICENTS, // start_time: 0, // expire_time: 12 * MONTH_IN_SECONDS as u64 // }], @@ -525,24 +534,24 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // }) // ); // -// assert_eq!(Kton::free_balance(&1001), kton_free_balance + (5 * COIN / 10000)); +// assert_eq!(Kton::free_balance(&1001), kton_free_balance + (5 * MILLICENTS / 10000)); // }); //} // //#[test] //fn expired_ring_should_capable_to_promise_again() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -// let _ = Ring::deposit_creating(&1001, 100 * COIN); +// let _ = Ring::deposit_creating(&1001, 100 * MILLICENTS); // assert_ok!(Staking::bond( // Origin::signed(1001), // 1000, -// StakingBalance::Ring(10 * COIN), +// StakingBalance::Ring(10 * MILLICENTS), // RewardDestination::Stash, // 12 // )); // let mut ledger = Staking::ledger(&1000).unwrap(); // let ts = 13 * MONTH_IN_SECONDS as u64; -// let promise_extra_value = 5 * COIN; +// let promise_extra_value = 5 * MILLICENTS; // Timestamp::set_timestamp(ts); // assert_ok!(Staking::promise_extra(Origin::signed(1000), promise_extra_value, 13)); // ledger.total_deposit_ring = promise_extra_value; @@ -560,14 +569,14 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { ////#[test] ////fn inflation_should_be_correct() { //// ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -//// let initial_issuance = 1_200_000_000 * COIN; +//// let initial_issuance = 1_200_000_000 * MILLICENTS; //// let surplus_needed = initial_issuance - Ring::total_issuance(); //// let _ = Ring::deposit_into_existing(&11, surplus_needed); //// assert_eq!(Ring::total_issuance(), initial_issuance); -//// // assert_eq!(Staking::current_era_total_reward(), 80000000 * COIN / 10); +//// // assert_eq!(Staking::current_era_total_reward(), 80000000 * MILLICENTS / 10); //// start_era(11); //// // ErasPerEpoch = 10 -//// // assert_eq!(Staking::current_era_total_reward(), 88000000 * COIN / 10); +//// // assert_eq!(Staking::current_era_total_reward(), 88000000 * MILLICENTS / 10); //// }); ////} // @@ -575,44 +584,44 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { //fn reward_should_work_correctly() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { // // create controller account -// let _ = Ring::deposit_creating(&2000, COIN); -// let _ = Ring::deposit_creating(&1000, COIN); -// let _ = Ring::deposit_creating(&200, COIN); +// let _ = Ring::deposit_creating(&2000, MILLICENTS); +// let _ = Ring::deposit_creating(&1000, MILLICENTS); +// let _ = Ring::deposit_creating(&200, MILLICENTS); // // new validator -// let _ = Ring::deposit_creating(&2001, 2000 * COIN); -// Kton::deposit_creating(&2001, 10 * COIN); +// let _ = Ring::deposit_creating(&2001, 2000 * MILLICENTS); +// Kton::deposit_creating(&2001, 10 * MILLICENTS); // // new validator -// let _ = Ring::deposit_creating(&1001, 300 * COIN); -// Kton::deposit_creating(&1001, 1 * COIN); +// let _ = Ring::deposit_creating(&1001, 300 * MILLICENTS); +// Kton::deposit_creating(&1001, 1 * MILLICENTS); // // handle some dirty work -// let _ = Ring::deposit_creating(&201, 2000 * COIN); -// Kton::deposit_creating(&201, 10 * COIN); -// assert_eq!(Kton::free_balance(&201), 10 * COIN); +// let _ = Ring::deposit_creating(&201, 2000 * MILLICENTS); +// Kton::deposit_creating(&201, 10 * MILLICENTS); +// assert_eq!(Kton::free_balance(&201), 10 * MILLICENTS); // // // 2001-2000 // assert_ok!(Staking::bond( // Origin::signed(2001), // 2000, -// StakingBalance::Ring(300 * COIN), +// StakingBalance::Ring(300 * MILLICENTS), // RewardDestination::Controller, // 12, // )); // assert_ok!(Staking::bond_extra( // Origin::signed(2001), -// StakingBalance::Kton(1 * COIN), +// StakingBalance::Kton(1 * MILLICENTS), // 0 // )); // // 1001-1000 // assert_ok!(Staking::bond( // Origin::signed(1001), // 1000, -// StakingBalance::Ring(300 * COIN), +// StakingBalance::Ring(300 * MILLICENTS), // RewardDestination::Controller, // 12, // )); // assert_ok!(Staking::bond_extra( // Origin::signed(1001), -// StakingBalance::Kton(1 * COIN), +// StakingBalance::Kton(1 * MILLICENTS), // 0 // )); // let ring_pool = Staking::ring_pool(); @@ -621,29 +630,29 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // assert_ok!(Staking::bond( // Origin::signed(201), // 200, -// StakingBalance::Ring(3000 * COIN - ring_pool), +// StakingBalance::Ring(3000 * MILLICENTS - ring_pool), // RewardDestination::Stash, // 12, // )); // assert_ok!(Staking::bond_extra( // Origin::signed(201), -// StakingBalance::Kton(10 * COIN - kton_pool), +// StakingBalance::Kton(10 * MILLICENTS - kton_pool), // 0, // )); // // ring_pool and kton_pool -// assert_eq!(Staking::ring_pool(), 3000 * COIN); -// assert_eq!(Staking::kton_pool(), 10 * COIN); +// assert_eq!(Staking::ring_pool(), 3000 * MILLICENTS); +// assert_eq!(Staking::kton_pool(), 10 * MILLICENTS); // // 1/5 ring_pool and 1/5 kton_pool // assert_ok!(Staking::validate(Origin::signed(2000), [0; 8].to_vec(), 0, 3)); // assert_ok!(Staking::nominate(Origin::signed(1000), vec![2001])); // -// assert_eq!(Staking::ledger(&2000).unwrap().active_kton, 1 * COIN); -// assert_eq!(Staking::ledger(&2000).unwrap().active_ring, 300 * COIN); +// assert_eq!(Staking::ledger(&2000).unwrap().active_kton, 1 * MILLICENTS); +// assert_eq!(Staking::ledger(&2000).unwrap().active_ring, 300 * MILLICENTS); // assert_eq!(Staking::power_of(&2001), 1_000_000_000 / 10 as u128); // // 600COIN for rewarding ring bond-er // // 600COIN for rewarding kton bond-er // Staking::select_validators(); -// Staking::reward_validator(&2001, 1200 * COIN); +// Staking::reward_validator(&2001, 1200 * MILLICENTS); // // assert_eq!( // Staking::stakers(2001), @@ -656,33 +665,33 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // }] // } // ); -// assert_eq!(Ring::free_balance(&2000), 601 * COIN); -// assert_eq!(Ring::free_balance(&1000), 601 * COIN); +// assert_eq!(Ring::free_balance(&2000), 601 * MILLICENTS); +// assert_eq!(Ring::free_balance(&1000), 601 * MILLICENTS); // }); //} // //#[test] //fn slash_should_work() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -// let _ = Ring::deposit_creating(&1001, 100 * COIN); -// Kton::deposit_creating(&1001, 100 * COIN); +// let _ = Ring::deposit_creating(&1001, 100 * MILLICENTS); +// Kton::deposit_creating(&1001, 100 * MILLICENTS); // // assert_ok!(Staking::bond( // Origin::signed(1001), // 1000, -// StakingBalance::Ring(50 * COIN), +// StakingBalance::Ring(50 * MILLICENTS), // RewardDestination::Controller, // 0, // )); // assert_ok!(Staking::bond_extra( // Origin::signed(1001), -// StakingBalance::Kton(50 * COIN), +// StakingBalance::Kton(50 * MILLICENTS), // 0 // )); // assert_ok!(Staking::validate(Origin::signed(1000), [0; 8].to_vec(), 0, 3)); // // // slash 1% -// let slash_value = 5 * COIN / 10; +// let slash_value = 5 * MILLICENTS / 10; // let mut ledger = Staking::ledger(&1000).unwrap(); // let ring_free_balance = Ring::free_balance(&1001); // let kton_free_balance = Kton::free_balance(&1001); @@ -698,10 +707,10 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { //#[test] ////fn test_inflation() { //// ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -//// assert_eq!(Staking::current_era_total_reward(), 80_000_000 * COIN / 10); +//// assert_eq!(Staking::current_era_total_reward(), 80_000_000 * MILLICENTS / 10); //// start_era(20); //// assert_eq!(Staking::epoch_index(), 2); -//// assert_eq!(Staking::current_era_total_reward(), 9_999_988_266 * COIN / 1000); +//// assert_eq!(Staking::current_era_total_reward(), 9_999_988_266 * MILLICENTS / 1000); //// }); ////} //#[test] @@ -722,9 +731,9 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { //#[test] //fn set_controller_should_not_change_ledger() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { -// assert_eq!(Staking::ledger(&10).unwrap().active_ring, 100 * COIN); +// assert_eq!(Staking::ledger(&10).unwrap().active_ring, 100 * MILLICENTS); // assert_ok!(Staking::set_controller(Origin::signed(11), 12)); -// assert_eq!(Staking::ledger(&12).unwrap().active_ring, 100 * COIN); +// assert_eq!(Staking::ledger(&12).unwrap().active_ring, 100 * MILLICENTS); // }); //} // @@ -738,29 +747,29 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // old_ledger.active_ring, // old_ledger.active_deposit_ring // ), -// (100 * COIN, 100 * COIN) +// (100 * MILLICENTS, 100 * MILLICENTS) // ); // // assert_ok!(Staking::bond_extra( // Origin::signed(11), -// StakingBalance::Ring(100 * COIN), +// StakingBalance::Ring(100 * MILLICENTS), // 0 // )); -// Kton::deposit_creating(&11, 10 * COIN); +// Kton::deposit_creating(&11, 10 * MILLICENTS); // assert_ok!(Staking::bond_extra( // Origin::signed(11), -// StakingBalance::Kton(10 * COIN), +// StakingBalance::Kton(10 * MILLICENTS), // 0 // )); // -// assert_ok!(Staking::unbond(Origin::signed(10), StakingBalance::Ring(10 * COIN))); +// assert_ok!(Staking::unbond(Origin::signed(10), StakingBalance::Ring(10 * MILLICENTS))); // let new_ledger = Staking::ledger(&10).unwrap(); // assert_eq!( // ( // new_ledger.active_ring, // new_ledger.active_deposit_ring // ), -// (190 * COIN, 100 * COIN) +// (190 * MILLICENTS, 100 * MILLICENTS) // ); // // // slash 100% @@ -772,7 +781,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // 10Ring in unbondings // (0, 0) // ); -// assert_eq!(ledger.unbondings[0].value, StakingBalance::Ring(10 * COIN)); +// assert_eq!(ledger.unbondings[0].value, StakingBalance::Ring(10 * MILLICENTS)); // }); //} // @@ -784,7 +793,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Staking::bond( // Origin::signed(stash), // controller, -// StakingBalance::Ring(COIN), +// StakingBalance::Ring(MILLICENTS), // RewardDestination::Stash, // 37 // ), @@ -793,7 +802,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // gen_paired_account!(stash(123), controller(456), promise_month(12)); // assert_err!( -// Staking::bond_extra(Origin::signed(stash), StakingBalance::Ring(COIN), 37), +// Staking::bond_extra(Origin::signed(stash), StakingBalance::Ring(MILLICENTS), 37), // "months at most is 36." // ); // }); @@ -807,7 +816,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Staking::bond( // Origin::signed(11), // unpaired_controller, -// StakingBalance::Ring(COIN), +// StakingBalance::Ring(MILLICENTS), // RewardDestination::Stash, // 0 // ), @@ -817,7 +826,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Staking::bond( // Origin::signed(unpaired_stash), // 10, -// StakingBalance::Ring(COIN), +// StakingBalance::Ring(MILLICENTS), // RewardDestination::Stash, // 0 // ), @@ -835,54 +844,54 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // bond: 100COIN // gen_paired_account!(stash_1(111), controller_1(222), 0); // gen_paired_account!(stash_2(333), controller_2(444), promise_month(12)); -// ring_pool += 100 * COIN; -// kton_pool += 100 * COIN; +// ring_pool += 100 * MILLICENTS; +// kton_pool += 100 * MILLICENTS; // assert_eq!(Staking::ring_pool(), ring_pool); // assert_eq!(Staking::kton_pool(), kton_pool); // // // unbond: 50Ring 50Kton // assert_ok!(Staking::unbond( // Origin::signed(controller_1), -// StakingBalance::Ring(50 * COIN) +// StakingBalance::Ring(50 * MILLICENTS) // )); // assert_ok!(Staking::unbond( // Origin::signed(controller_1), -// StakingBalance::Kton(25 * COIN) +// StakingBalance::Kton(25 * MILLICENTS) // )); // // not yet expired: promise for 12 months // assert_ok!(Staking::unbond( // Origin::signed(controller_2), -// StakingBalance::Ring(50 * COIN) +// StakingBalance::Ring(50 * MILLICENTS) // )); // assert_ok!(Staking::unbond( // Origin::signed(controller_2), -// StakingBalance::Kton(25 * COIN) +// StakingBalance::Kton(25 * MILLICENTS) // )); -// ring_pool -= 50 * COIN; -// kton_pool -= 50 * COIN; +// ring_pool -= 50 * MILLICENTS; +// kton_pool -= 50 * MILLICENTS; // assert_eq!(Staking::ring_pool(), ring_pool); // assert_eq!(Staking::kton_pool(), kton_pool); // // // unbond with punish: 12.5Ring // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller_2), -// 125 * COIN / 10, +// 125 * MILLICENTS / 10, // promise_month * MONTH_IN_SECONDS as u64 // )); // // unbond deposit items: 12.5Ring // Timestamp::set_timestamp(promise_month * MONTH_IN_SECONDS as u64); // assert_ok!(Staking::unbond( // Origin::signed(controller_2), -// StakingBalance::Ring(125 * COIN / 10) +// StakingBalance::Ring(125 * MILLICENTS / 10) // )); -// ring_pool -= 25 * COIN; +// ring_pool -= 25 * MILLICENTS; // assert_eq!(Staking::ring_pool(), ring_pool); // // // slash: 25Ring 50Kton // Staking::slash_validator(&stash_1, 1_000_000_000); // Staking::slash_validator(&stash_2, 1_000_000_000); -// ring_pool -= 25 * COIN; -// kton_pool -= 50 * COIN; +// ring_pool -= 25 * MILLICENTS; +// kton_pool -= 50 * MILLICENTS; // assert_eq!(Staking::ring_pool(), ring_pool); // assert_eq!(Staking::kton_pool(), kton_pool); // }); @@ -897,7 +906,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // for _ in 1..deposit_items_len { // assert_ok!(Staking::bond_extra( // Origin::signed(stash), -// StakingBalance::Ring(COIN), +// StakingBalance::Ring(MILLICENTS), // promise_month // )); // } @@ -910,7 +919,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Timestamp::set_timestamp(promise_month as u64 * MONTH_IN_SECONDS as u64); // // for _ in 1..deposit_items_len { -// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(COIN))); +// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(MILLICENTS))); // } // { // let ledger = Staking::ledger(&controller).unwrap(); @@ -920,7 +929,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // assert_err!( // Staking::unbond( // Origin::signed(controller), -// StakingBalance::Ring((deposit_items_len - 1) as u64 * COIN) +// StakingBalance::Ring((deposit_items_len - 1) as u64 * MILLICENTS) // ), // "can not schedule more unlock chunks" // ); @@ -934,34 +943,34 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // { // let stash = 444; // let controller = 555; -// let _ = Ring::deposit_creating(&stash, 100 * COIN); -// Kton::deposit_creating(&stash, 100 * COIN); +// let _ = Ring::deposit_creating(&stash, 100 * MILLICENTS); +// Kton::deposit_creating(&stash, 100 * MILLICENTS); // // assert_ok!(Staking::bond( // Origin::signed(stash), // controller, -// StakingBalance::Ring(50 * COIN), +// StakingBalance::Ring(50 * MILLICENTS), // RewardDestination::Stash, // 0 // )); // assert_ok!(Staking::bond_extra( // Origin::signed(stash), -// StakingBalance::Kton(50 * COIN), +// StakingBalance::Kton(50 * MILLICENTS), // 0 // )); // // let mut unbondings = Staking::ledger(&controller).unwrap().unbondings; // -// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(COIN))); +// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(MILLICENTS))); // unbondings.push(NormalLock { -// value: StakingBalance::Ring(COIN), +// value: StakingBalance::Ring(MILLICENTS), // era: 3, // is_time_deposit: false, // }); // assert_eq!(&Staking::ledger(&controller).unwrap().unbondings, &unbondings); -// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Kton(COIN))); +// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Kton(MILLICENTS))); // unbondings.push(NormalLock { -// value: StakingBalance::Kton(COIN), +// value: StakingBalance::Kton(MILLICENTS), // era: 3, // is_time_deposit: false, // }); @@ -989,13 +998,13 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // assert_ok!(Staking::bond_extra( // Origin::signed(stash), -// StakingBalance::Ring(50 * COIN), +// StakingBalance::Ring(50 * MILLICENTS), // 36 // )); // // let mut unbondings = Staking::ledger(&controller).unwrap().unbondings; // -// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(COIN))); +// assert_ok!(Staking::unbond(Origin::signed(controller), StakingBalance::Ring(MILLICENTS))); // unbondings.push(NormalLock { // value: StakingBalance::Ring(0), // era: 3, @@ -1006,11 +1015,11 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // for month in [12, 36].iter() { // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 20 * COIN, +// 20 * MILLICENTS, // month * MONTH_IN_SECONDS as u64 // )); // unbondings.push(NormalLock { -// value: StakingBalance::Ring(20 * COIN), +// value: StakingBalance::Ring(20 * MILLICENTS), // era: 3, // is_time_deposit: true, // }); @@ -1018,11 +1027,11 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 29 * COIN, +// 29 * MILLICENTS, // month * MONTH_IN_SECONDS as u64 // )); // unbondings.push(NormalLock { -// value: StakingBalance::Ring(29 * COIN), +// value: StakingBalance::Ring(29 * MILLICENTS), // era: 3, // is_time_deposit: true, // }); @@ -1030,11 +1039,11 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 50 * COIN, +// 50 * MILLICENTS, // month * MONTH_IN_SECONDS as u64 // )); // unbondings.push(NormalLock { -// value: StakingBalance::Ring(1 * COIN), +// value: StakingBalance::Ring(1 * MILLICENTS), // era: 3, // is_time_deposit: true, // }); @@ -1062,17 +1071,17 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // assert_ok!(Staking::bond_extra( // Origin::signed(stash), -// StakingBalance::Ring(5 * COIN), +// StakingBalance::Ring(5 * MILLICENTS), // 0 // )); // for _ in 0..expired_item_len { -// assert_ok!(Staking::promise_extra(Origin::signed(controller), COIN, promise_month)); +// assert_ok!(Staking::promise_extra(Origin::signed(controller), MILLICENTS, promise_month)); // } // // Timestamp::set_timestamp(expiry_date - 1); // assert_ok!(Staking::promise_extra( // Origin::signed(controller), -// 2 * COIN, +// 2 * MILLICENTS, // promise_month // )); // assert_eq!( @@ -1083,7 +1092,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // Timestamp::set_timestamp(expiry_date); // assert_ok!(Staking::promise_extra( // Origin::signed(controller), -// 2 * COIN, +// 2 * MILLICENTS, // promise_month // )); // assert_eq!(Staking::ledger(&controller).unwrap().deposit_items.len(), 2); @@ -1094,7 +1103,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { //fn unbond_zero_before_expiry() { // ExtBuilder::default().existential_deposit(0).build().execute_with(|| { // let expiry_date = 12 * MONTH_IN_SECONDS as u64; -// let unbond_value = StakingBalance::Ring(COIN); +// let unbond_value = StakingBalance::Ring(MILLICENTS); // // Timestamp::set_timestamp(expiry_date - 1); // assert_ok!(Staking::unbond(Origin::signed(10), unbond_value.clone())); @@ -1143,7 +1152,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 10_000 * COIN, +// 10_000 * MILLICENTS, // 12 * MONTH_IN_SECONDS as u64 // )); // assert_eq!(Kton::free_balance(&stash), 1); @@ -1167,7 +1176,7 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // // not enough Kton to unbond // assert_ok!(Staking::unbond_with_punish( // Origin::signed(controller), -// 10_000 * COIN, +// 10_000 * MILLICENTS, // 36 * MONTH_IN_SECONDS as u64 // )); // assert_eq!(&Staking::ledger(&controller).unwrap(), &ledger); @@ -1207,8 +1216,8 @@ fn time_deposit_ring_unbond_and_withdraw_should_work() { // if with_new_era { // start_era(2); // } -// Staking::reward_validator(&validator_1_stash, 1000 * COIN); -// Staking::reward_validator(&validator_2_stash, 1000 * COIN); +// Staking::reward_validator(&validator_1_stash, 1000 * MILLICENTS); +// Staking::reward_validator(&validator_2_stash, 1000 * MILLICENTS); // // balance = Ring::free_balance(&nominator_stash); // }); From c4d4aeddc52bec428df9815897efd41812f31962 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 22 Nov 2019 18:44:41 +0800 Subject: [PATCH 2/2] update: primitives, patch for #102 --- node/cli/src/chain_spec.rs | 32 +++++++++++++++----------------- node/runtime/src/constants.rs | 7 ++++--- node/runtime/src/lib.rs | 12 ++++++------ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index b6fb9af20..243eae826 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -15,26 +15,24 @@ // along with Substrate. If not, see . //! 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::{ - constants::currency::MILLICENTS, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, - GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, - SudoConfig, SystemConfig, WASM_BINARY, + constants::currency::{COIN, MILLI}, + 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; @@ -195,8 +193,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 { @@ -230,7 +228,7 @@ pub fn testnet_genesis( enable_println, // this should only be enabled on development chains ..Default::default() }, - gas_price: 1 * MILLICENTS, + gas_price: 1 * MILLI, }), sudo: Some(SudoConfig { key: root_key }), babe: Some(BabeConfig { authorities: vec![] }), @@ -249,7 +247,7 @@ pub fn testnet_genesis( }), staking: Some(StakingConfig { current_era: 0, - // current_era_total_reward: 80_000_000 * MILLICENTS / 63720, + // current_era_total_reward: 80_000_000 * MILLI / 63720, // offline_slash: Perbill::from_parts(1_000_000), session_reward: Perbill::from_percent(90), validator_count: 7, @@ -350,8 +348,8 @@ pub fn darwinia_genesis_verbose( ] }); - const ENDOWMENT: Balance = 100_000_000 * MILLICENTS; - const STASH: Balance = 100 * MILLICENTS; + const ENDOWMENT: Balance = 100_000_000 * MILLI; + const STASH: Balance = 100 * MILLI; GenesisConfig { system: Some(SystemConfig { @@ -385,7 +383,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 * MILLI, }), sudo: Some(SudoConfig { key: root_key }), babe: Some(BabeConfig { authorities: vec![] }), @@ -404,7 +402,7 @@ pub fn darwinia_genesis_verbose( }), staking: Some(StakingConfig { current_era: 0, - // current_era_total_reward: 80_000_000 * MILLICENTS / 63720, + // current_era_total_reward: 80_000_000 * MILLI / 63720, // offline_slash: Perbill::from_parts(1_000_000), session_reward: Perbill::from_percent(90), validator_count: 7, diff --git a/node/runtime/src/constants.rs b/node/runtime/src/constants.rs index 39dc0dc7b..e20583184 100644 --- a/node/runtime/src/constants.rs +++ b/node/runtime/src/constants.rs @@ -23,9 +23,10 @@ pub mod currency { pub const NANO: Balance = 1; pub const MICRO: Balance = 1_000 * NANO; pub const MILLI: Balance = 1_000 * MICRO; - pub const MILLICENTS: Balance = 1_000 * MILLI; - pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. - pub const DOLLARS: Balance = 100 * CENTS; + pub const COIN: Balance = 1_000 * MILLI; + // pub const MILLICENTS: Balance = 1_000 * MILLI; + // pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. + // pub const DOLLARS: Balance = 100 * CENTS; } /// Time. diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 5b0de4faf..ae2b4a237 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -151,7 +151,7 @@ impl indices::Trait for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * MILLICENTS; + pub const ExistentialDeposit: Balance = 1 * COIN; pub const TransferFee: Balance = 1 * MILLI; pub const CreationFee: Balance = 1 * MILLI; } @@ -295,10 +295,10 @@ parameter_types! { pub const ContractTransactionBaseFee: Balance = 1 * MILLI; pub const ContractTransactionByteFee: Balance = 10 * MICRO; pub const ContractFee: Balance = 1 * MILLI; - pub const TombstoneDeposit: Balance = 1 * MILLICENTS; - pub const RentByteFee: Balance = 1 * MILLICENTS; - pub const RentDepositOffset: Balance = 1000 * MILLICENTS; - pub const SurchargeReward: Balance = 150 * MILLICENTS; + pub const TombstoneDeposit: Balance = 1 * COIN; + pub const RentByteFee: Balance = 1 * COIN; + pub const RentDepositOffset: Balance = 1000 * COIN; + pub const SurchargeReward: Balance = 150 * COIN; } impl contracts::Trait for Runtime { type Currency = Balances; @@ -375,7 +375,7 @@ parameter_types! { // 365 days * 24 hours * 60 minutes / 5 minutes pub const ErasPerEpoch: EraIndex = 105120; // decimal 9 - pub const HardCap: Balance = 10_000_000_000 * MILLICENTS; + pub const HardCap: Balance = 10_000_000_000 * COIN; pub const GenesisTime: Moment = 1_574_156_000_000; } impl staking::Trait for Runtime {