Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make a test crate to make the runtime-test usable #1258

Merged
merged 111 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
7a956fb
WIP
cecton Jun 12, 2020
9dd9118
WIP
cecton Jun 12, 2020
ffa95f1
WIP
cecton Jun 15, 2020
b5ee29e
CLEANUP
cecton Jun 15, 2020
d2428b4
CLEANUP
cecton Jun 15, 2020
587870d
CLEANUP
cecton Jun 15, 2020
886d76f
Rename to polkadot-test-service and rename dir
cecton Jun 15, 2020
6306561
Merge commit b2c9c14971f1f06400c6522e40d02e79c0f11a05 (no conflict)
cecton Jun 15, 2020
6c95310
Bump spec_version
cecton Jun 15, 2020
555715a
Move code to macro to avoid adding pub fn to API
cecton Jun 15, 2020
4a3b4b0
CLEANUP
cecton Jun 15, 2020
0d506a1
Fixed missing import
cecton Jun 15, 2020
16f1c67
Fix missing import
cecton Jun 15, 2020
9e1bf51
WIP
cecton Jun 15, 2020
186a764
CLEANUP
cecton Jun 15, 2020
528b2ed
WIP Attempt to make a test
cecton Jun 15, 2020
88c57d3
Change most const to storage
cecton Jun 16, 2020
b5b219e
Add Get impl
cecton Jun 16, 2020
9aba20a
Move everything to the test crate to create an API
cecton Jun 16, 2020
83d9bf3
create chain spec
cecton Jun 16, 2020
84fe08a
Parametrize storage update
cecton Jun 16, 2020
df43948
CLEANUP
cecton Jun 16, 2020
7a27276
regex to the rescue
cecton Jun 16, 2020
29b8a34
Improving API
cecton Jun 16, 2020
4ca5082
format
cecton Jun 16, 2020
f67af13
WIP
cecton Jun 17, 2020
5ae1794
WIP
cecton Jun 17, 2020
0061afe
WIP
cecton Jun 18, 2020
2fd2d71
WIP
cecton Jun 18, 2020
899505d
use memory
cecton Jun 18, 2020
25eb924
fixing last commit
cecton Jun 19, 2020
780fbdf
WIP
cecton Jun 19, 2020
302fa9a
max allowed time
cecton Jun 19, 2020
a3ba37b
CLEANUP
cecton Jun 19, 2020
d36cdc2
fmt
cecton Jun 19, 2020
960f1f1
Revert Cargo.lock
cecton Jun 19, 2020
de25f24
CLEANUP
cecton Jun 19, 2020
ee93ecd
Added sudo
cecton Jun 19, 2020
cd96ffb
Merge commit b0b444ce5439849cbffea1d07dd710957402c064 (no conflict)
cecton Jun 19, 2020
d42d727
Merge commit a16cc4da50fa0205187c4babecc34f695918b63e (conflicts)
cecton Jun 19, 2020
95e1a87
Merge commit 79a0df2f77f9d896b7b1790d04fb09355b6cccd2 (no conflict)
cecton Jun 19, 2020
30c0dd7
Merge commit daf0073759f66a63b17abe1f8cdcaec93640afc9 (conflicts)
cecton Jun 19, 2020
f48b071
fix merge upgrade
cecton Jun 19, 2020
9c04748
Cargo.lock
cecton Jun 19, 2020
4730489
Merge commit fb66e42fe51d70d93688461aa6654cd87bc61db2 (no conflict)
cecton Jun 19, 2020
3a0eee3
Fixed slot_duration for test w/ and w/out service
cecton Jun 22, 2020
f2444bc
increase spec version
cecton Jun 22, 2020
fb62093
Merge commit 4f79b770dc9d891739cc8dbadd62f7d9d8e36a58 (no conflict)
cecton Jun 22, 2020
acb88cc
better fix
cecton Jun 22, 2020
6e5e060
Update runtime/test-runtime/client/src/lib.rs
cecton Jun 22, 2020
3de82c2
Added doc and simplified API
cecton Jun 30, 2020
8f4245d
Make wait_for_blocks more generic to avoid duplication in cumulus
cecton Jun 30, 2020
605da30
Merge commit 39a3605224791f0b8fcd41af2f9636b83403780e (no conflict)
cecton Jun 30, 2020
9467bd8
Merge commit b05bb8f6336928dd9fb5711036f98c38a854650a (conflicts)
cecton Jun 30, 2020
b723dea
Merge commit 0762de59f975fe2392fd6ca28dc3bd904df7f3a8 (no conflict)
cecton Jun 30, 2020
be679dd
Merge commit 51ce2b31230d6debdcd04f6bf9b345ec92544b94 (conflicts)
cecton Jun 30, 2020
4816880
Removed base_path as this is not needed anymore
cecton Jun 30, 2020
f35262e
Helper to send transaction more easily
cecton Jun 30, 2020
74ab47c
Fix indent
cecton Jul 1, 2020
be3889b
Added test for send-transaction
cecton Jul 1, 2020
73ae473
Ensure task_manager dropped after task finish
cecton Jul 1, 2020
b8ec09d
Improve logging by using informant prefix
cecton Jul 1, 2020
36fec81
Update polkadot-test-service/src/lib.rs
cecton Jul 1, 2020
178ab7b
Update polkadot-test-service/src/lib.rs
cecton Jul 1, 2020
de65c05
Update polkadot-test-service/src/lib.rs
cecton Jul 1, 2020
abf0f35
Replace asserts with expects
cecton Jul 1, 2020
6bae984
Merged imports
cecton Jul 1, 2020
261c552
Revert slot duration change
cecton Jul 1, 2020
4fc1a58
Helper to call a function
cecton Jul 1, 2020
5796cd5
Update substrate branch to cecton-testing-helpers
cecton Jul 2, 2020
91bf6bb
CLEANUP
cecton Jul 2, 2020
a6a54b5
Revert "Update substrate branch to cecton-testing-helpers"
cecton Jul 2, 2020
3092be3
Merge commit 90d5dbe564ae795d68aff1c936cbdd1f98c9d536 (no conflict)
cecton Jul 2, 2020
6dce9b1
Update substrate branch to cecton-testing-helpers
cecton Jul 2, 2020
a8fe1dd
CLEANUP
cecton Jul 2, 2020
df63aa1
CLEANUP
cecton Jul 2, 2020
0cdda37
Add test runtime to command
cecton Jun 30, 2020
5b4fcfd
replaced panic with clean error
cecton Jul 2, 2020
36c8c65
Simplify test
cecton Jul 2, 2020
cf3fb7b
rename test
cecton Jul 2, 2020
2bbe1b6
Revert "Add test runtime to command"
cecton Jul 3, 2020
f97dd0c
increase kusama
cecton Jul 3, 2020
523366e
Update substrate
cecton Jul 3, 2020
6be349f
Revert to master
cecton Jul 3, 2020
fb41215
Merge commit aeb79d47345e2e5d6320e0f2c11cb70df1e614e4 (no conflict)
cecton Jul 3, 2020
5550cbb
Merge commit 0a7d04d00edc50488b2d6c34db685dac2234d749 (no conflict)
cecton Jul 3, 2020
c4cd5fb
Cargo.lock again
cecton Jul 3, 2020
a44b1c0
removed unused id prefix
cecton Jul 3, 2020
e8573ae
fix update
cecton Jul 3, 2020
fd8a9d7
Merge commit 21f31f78de36c6a36defb0fa0ee0052df35a0d0f (no conflict)
cecton Jul 5, 2020
fc00d0c
Merge commit 78e6e08e9e4524faddad463bbadbaf2c70e47256 (conflicts)
cecton Jul 5, 2020
5916b39
Update runtime/test-runtime/src/lib.rs
cecton Jul 6, 2020
d620fc6
Update polkadot-test-service/src/lib.rs
cecton Jul 6, 2020
f108a3f
apply suggestions
cecton Jul 6, 2020
602814a
add missing license
cecton Jul 7, 2020
00316bd
Merge commit 8348cc4cb0aea625cd6868dcc4faa6633d0f8d9e (no conflict)
cecton Jul 7, 2020
42545d5
Move polkadot-test-service to node/test-service
cecton Jul 7, 2020
c94459c
Sort dependencies and group
cecton Jul 7, 2020
1637455
Attempt to remove genesismap
cecton Jul 7, 2020
90750a1
Pass parameters
cecton Jul 7, 2020
35e8ab1
Merge commit 891767bcd28a4a53fbc17ba87c2cc2d48758e35f (no conflict)
cecton Jul 7, 2020
5fb41d2
another attempt to fix the test
cecton Jul 7, 2020
7fa0a85
Merge remote-tracking branch 'origin/master' into cecton-polkadot-tes…
bkchr Jul 9, 2020
6a65f87
Revert "another attempt to fix the test"
bkchr Jul 9, 2020
c74756a
Fix tests
bkchr Jul 9, 2020
f94de16
Update substrate
cecton Jul 9, 2020
e606833
adapt code
cecton Jul 9, 2020
4e65412
fix
cecton Jul 9, 2020
b44f302
unused import
cecton Jul 9, 2020
f3b3142
WIP
cecton Jul 9, 2020
d32f811
replace async_std with tokio
cecton Jul 9, 2020
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
342 changes: 205 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ members = [
"node/service",
"node/subsystem",
"node/test-helpers/subsystem",
"node/test-service",

"parachain/test-parachains",
"parachain/test-parachains/adder",
Expand Down
2 changes: 1 addition & 1 deletion network/test/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>)
let mut client = polkadot_test_runtime_client::new();
let mut builder = client.new_block(Default::default()).unwrap();

let extrinsics = polkadot_test_runtime_client::needed_extrinsics(vec![]);
let extrinsics = polkadot_test_runtime_client::needed_extrinsics(vec![], 0);

for extrinsic in &extrinsics {
builder.push(extrinsic.clone()).unwrap();
Expand Down
8 changes: 6 additions & 2 deletions node/service/src/grandpa_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,21 @@ mod tests {

let mut push_blocks = {
let mut client = client.clone();
let mut base = 0;

move |n| {
for _ in 0..n {
for i in 0..n {
let mut builder = client.new_block(Default::default()).unwrap();

for extrinsic in polkadot_test_runtime_client::needed_extrinsics(vec![]) {
for extrinsic in polkadot_test_runtime_client::needed_extrinsics(vec![], base + i) {
builder.push(extrinsic).unwrap()
}

let block = builder.build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();
}

base += n;
}
};

Expand Down
56 changes: 56 additions & 0 deletions node/test-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "polkadot-test-service"
version = "0.8.2"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
futures = "0.3.4"
futures01 = { package = "futures", version = "0.1.29" }
hex = "0.4"
log = "0.4.8"
rand = "0.7.3"
tempfile = "3.1.0"

# Polkadot dependencies
av_store = { package = "polkadot-availability-store", path = "../../availability-store" }
consensus = { package = "polkadot-validation", path = "../../validation" }
polkadot-network = { path = "../../network" }
polkadot-primitives = { path = "../../primitives" }
polkadot-rpc = { path = "../../rpc" }
polkadot-runtime-common = { path = "../../runtime/common" }
polkadot-service = { path = "../../service" }
polkadot-test-runtime = { path = "../../runtime/test-runtime" }

# Substrate dependencies
authority-discovery = { package = "sc-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "master" }
babe = { package = "sc-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "master" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
grandpa_primitives = { package = "sp-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "master" }

[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
serde_json = "1.0"
tokio = { version = "0.2", features = ["macros"] }
184 changes: 184 additions & 0 deletions node/test-service/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use babe_primitives::AuthorityId as BabeId;
use grandpa::AuthorityId as GrandpaId;
use pallet_staking::Forcing;
use polkadot_primitives::{parachain::ValidatorId, AccountId};
use polkadot_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions};
use polkadot_test_runtime::constants::currency::DOTS;
use sc_chain_spec::{ChainSpec, ChainType};
use sp_core::{sr25519, ChangesTrieConfiguration};
use sp_runtime::Perbill;

const DEFAULT_PROTOCOL_ID: &str = "dot";

/// The `ChainSpec parametrised for polkadot runtime`.
pub type PolkadotChainSpec =
service::GenericChainSpec<polkadot_test_runtime::GenesisConfig, Extensions>;

/// Polkadot local testnet config (multivalidator Alice + Bob)
pub fn polkadot_local_testnet_config() -> PolkadotChainSpec {
PolkadotChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
ChainType::Local,
|| polkadot_local_testnet_genesis(None),
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
None,
Default::default(),
)
}

/// Polkadot local testnet genesis config (multivalidator Alice + Bob)
pub fn polkadot_local_testnet_genesis(
changes_trie_config: Option<ChangesTrieConfiguration>,
) -> polkadot_test_runtime::GenesisConfig {
polkadot_testnet_genesis(
vec![
get_authority_keys_from_seed("Alice"),
get_authority_keys_from_seed("Bob"),
get_authority_keys_from_seed("Charlie"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
changes_trie_config,
)
}

/// Helper function to generate stash, controller and session key from seed
fn get_authority_keys_from_seed(
seed: &str,
) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId) {
(
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
get_account_id_from_seed::<sr25519::Public>(seed),
get_from_seed::<BabeId>(seed),
get_from_seed::<GrandpaId>(seed),
get_from_seed::<ValidatorId>(seed),
)
}

fn testnet_accounts() -> Vec<AccountId> {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
]
}

/// Helper function to create polkadot GenesisConfig for testing
fn polkadot_testnet_genesis(
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ValidatorId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
changes_trie_config: Option<ChangesTrieConfiguration>,
) -> polkadot_test_runtime::GenesisConfig {
use polkadot_test_runtime as polkadot;

let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);

const ENDOWMENT: u128 = 1_000_000 * DOTS;
const STASH: u128 = 100 * DOTS;

polkadot::GenesisConfig {
system: Some(polkadot::SystemConfig {
code: polkadot::WASM_BINARY.to_vec(),
changes_trie_config,
}),
indices: Some(polkadot::IndicesConfig { indices: vec![] }),
balances: Some(polkadot::BalancesConfig {
balances: endowed_accounts
.iter()
.map(|k| (k.clone(), ENDOWMENT))
.collect(),
}),
session: Some(polkadot::SessionConfig {
keys: initial_authorities
.iter()
.map(|x| {
(
x.0.clone(),
x.0.clone(),
polkadot_test_runtime::SessionKeys {
babe: x.2.clone(),
grandpa: x.3.clone(),
parachain_validator: x.4.clone(),
},
)
})
.collect::<Vec<_>>(),
}),
staking: Some(polkadot::StakingConfig {
minimum_validator_count: 1,
validator_count: 2,
stakers: initial_authorities
.iter()
.map(|x| {
(
x.0.clone(),
x.1.clone(),
STASH,
polkadot::StakerStatus::Validator,
)
})
.collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
force_era: Forcing::NotForcing,
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
babe: Some(Default::default()),
grandpa: Some(Default::default()),
authority_discovery: Some(polkadot::AuthorityDiscoveryConfig { keys: vec![] }),
parachains: Some(polkadot::ParachainsConfig {
authorities: vec![],
}),
registrar: Some(polkadot::RegistrarConfig {
parachains: vec![],
_phdata: Default::default(),
}),
claims: Some(polkadot::ClaimsConfig {
claims: vec![],
vesting: vec![],
}),
vesting: Some(polkadot::VestingConfig { vesting: vec![] }),
sudo: Some(polkadot::SudoConfig { key: root_key }),
}
}

/// Can be called for a `Configuration` to check if it is a configuration for the `Test` network.
pub trait IdentifyVariant {
/// Returns if this is a configuration for the `Test` network.
fn is_test(&self) -> bool;
}

impl IdentifyVariant for Box<dyn ChainSpec> {
fn is_test(&self) -> bool {
self.id().starts_with("test")
}
}
Loading