Wait for relay chain block import before validatiing a block announcement (#227)

* Start with something

* Whatever

* Update

* MOARE

* Make cumulus-network compile and tests work

* Update more and fixes

* More stuff

* More fixes

* Make collator build

* Make test almost work

* Remove contracts runtime

* More test work

* Make service compile

* Fix test-service

* Fix test client

* More fixes

* Fix collator test

* Fix network tests (again)

* Make everything compile, finally

* Fix tests

* Write test that should fail

* Add `WaitOnRelayChainBlock`

* Update git versions

* Make it all work

* Update logging

* Switch to provided method for pushing an extrinsic

* Try to debug CI

* Aaaa

* Only use Debug

* Updates

* Use native execution to hopefully make CI happy...
This commit is contained in:
Bastian Köcher
2020-11-23 00:21:02 +01:00
committed by GitHub
parent 9ed50e83c4
commit 63efcc49c3
17 changed files with 1310 additions and 683 deletions
+11 -54
View File
@@ -12,29 +12,23 @@
// 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/>.
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! A Cumulus test client.
//! A Polkadot test client.
mod block_builder;
pub use block_builder::*;
use codec::Encode;
pub use cumulus_test_runtime as runtime;
use runtime::{
Balance, Block, BlockHashCount, Call, GenesisConfig, Runtime, Signature, SignedExtra,
SignedPayload, UncheckedExtrinsic, VERSION,
};
use sc_service::client;
use sp_blockchain::HeaderBackend;
use sp_core::{map, storage::Storage, twox_128, ChangesTrieConfiguration};
use sp_runtime::{
generic::Era,
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
BuildStorage, SaturatedConversion,
};
use std::collections::BTreeMap;
use sp_core::storage::Storage;
use sp_runtime::{generic::Era, BuildStorage, SaturatedConversion};
pub use block_builder::*;
pub use cumulus_test_runtime as runtime;
pub use substrate_test_client::*;
mod local_executor {
@@ -67,42 +61,16 @@ pub type Client = client::Client<Backend, Executor, Block, runtime::RuntimeApi>;
/// Parameters of test-client builder with test-runtime.
#[derive(Default)]
pub struct GenesisParameters {
support_changes_trie: bool,
}
pub struct GenesisParameters;
impl substrate_test_client::GenesisInit for GenesisParameters {
fn genesis_storage(&self) -> Storage {
let changes_trie_config: Option<ChangesTrieConfiguration> = if self.support_changes_trie {
Some(sp_test_primitives::changes_trie_config())
} else {
None
};
let mut storage = genesis_config(changes_trie_config).build_storage().unwrap();
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root =
<<<runtime::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 =
<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
);
let block: runtime::Block = client::genesis::construct_genesis_block(state_root);
storage.top.extend(additional_storage_with_genesis(&block));
storage
genesis_config().build_storage().unwrap()
}
}
/// A `test-runtime` extensions to `TestClientBuilder`.
pub trait TestClientBuilderExt: Sized {
/// Enable or disable support for changes trie in genesis.
fn set_support_changes_trie(self, support_changes_trie: bool) -> Self;
/// Build the test client.
fn build(self) -> Client {
self.build_with_longest_chain().0
@@ -113,11 +81,6 @@ pub trait TestClientBuilderExt: Sized {
}
impl TestClientBuilderExt for TestClientBuilder {
fn set_support_changes_trie(mut self, support_changes_trie: bool) -> Self {
self.genesis_init_mut().support_changes_trie = support_changes_trie;
self
}
fn build_with_longest_chain(self) -> (Client, LongestChain) {
self.build_with_native_executor(None)
}
@@ -135,14 +98,8 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
}
}
fn genesis_config(changes_trie_config: Option<ChangesTrieConfiguration>) -> GenesisConfig {
cumulus_test_service::local_testnet_genesis(changes_trie_config)
}
fn additional_storage_with_genesis(genesis_block: &Block) -> BTreeMap<Vec<u8>, Vec<u8>> {
map![
twox_128(&b"latest"[..]).to_vec() => genesis_block.hash().as_fixed_bytes().to_vec()
]
fn genesis_config() -> GenesisConfig {
cumulus_test_service::local_testnet_genesis()
}
/// Generate an extrinsic from the provided function call, origin and [`Client`].