Make sure system tests are checking for the correct result (#491)

This commit is contained in:
Bastian Köcher
2021-06-13 11:23:13 +01:00
committed by GitHub
parent 2dc281b482
commit 80b739d886
@@ -14,6 +14,7 @@
// 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::{Decode, Encode};
use cumulus_primitives_core::{ParachainBlockData, PersistedValidationData};
use cumulus_test_client::{
runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY},
@@ -33,8 +34,7 @@ use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use codec::{Decode, Encode};
use std::{env, process::Command};
fn call_validate_block(
parent_head: Header,
@@ -187,10 +187,10 @@ fn validate_block_with_extra_extrinsics() {
}
#[test]
#[should_panic(expected = "Calls `validate_block`: Other(\"Trap: Trap { kind: Unreachable }\")")]
fn validate_block_invalid_parent_hash() {
let _ = env_logger::try_init();
if env::var("RUN_TEST").is_ok() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let TestBlockData {
@@ -207,14 +207,24 @@ fn validate_block_invalid_parent_hash() {
block_data,
validation_data.relay_parent_storage_root,
)
.expect("Calls `validate_block`");
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&["validate_block_invalid_parent_hash", "--", "--nocapture"])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
assert!(output.status.success());
assert!(dbg!(String::from_utf8(output.stderr).unwrap()).contains("Invalid parent hash"));
}
}
#[test]
#[should_panic(expected = "Calls `validate_block`: Other(\"Trap: Trap { kind: Unreachable }\")")]
fn validate_block_fails_on_invalid_validation_data() {
let _ = env_logger::try_init();
if env::var("RUN_TEST").is_ok() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let TestBlockData { block, witness, .. } =
@@ -222,14 +232,29 @@ fn validate_block_fails_on_invalid_validation_data() {
let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new(header, extrinsics, witness);
call_validate_block(parent_head, block_data, Hash::random()).expect("Calls `validate_block`");
call_validate_block(parent_head, block_data, Hash::random()).unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&[
"validate_block_fails_on_invalid_validation_data",
"--",
"--nocapture",
])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
assert!(output.status.success());
assert!(dbg!(String::from_utf8(output.stderr).unwrap())
.contains("Relay parent storage root doesn't match"));
}
}
#[test]
#[should_panic(expected = "Calls `validate_block`: Other(\"Trap: Trap { kind: Unreachable }\")")]
fn check_inherent_fails_on_validate_block_as_expected() {
let _ = env_logger::try_init();
if env::var("RUN_TEST").is_ok() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
@@ -250,11 +275,26 @@ fn check_inherent_fails_on_validate_block_as_expected() {
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness);
let res_header = call_validate_block(
call_validate_block(
parent_head,
block_data,
validation_data.relay_parent_storage_root,
)
.expect("Calls `validate_block`");
assert_eq!(header, res_header);
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&[
"check_inherent_fails_on_validate_block_as_expected",
"--",
"--nocapture",
])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
assert!(output.status.success());
assert!(
dbg!(String::from_utf8(output.stderr).unwrap()).contains("Checking inherents failed")
);
}
}