Skip to content

Commit 027e809

Browse files
authored
Merge pull request #102 from AurevoirXavier/update-test
update: sync tests and runtime primitives
2 parents c5adb0c + 45729fd commit 027e809

File tree

13 files changed

+1089
-1383
lines changed

13 files changed

+1089
-1383
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/cli/src/chain_spec.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,23 @@
1515
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

1717
//! Substrate chain configurations.
18+
pub use node_runtime::GenesisConfig;
19+
1820
use babe_primitives::AuthorityId as BabeId;
1921
use chain_spec::ChainSpecExtension;
2022
use grandpa_primitives::AuthorityId as GrandpaId;
2123
use hex_literal::hex;
2224
use im_online::sr25519::AuthorityId as ImOnlineId;
2325
use node_primitives::{AccountId, Balance};
24-
use node_runtime::constants::currency::*;
25-
use node_runtime::Block;
26-
pub use node_runtime::GenesisConfig;
2726
use node_runtime::{
28-
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, GrandpaConfig, ImOnlineConfig,
29-
IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, COIN,
30-
WASM_BINARY,
27+
constants::currency::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, Block, ContractsConfig,
28+
GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
29+
SudoConfig, SystemConfig, WASM_BINARY,
3130
};
3231
use primitives::{crypto::UncheckedInto, Pair, Public};
3332
use serde::{Deserialize, Serialize};
34-
use serde_json::de::ParserNumber;
35-
use serde_json::Number;
33+
use serde_json::{de::ParserNumber, Number};
3634
use sr_primitives::Perbill;
37-
use substrate_service;
3835
use substrate_service::Properties;
3936
use substrate_telemetry::TelemetryEndpoints;
4037

@@ -195,8 +192,8 @@ pub fn testnet_genesis(
195192
]
196193
});
197194

198-
const ENDOWMENT: Balance = 10_000_000 * DOLLARS;
199-
const STASH: Balance = 100 * DOLLARS;
195+
const ENDOWMENT: Balance = 10_000_000 * COIN;
196+
const STASH: Balance = 100 * COIN;
200197

201198
GenesisConfig {
202199
system: Some(SystemConfig {
@@ -230,7 +227,7 @@ pub fn testnet_genesis(
230227
enable_println, // this should only be enabled on development chains
231228
..Default::default()
232229
},
233-
gas_price: 1 * MILLICENTS,
230+
gas_price: 1 * MICRO,
234231
}),
235232
sudo: Some(SudoConfig { key: root_key }),
236233
babe: Some(BabeConfig { authorities: vec![] }),
@@ -385,7 +382,7 @@ pub fn darwinia_genesis_verbose(
385382
enable_println, // this should only be enabled on development chains
386383
..Default::default()
387384
},
388-
gas_price: 1 * MILLICENTS,
385+
gas_price: 1 * MICRO,
389386
}),
390387
sudo: Some(SudoConfig { key: root_key }),
391388
babe: Some(BabeConfig { authorities: vec![] }),

node/runtime/src/constants.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
pub mod currency {
2121
use node_primitives::Balance;
2222

23-
pub const MILLICENTS: Balance = 1_000_000_000;
24-
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
25-
pub const DOLLARS: Balance = 100 * CENTS;
23+
pub const NANO: Balance = 1;
24+
pub const MICRO: Balance = 1_000 * NANO;
25+
pub const MILLI: Balance = 1_000 * MICRO;
26+
pub const COIN: Balance = 1_000 * MILLI;
2627
}
2728

2829
/// Time.

node/runtime/src/lib.rs

Lines changed: 44 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,60 +19,51 @@
1919
#![cfg_attr(not(feature = "std"), no_std)]
2020
#![recursion_limit = "256"]
2121

22-
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
23-
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
24-
pub use balances::Call as BalancesCall;
25-
use codec::{Decode, Encode};
22+
/// Constant values used within the runtime.
23+
pub mod constants;
24+
/// Implementations of some helper traits passed into runtime modules as associated types.
25+
pub mod impls;
26+
2627
pub use contracts::Gas;
27-
use sr_api::impl_runtime_apis;
28+
pub use timestamp::Call as TimestampCall;
2829

29-
//use grandpa::fg_primitives;
30-
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
31-
//use im_online::sr25519::AuthorityId as ImOnlineId;
30+
pub use balances::Call as BalancesCall;
31+
pub use staking::StakerStatus;
3232

33+
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
34+
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
35+
use codec::{Decode, Encode};
36+
use grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList};
37+
use im_online::sr25519::AuthorityId as ImOnlineId;
3338
use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature};
3439
use rstd::prelude::*;
35-
use sr_primitives::traits::{
36-
self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup,
40+
use sr_api::impl_runtime_apis;
41+
use sr_primitives::{
42+
create_runtime_str, generic, impl_opaque_keys,
43+
traits::{self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup},
44+
transaction_validity::TransactionValidity,
45+
weights::Weight,
46+
ApplyResult, Perbill,
3747
};
38-
use sr_primitives::transaction_validity::TransactionValidity;
39-
use sr_primitives::weights::Weight;
40-
#[cfg(any(feature = "std", test))]
41-
pub use sr_primitives::BuildStorage;
42-
43-
use sr_primitives::{create_runtime_str, generic, impl_opaque_keys, ApplyResult, Perbill};
4448
use substrate_primitives::u32_trait::{_1, _4};
45-
46-
use support::traits::OnUnbalanced;
47-
pub use support::StorageValue;
49+
use substrate_primitives::OpaqueMetadata;
4850
use support::{
4951
construct_runtime, parameter_types,
50-
traits::{Currency, Randomness, SplitTwoWays},
52+
traits::{Currency, OnUnbalanced, Randomness, SplitTwoWays},
5153
};
52-
53-
pub use timestamp::Call as TimestampCall;
54+
use system::offchain::TransactionSubmitter;
55+
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
5456
#[cfg(any(feature = "std", test))]
5557
use version::NativeVersion;
5658
use version::RuntimeVersion;
59+
//use grandpa::fg_primitives;
60+
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
61+
//use im_online::sr25519::AuthorityId as ImOnlineId;
5762

58-
use grandpa::fg_primitives;
59-
use grandpa::AuthorityList as GrandpaAuthorityList;
60-
use im_online::sr25519::AuthorityId as ImOnlineId;
61-
use substrate_primitives::OpaqueMetadata;
62-
use system::offchain::TransactionSubmitter;
63-
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
64-
63+
use constants::{currency::*, time::*};
6564
use darwinia_support::TimeStamp;
66-
use staking::EraIndex;
67-
pub use staking::StakerStatus;
68-
69-
/// Implementations of some helper traits passed into runtime modules as associated types.
70-
pub mod impls;
7165
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};
72-
73-
/// Constant values used within the runtime.
74-
pub mod constants;
75-
use constants::time::*;
66+
use staking::EraIndex;
7667

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

99-
pub const NANO: Balance = 1;
100-
pub const MICRO: Balance = 1_000 * NANO;
101-
pub const MILLI: Balance = 1_000 * MICRO;
102-
pub const COIN: Balance = 1_000 * MILLI;
103-
10490
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
91+
type DealWithFees = SplitTwoWays<
92+
Balance,
93+
NegativeImbalance,
94+
_4,
95+
MockTreasury, // 4 parts (80%) goes to the treasury.
96+
_1,
97+
Author, // 1 part (20%) goes to the block author.
98+
>;
10599

106100
//pub struct Author;
107101
//
@@ -118,20 +112,6 @@ impl OnUnbalanced<NegativeImbalance> for MockTreasury {
118112
}
119113
}
120114

121-
pub type DealWithFees = SplitTwoWays<
122-
Balance,
123-
NegativeImbalance,
124-
_4,
125-
MockTreasury, // 4 parts (80%) goes to the treasury.
126-
_1,
127-
Author, // 1 part (20%) goes to the block author.
128-
>;
129-
130-
pub const SECS_PER_BLOCK: BlockNumber = 6;
131-
pub const MINUTES: BlockNumber = 60 / SECS_PER_BLOCK;
132-
pub const HOURS: BlockNumber = MINUTES * 60;
133-
pub const DAYS: BlockNumber = HOURS * 24;
134-
135115
parameter_types! {
136116
pub const BlockHashCount: BlockNumber = 250;
137117
pub const MaximumBlockWeight: Weight = 1_000_000_000;
@@ -171,8 +151,8 @@ impl indices::Trait for Runtime {
171151

172152
parameter_types! {
173153
pub const ExistentialDeposit: Balance = 1 * COIN;
174-
pub const TransferFee: Balance = 1 * MILLI;
175-
pub const CreationFee: Balance = 1 * MILLI;
154+
pub const TransferFee: Balance = 1 * MICRO;
155+
pub const CreationFee: Balance = 1 * MICRO;
176156
}
177157
impl balances::Trait for Runtime {
178158
type Balance = Balance;
@@ -187,7 +167,7 @@ impl balances::Trait for Runtime {
187167
}
188168

189169
parameter_types! {
190-
pub const TransactionBaseFee: Balance = 1 * MILLI;
170+
pub const TransactionBaseFee: Balance = 1 * MICRO;
191171
pub const TransactionByteFee: Balance = 10 * MICRO;
192172
// setting this to zero will disable the weight fee.
193173
pub const WeightFeeCoefficient: Balance = 1_000;
@@ -309,11 +289,11 @@ impl finality_tracker::Trait for Runtime {
309289
}
310290

311291
parameter_types! {
312-
pub const ContractTransferFee: Balance = 1 * MILLI;
313-
pub const ContractCreationFee: Balance = 1 * MILLI;
314-
pub const ContractTransactionBaseFee: Balance = 1 * MILLI;
292+
pub const ContractTransferFee: Balance = 1 * MICRO;
293+
pub const ContractCreationFee: Balance = 1 * MICRO;
294+
pub const ContractTransactionBaseFee: Balance = 1 * MICRO;
315295
pub const ContractTransactionByteFee: Balance = 10 * MICRO;
316-
pub const ContractFee: Balance = 1 * MILLI;
296+
pub const ContractFee: Balance = 1 * MICRO;
317297
pub const TombstoneDeposit: Balance = 1 * COIN;
318298
pub const RentByteFee: Balance = 1 * COIN;
319299
pub const RentDepositOffset: Balance = 1000 * COIN;

srml/kton/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ darwinia-support = { path = "../support", default-features = false }
2222
runtime_io = { package = "sr-io", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }
2323
substrate-primitives = { git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }
2424

25+
node-runtime = { path = "../../node/runtime" }
26+
node-primitives = { path = "../../node/primitives" }
27+
2528
[features]
2629
default = ["std"]
2730
std = [

srml/kton/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

33
use codec::{Codec, Decode, Encode};
4-
#[cfg(not(feature = "std"))]
5-
use rstd::borrow::ToOwned;
64
use rstd::{cmp, fmt::Debug, prelude::*, result};
75
#[cfg(feature = "std")]
86
use sr_primitives::traits::One;

srml/kton/src/mock.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
pub use node_runtime::constants::currency::COIN;
2+
13
use std::{cell::RefCell, collections::HashSet};
24

35
use sr_primitives::{
46
testing::Header,
57
traits::{BlakeTwo256, IdentityLookup},
8+
weights::Weight,
69
Perbill,
710
};
811
use srml_support::{impl_outer_origin, parameter_types};
912
use substrate_primitives::H256;
1013

1114
use super::*;
1215
use crate::{GenesisConfig, Module};
13-
14-
pub const COIN: u64 = 1_000_000_000;
16+
use node_primitives::Balance;
1517

1618
thread_local! {
1719
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
18-
static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0);
20+
static EXISTENTIAL_DEPOSIT: RefCell<Balance> = RefCell::new(0);
1921
}
2022

2123
/// The AccountId alias in this test module.
2224
pub type AccountId = u64;
25+
// FIXME:
26+
// replace
27+
// testing::Header.number: u64
28+
// with
29+
// node_primitives::BlockNumber
2330
pub type BlockNumber = u64;
24-
pub type Balance = u64;
2531

2632
impl_outer_origin! {
2733
pub enum Origin for Test {}
@@ -31,8 +37,8 @@ impl_outer_origin! {
3137
#[derive(Clone, PartialEq, Eq, Debug)]
3238
pub struct Test;
3339
parameter_types! {
34-
pub const BlockHashCount: u64 = 250;
35-
pub const MaximumBlockWeight: u32 = 1024;
40+
pub const BlockHashCount: BlockNumber = 250;
41+
pub const MaximumBlockWeight: Weight = 1024;
3642
pub const MaximumBlockLength: u32 = 2 * 1024;
3743
pub const AvailableBlockRatio: Perbill = Perbill::one();
3844
}
@@ -71,7 +77,7 @@ impl Trait for Test {
7177
}
7278

7379
pub struct ExtBuilder {
74-
existential_deposit: u64,
80+
existential_deposit: Balance,
7581
}
7682

7783
impl Default for ExtBuilder {
@@ -81,7 +87,7 @@ impl Default for ExtBuilder {
8187
}
8288

8389
impl ExtBuilder {
84-
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
90+
pub fn existential_deposit(mut self, existential_deposit: Balance) -> Self {
8591
self.existential_deposit = existential_deposit;
8692
self
8793
}

srml/staking/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ substrate-primitives = { git = "https://github.com/darwinia-network/substrate.gi
2929
timestamp = { package = "srml-timestamp", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop" }
3030
rand = "0.7.2"
3131

32-
balances = { package = "darwinia-balances", path = '../balances', default-features = false }
32+
balances = { package = "darwinia-balances", path = '../balances' }
3333
kton = { package = "darwinia-kton", path = "../kton" }
3434
node-runtime = { path = "../../node/runtime" }
35+
node-primitives = { path = "../../node/primitives" }
3536

3637
[features]
3738
equalize = []

srml/staking/src/inflation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use substrate_primitives::U256;
99

1010
// 1 - (99 /100)^sqrt(year)
1111
// <T: Trait + 'static>() -> RingBalanceOf<T>
12-
pub fn compute_total_payout<T: Trait + 'static>(
12+
pub fn compute_total_payout<T: Trait>(
1313
era_duration: u64,
1414
living_time: u64,
1515
total_left: u128,
@@ -48,7 +48,7 @@ pub fn compute_total_payout<T: Trait + 'static>(
4848

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

0 commit comments

Comments
 (0)