Skip to content

Commit

Permalink
Merge pull request #102 from AurevoirXavier/update-test
Browse files Browse the repository at this point in the history
update: sync tests and runtime primitives
  • Loading branch information
hackfisher authored Nov 27, 2019
2 parents c5adb0c + 45729fd commit 027e809
Show file tree
Hide file tree
Showing 13 changed files with 1,089 additions and 1,383 deletions.
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

0 comments on commit 027e809

Please sign in to comment.