This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make a test crate to make the runtime-test usable #1258
Merged
Merged
Changes from 91 commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
7a956fb
WIP
cecton 9dd9118
WIP
cecton ffa95f1
WIP
cecton b5ee29e
CLEANUP
cecton d2428b4
CLEANUP
cecton 587870d
CLEANUP
cecton 886d76f
Rename to polkadot-test-service and rename dir
cecton 6306561
Merge commit b2c9c14971f1f06400c6522e40d02e79c0f11a05 (no conflict)
cecton 6c95310
Bump spec_version
cecton 555715a
Move code to macro to avoid adding pub fn to API
cecton 4a3b4b0
CLEANUP
cecton 0d506a1
Fixed missing import
cecton 16f1c67
Fix missing import
cecton 9e1bf51
WIP
cecton 186a764
CLEANUP
cecton 528b2ed
WIP Attempt to make a test
cecton 88c57d3
Change most const to storage
cecton b5b219e
Add Get impl
cecton 9aba20a
Move everything to the test crate to create an API
cecton 83d9bf3
create chain spec
cecton 84fe08a
Parametrize storage update
cecton df43948
CLEANUP
cecton 7a27276
regex to the rescue
cecton 29b8a34
Improving API
cecton 4ca5082
format
cecton f67af13
WIP
cecton 5ae1794
WIP
cecton 0061afe
WIP
cecton 2fd2d71
WIP
cecton 899505d
use memory
cecton 25eb924
fixing last commit
cecton 780fbdf
WIP
cecton 302fa9a
max allowed time
cecton a3ba37b
CLEANUP
cecton d36cdc2
fmt
cecton 960f1f1
Revert Cargo.lock
cecton de25f24
CLEANUP
cecton ee93ecd
Added sudo
cecton cd96ffb
Merge commit b0b444ce5439849cbffea1d07dd710957402c064 (no conflict)
cecton d42d727
Merge commit a16cc4da50fa0205187c4babecc34f695918b63e (conflicts)
cecton 95e1a87
Merge commit 79a0df2f77f9d896b7b1790d04fb09355b6cccd2 (no conflict)
cecton 30c0dd7
Merge commit daf0073759f66a63b17abe1f8cdcaec93640afc9 (conflicts)
cecton f48b071
fix merge upgrade
cecton 9c04748
Cargo.lock
cecton 4730489
Merge commit fb66e42fe51d70d93688461aa6654cd87bc61db2 (no conflict)
cecton 3a0eee3
Fixed slot_duration for test w/ and w/out service
cecton f2444bc
increase spec version
cecton fb62093
Merge commit 4f79b770dc9d891739cc8dbadd62f7d9d8e36a58 (no conflict)
cecton acb88cc
better fix
cecton 6e5e060
Update runtime/test-runtime/client/src/lib.rs
cecton 3de82c2
Added doc and simplified API
cecton 8f4245d
Make wait_for_blocks more generic to avoid duplication in cumulus
cecton 605da30
Merge commit 39a3605224791f0b8fcd41af2f9636b83403780e (no conflict)
cecton 9467bd8
Merge commit b05bb8f6336928dd9fb5711036f98c38a854650a (conflicts)
cecton b723dea
Merge commit 0762de59f975fe2392fd6ca28dc3bd904df7f3a8 (no conflict)
cecton be679dd
Merge commit 51ce2b31230d6debdcd04f6bf9b345ec92544b94 (conflicts)
cecton 4816880
Removed base_path as this is not needed anymore
cecton f35262e
Helper to send transaction more easily
cecton 74ab47c
Fix indent
cecton be3889b
Added test for send-transaction
cecton 73ae473
Ensure task_manager dropped after task finish
cecton b8ec09d
Improve logging by using informant prefix
cecton 36fec81
Update polkadot-test-service/src/lib.rs
cecton 178ab7b
Update polkadot-test-service/src/lib.rs
cecton de65c05
Update polkadot-test-service/src/lib.rs
cecton abf0f35
Replace asserts with expects
cecton 6bae984
Merged imports
cecton 261c552
Revert slot duration change
cecton 4fc1a58
Helper to call a function
cecton 5796cd5
Update substrate branch to cecton-testing-helpers
cecton 91bf6bb
CLEANUP
cecton a6a54b5
Revert "Update substrate branch to cecton-testing-helpers"
cecton 3092be3
Merge commit 90d5dbe564ae795d68aff1c936cbdd1f98c9d536 (no conflict)
cecton 6dce9b1
Update substrate branch to cecton-testing-helpers
cecton a8fe1dd
CLEANUP
cecton df63aa1
CLEANUP
cecton 0cdda37
Add test runtime to command
cecton 5b4fcfd
replaced panic with clean error
cecton 36c8c65
Simplify test
cecton cf3fb7b
rename test
cecton 2bbe1b6
Revert "Add test runtime to command"
cecton f97dd0c
increase kusama
cecton 523366e
Update substrate
cecton 6be349f
Revert to master
cecton fb41215
Merge commit aeb79d47345e2e5d6320e0f2c11cb70df1e614e4 (no conflict)
cecton 5550cbb
Merge commit 0a7d04d00edc50488b2d6c34db685dac2234d749 (no conflict)
cecton c4cd5fb
Cargo.lock again
cecton a44b1c0
removed unused id prefix
cecton e8573ae
fix update
cecton fd8a9d7
Merge commit 21f31f78de36c6a36defb0fa0ee0052df35a0d0f (no conflict)
cecton fc00d0c
Merge commit 78e6e08e9e4524faddad463bbadbaf2c70e47256 (conflicts)
cecton 5916b39
Update runtime/test-runtime/src/lib.rs
cecton d620fc6
Update polkadot-test-service/src/lib.rs
cecton f108a3f
apply suggestions
cecton 602814a
add missing license
cecton 00316bd
Merge commit 8348cc4cb0aea625cd6868dcc4faa6633d0f8d9e (no conflict)
cecton 42545d5
Move polkadot-test-service to node/test-service
cecton c94459c
Sort dependencies and group
cecton 1637455
Attempt to remove genesismap
cecton 90750a1
Pass parameters
cecton 35e8ab1
Merge commit 891767bcd28a4a53fbc17ba87c2cc2d48758e35f (no conflict)
cecton 5fb41d2
another attempt to fix the test
cecton 7fa0a85
Merge remote-tracking branch 'origin/master' into cecton-polkadot-tes…
bkchr 6a65f87
Revert "another attempt to fix the test"
bkchr c74756a
Fix tests
bkchr f94de16
Update substrate
cecton e606833
adapt code
cecton 4e65412
fix
cecton b44f302
unused import
cecton f3b3142
WIP
cecton d32f811
replace async_std with tokio
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[package] | ||
name = "polkadot-test-service" | ||
version = "0.8.2" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
log = "0.4.8" | ||
futures = "0.3.4" | ||
tempfile = "3.1.0" | ||
rand = "0.7.3" | ||
hex = "0.4" | ||
futures01 = { package = "futures", version = "0.1.29" } | ||
av_store = { package = "polkadot-availability-store", path = "../availability-store" } | ||
consensus = { package = "polkadot-validation", path = "../validation" } | ||
polkadot-primitives = { path = "../primitives" } | ||
polkadot-test-runtime = { path = "../runtime/test-runtime" } | ||
polkadot-network = { path = "../network" } | ||
polkadot-rpc = { path = "../rpc" } | ||
polkadot-service = { path = "../service" } | ||
polkadot-runtime-common = { path = "../runtime/common" } | ||
sp-core = { 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-network = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
consensus_common = { package = "sp-consensus", 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" } | ||
service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
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" } | ||
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
|
||
[dev-dependencies] | ||
async-std = "1.5" | ||
serde_json = "1.0" | ||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
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; | ||
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, | ||
vec![], | ||
None, | ||
Some(DEFAULT_PROTOCOL_ID), | ||
None, | ||
Default::default(), | ||
) | ||
} | ||
|
||
fn polkadot_local_testnet_genesis() -> polkadot_test_runtime::GenesisConfig { | ||
polkadot_testnet_genesis( | ||
vec![ | ||
get_authority_keys_from_seed("Alice"), | ||
get_authority_keys_from_seed("Bob"), | ||
], | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
None, | ||
) | ||
} | ||
|
||
/// 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>>, | ||
) -> 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: Default::default(), | ||
}), | ||
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") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems somewhat redundant to put this in a directory starting with
polkadot
. What do you think about just calling the directorytest-service
? Also, maybe put it innode/
instead of at the root. That will keep things more organizedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely is... when I first named it I called it just "test" but it was super confusing with the tests directory.
I'm not familiar with the "node" directory. I think it's newish? I see it's been introduced in early June. What should we put there?
(Meanwhile I will follow your suggestion and move it already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the
node
dir is new and is meant to hold all things related to the node. At the end I think I'd like to have onlynode
/runtime
/primitives
at the root.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we have a
test-helpers
directory. Wouldn't it be even better if I moved it to there in "service" (crate name would be: polkadot-service-test-helpers)