Uniformize tests (#220)

* Initial commit

Forked at: 5bbab68f02
Parent branch: origin/master

* Copy runtime module from rococo

Forked at: 5bbab68f02
Parent branch: origin/master

* Also copy dependencies pallets and primitives

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* test-service

* Move integration test

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* Not sure what went wrong...

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* fmt

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* Remove pallet contracts (not used)

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

* Sort dependencies alphabetically

* CLEANUP

Forked at: 5bbab68f02
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: 5bbab68f02
Parent branch: origin/master

* Half the solution to previous commit :(

* Revert "Fix for previous commit"

This reverts commit 60010bab6797487093ac8c790b3a536f7ca0895b.

* Revert "runtime: replace const by storage"

This reverts commit c64b3a46f0325a98922015e0cbf3570e2e431774.

Not working for some reason...

* Use helper

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* Remove test-primitives

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

This reverts commit 9a8f89f9f06252198e6405057043c6b313f1aea4.

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

This reverts commit 6a93f0f09d74ccdc3738dd78a777c483427c03ce.

* Test with some extra extrinsics

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* WIP

Forked at: 5bbab68f02
Parent branch: origin/master

* CLEANUP

Forked at: 5bbab68f02
Parent branch: origin/master

* Remove message broker
This commit is contained in:
Cecile Tonglet
2020-10-07 10:51:01 +02:00
committed by GitHub
parent 23a49da012
commit 4d150a0199
24 changed files with 1956 additions and 869 deletions
+27 -45
View File
@@ -25,14 +25,16 @@ use sp_blockchain::HeaderBackend;
use sp_consensus::SelectChain;
use sp_core::traits::CallInWasm;
use sp_io::TestExternalities;
use sp_keyring::AccountKeyring;
use sp_keyring::AccountKeyring::*;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use test_client::{
runtime::{Block, Hash, Header, Transfer, WASM_BINARY},
Client, DefaultTestClientBuilderExt, LongestChain, TestClientBuilder, TestClientBuilderExt,
generate_block_inherents,
runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY},
transfer, Client, DefaultTestClientBuilderExt, LongestChain, TestClientBuilder,
TestClientBuilderExt,
};
use codec::{Decode, Encode};
@@ -74,53 +76,27 @@ fn call_validate_block(
.map_err(|err| err.into())
}
fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
vec![
Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
amount: 69,
nonce: 0,
}
.into_signed_tx(),
Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Charlie.into(),
amount: 100,
nonce: 1,
}
.into_signed_tx(),
Transfer {
from: AccountKeyring::Bob.into(),
to: AccountKeyring::Charlie.into(),
amount: 100,
nonce: 0,
}
.into_signed_tx(),
Transfer {
from: AccountKeyring::Charlie.into(),
to: AccountKeyring::Alice.into(),
amount: 500,
nonce: 0,
}
.into_signed_tx(),
]
}
fn create_test_client() -> (Client, LongestChain) {
TestClientBuilder::new().build_with_longest_chain()
TestClientBuilder::new()
// NOTE: this allows easier debugging
.set_execution_strategy(sc_client_api::ExecutionStrategy::NativeWhenPossible)
.build_with_longest_chain()
}
fn build_block_with_proof(
client: &Client,
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
extra_extrinsics: Vec<UncheckedExtrinsic>,
) -> (Block, sp_trie::StorageProof) {
let block_id = BlockId::Hash(client.info().best_hash);
let mut builder = client
.new_block_at(&block_id, Default::default(), true)
.expect("Initializes new block");
extrinsics
generate_block_inherents(client)
.into_iter()
.for_each(|e| builder.push(e).expect("Pushes an inherent"));
extra_extrinsics
.into_iter()
.for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
@@ -135,10 +111,10 @@ fn build_block_with_proof(
}
#[test]
fn validate_block_with_no_extrinsics() {
fn validate_block_no_extra_extrinsics() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (block, witness_data) = build_block_with_proof(&client, vec![]);
let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
@@ -148,10 +124,16 @@ fn validate_block_with_no_extrinsics() {
}
#[test]
fn validate_block_with_extrinsics() {
fn validate_block_with_extra_extrinsics() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
let extra_extrinsics = vec![
transfer(&client, Alice, Bob, 69),
transfer(&client, Bob, Charlie, 100),
transfer(&client, Charlie, Alice, 500),
];
let (block, witness_data) = build_block_with_proof(&client, extra_extrinsics);
let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
@@ -161,11 +143,11 @@ fn validate_block_with_extrinsics() {
}
#[test]
#[should_panic]
#[should_panic(expected = "Calls `validate_block`: Other(\"Trap: Trap { kind: Unreachable }\")")]
fn validate_block_invalid_parent_hash() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (block, witness_data) = build_block_with_proof(&client, vec![]);
let (mut header, extrinsics) = block.deconstruct();
header.set_parent_hash(Hash::from_low_u64_be(1));