Skip to content

Commit

Permalink
Got one!
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzenioszeniou committed Oct 14, 2021
1 parent 78efa29 commit 18eea80
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
80 changes: 80 additions & 0 deletions testing/jormungandr-integration-tests/src/jormungandr/bft/block.rs
@@ -0,0 +1,80 @@
use assert_fs::TempDir;
use chain_impl_mockchain::{
block::{builder, BlockDate, BlockVersion, Contents},
chaintypes::ConsensusType,
header::HeaderBuilder,
testing::TestGen,
};
use jormungandr_testing_utils::testing::{
adversary::process::AdversaryNodeBuilder,
jormungandr::{ConfigurationBuilder, Starter, StartupVerificationMode},
startup,
};
use std::time::Duration;

#[test]
fn block_with_incorrect_hash() {
let temp_dir = TempDir::new().unwrap();
let keys = startup::create_new_key_pair();

let node_params = ConfigurationBuilder::default()
.with_block0_consensus(ConsensusType::Bft)
.with_slot_duration(10)
.with_leader_key_pair(keys.clone())
.build(&temp_dir);

let block0 = node_params.block0_configuration().to_block();

let jormungandr = Starter::default().config(node_params).start().unwrap();

jormungandr
.wait_for_bootstrap(&StartupVerificationMode::Rest, Duration::from_secs(1))
.unwrap();

let contents = Contents::empty();
let content_size = contents.compute_hash_size().1;

let block = builder(BlockVersion::Ed25519Signed, contents, |_| {
Ok::<_, ()>({
HeaderBuilder::new_raw(BlockVersion::Ed25519Signed, &TestGen::hash(), content_size)
.set_parent(&block0.header().id(), 1.into())
.set_date(BlockDate {
epoch: 0,
slot_id: 1,
})
.into_bft_builder()
.unwrap()
.sign_using(keys.0.private_key())
.generalize()
})
})
.unwrap();

let mut adversary = AdversaryNodeBuilder::new(block0).build();

assert!(adversary
.send_block_to_peer(jormungandr.address(), block)
.expect_err("Expected block to be rejected")
.message()
.contains("Inconsistent block content hash in header"));
}

#[test]
fn block_with_bad_signature() {
// TODO
}

#[test]
fn block_with_wrong_leader() {
// TODO
}

#[test]
fn block_with_nonexistent_leader() {
// TODO
}

#[test]
fn block_with_invalid_fragment() {
// TODO
}
@@ -1,2 +1,3 @@
pub mod mempool;
pub mod start_node;
mod block;
mod mempool;
mod start_node;
Expand Up @@ -25,14 +25,20 @@ const CLIENT_RETRY_WAIT: Duration = Duration::from_millis(500);

#[derive(Error, Debug, PartialEq)]
pub enum MockClientError {
#[error("request failed with message {0}")]
#[error("request failed with message '{0}'")]
InvalidRequest(String),
#[error(
"could not parse address '{0}'. HINT: accepted format example: /ip4/127.0.0.1/tcp/9000"
)]
InvalidAddressFormat(String),
}

impl MockClientError {
pub fn message(&self) -> String {
format!("{}", self)
}
}

pub struct JormungandrClient {
addr: SocketAddr,
inner_client: NodeClient<Channel>,
Expand Down

0 comments on commit 18eea80

Please sign in to comment.