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

Commit

Permalink
Uniformize tests (#220)
Browse files Browse the repository at this point in the history
* Initial commit

Forked at: 5bbab68
Parent branch: origin/master

* Copy runtime module from rococo

Forked at: 5bbab68
Parent branch: origin/master

* Also copy dependencies pallets and primitives

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* test-service

* Move integration test

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* Not sure what went wrong...

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* fmt

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* Remove pallet contracts (not used)

* Remove pallet parachain-info and token-dealer (not used)

* Sort dependencies alphabetically

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* CumulusTestNode for testing

* Speed up block generation

* Fix improper shutdown

* rustfmt

* runtime: replace const by storage

* Fix for previous commit

* Remove some generics

* Move generate_genesis_state to cumulus-primitives

* fmt

* Remove message_example

* fixup! Remove message_example

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* Half the solution to previous commit :(

* Revert "Fix for previous commit"

This reverts commit 60010ba.

* Revert "runtime: replace const by storage"

This reverts commit c64b3a4.

Not working for some reason...

* Use helper

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* Remove test-primitives

* Revert "Half the solution to previous commit :("

This reverts commit 9a8f89f.

* Revert "Revert "Half the solution to previous commit :(""

This reverts commit 6a93f0f.

* Test with some extra extrinsics

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* WIP

Forked at: 5bbab68
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68
Parent branch: origin/master

* Remove message broker
  • Loading branch information
cecton authored Oct 7, 2020
1 parent 23a49da commit 4d150a0
Show file tree
Hide file tree
Showing 24 changed files with 1,956 additions and 869 deletions.
886 changes: 486 additions & 400 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 @@ -15,6 +15,7 @@ members = [
"service",
"test/runtime",
"test/client",
"test/service",
"upward-message",
]

Expand Down
2 changes: 1 addition & 1 deletion parachain-upgrade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ decl_module! {
/// Set the current validation function parameters
///
/// This should be invoked exactly once per block. It will panic at the finalization
/// phease if the call was not invoked.
/// phase if the call was not invoked.
///
/// The dispatch origin for this call must be `Inherent`
///
Expand Down
2 changes: 2 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
# Substrate dependencies
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", optional = true }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
Expand All @@ -24,6 +25,7 @@ polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", bra
[features]
default = [ "std" ]
std = [
"sc-service",
"sp-std/std",
"codec/std",
"polkadot-primitives/std",
Expand Down
50 changes: 50 additions & 0 deletions primitives/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus 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.

// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.

use codec::Encode;
use sc_service::ChainSpec;
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};

/// Generate the genesis state for a given ChainSpec.
pub fn generate_genesis_block<Block: BlockT>(
chain_spec: &Box<dyn ChainSpec>,
) -> Result<Block, String> {
let storage = chain_spec.build_storage()?;

let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
);
(sk.clone(), state_root.encode())
});
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
);

let extrinsics_root =
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());

Ok(Block::new(
<<Block as BlockT>::Header as HeaderT>::new(
Zero::zero(),
extrinsics_root,
state_root,
Default::default(),
Default::default(),
),
Default::default(),
))
}
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub use polkadot_parachain::primitives::{
Id as ParaId, ParachainDispatchOrigin as UpwardMessageOrigin,
};

#[cfg(feature = "std")]
pub mod genesis;
pub mod validation_function_params;
pub mod xcmp;

Expand Down
16 changes: 0 additions & 16 deletions rococo-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococ
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
Expand Down Expand Up @@ -70,7 +69,6 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch =
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }

[build-dependencies]
Expand All @@ -79,17 +77,3 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
[dev-dependencies]
assert_cmd = "0.12"
nix = "0.17"
rand = "0.7.3"
tokio = { version = "0.2.21", features = ["macros"] }

# Polkadot dependencies
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-test-runtime-client = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }

# Substrate dependencies
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
40 changes: 5 additions & 35 deletions rococo-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
cli::{Cli, RelayChainCli, Subcommand},
};
use codec::Encode;
use cumulus_primitives::ParaId;
use cumulus_primitives::{genesis::generate_genesis_block, ParaId};
use log::info;
use parachain_runtime::Block;
use polkadot_parachain::primitives::AccountIdConversion;
Expand All @@ -29,7 +29,7 @@ use sc_cli::{
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};
use sp_runtime::traits::Block as BlockT;
use std::{io::Write, net::SocketAddr, sync::Arc};

fn load_spec(
Expand Down Expand Up @@ -134,34 +134,6 @@ impl SubstrateCli for RelayChainCli {
}
}

pub fn generate_genesis_state(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Block> {
let storage = chain_spec.build_storage()?;

let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
);
(sk.clone(), state_root.encode())
});
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
);

let extrinsics_root =
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());

Ok(Block::new(
<<Block as BlockT>::Header as HeaderT>::new(
Zero::zero(),
extrinsics_root,
state_root,
Default::default(),
Default::default(),
),
Default::default(),
))
}

fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
let mut storage = chain_spec.build_storage()?;

Expand Down Expand Up @@ -216,7 +188,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::ExportGenesisState(params)) => {
sc_cli::init_logger("");

let block = generate_genesis_state(&load_spec(
let block: Block = generate_genesis_block(&load_spec(
&params.chain.clone().unwrap_or_default(),
params.parachain_id.into(),
)?)?;
Expand Down Expand Up @@ -268,8 +240,8 @@ pub fn run() -> Result<()> {
let parachain_account =
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);

let block =
generate_genesis_state(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
let block: Block =
generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));

let task_executor = config.task_executor.clone();
Expand All @@ -293,7 +265,6 @@ pub fn run() -> Result<()> {
polkadot_config,
id,
collator,
false,
)
} else {
crate::service::start_node(
Expand All @@ -302,7 +273,6 @@ pub fn run() -> Result<()> {
polkadot_config,
id,
collator,
false,
)
.map(|r| r.0)
}
Expand Down
Loading

0 comments on commit 4d150a0

Please sign in to comment.