hbbft/tests/threshold_sign.rs

177 lines
6.1 KiB
Rust
Raw Permalink Normal View History

#![deny(unused_must_use)]
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
//! Non-deterministic tests for the ThresholdSign protocol
2018-06-11 09:00:23 -07:00
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
use std::sync::Arc;
2018-06-11 09:00:23 -07:00
use hbbft::{threshold_sign::ThresholdSign, util, ConsensusProtocol};
use hbbft_testing::adversary::{Adversary, NodeOrderAdversary, ReorderingAdversary};
use hbbft_testing::proptest::{gen_seed, TestRng, TestRngSeed};
use hbbft_testing::{NetBuilder, NewNodeInfo, VirtualNet};
2018-10-29 07:36:56 -07:00
use log::info;
use proptest::{prelude::ProptestConfig, proptest};
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
use rand::{Rng, SeedableRng};
2018-06-11 09:00:23 -07:00
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
type NodeId = u16;
2018-06-11 09:00:23 -07:00
/// Creates a new test network.
fn new_net<A, M, R>(
size: usize,
num_faulty: usize,
adv: A,
msg: M,
rng: &mut R,
) -> VirtualNet<ThresholdSign<NodeId>, A>
2018-06-11 09:00:23 -07:00
where
M: AsRef<[u8]> + 'static,
A: Adversary<ThresholdSign<NodeId>>,
R: Rng,
2018-06-11 09:00:23 -07:00
{
NetBuilder::new(0..size as u16)
.num_faulty(num_faulty as usize)
.message_limit(size * (size - 1))
.no_time_limit()
.adversary(adv)
.using(move |node_info: NewNodeInfo<_>| {
ThresholdSign::new_with_document(Arc::new(node_info.netinfo), &msg)
.expect("Failed to create a ThresholdSign instance.")
})
.build(rng)
.expect("Could not construct test network.")
.0
}
2018-06-11 09:00:23 -07:00
/// Tests a network of threshold signing instances.
fn test_threshold_sign_different_sizes<A, F>(new_adversary: F, seed: TestRngSeed)
where
A: Adversary<ThresholdSign<NodeId>>,
F: Fn() -> A,
{
const MSG: &str = "message";
// This returns an error in all but the first test.
let _ = env_logger::try_init();
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
let mut rng: TestRng = TestRng::from_seed(seed);
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
for &size in &[1, 2, 3, 4, 8, 15, 31] {
let num_faulty_nodes = util::max_faulty(size);
info!(
"Network size: {} good nodes, {} faulty nodes",
size - num_faulty_nodes,
num_faulty_nodes
);
let mut net = new_net(size, num_faulty_nodes, new_adversary(), MSG, &mut rng);
net.broadcast_input(&(), &mut rng)
.expect("threshold sign input failed");
// Handle messages until all good nodes have terminated.
while !net.nodes().all(|node| node.algorithm().terminated()) {
let _ = net.crank_expect(&mut rng);
}
let node0 = net.correct_nodes().next().unwrap();
// Verify that all instances output the same value.
assert_eq!(1, node0.outputs().len());
assert!(net.nodes().all(|node| node.outputs() == node0.outputs()));
let pk = node0.algorithm().netinfo().public_key_set().public_key();
assert!(pk.verify(&node0.outputs()[0], MSG));
}
2018-06-11 09:00:23 -07:00
}
const GOOD_SAMPLE_SET: f64 = 400.0;
/// The count of throws of each side of the coin should be approaching 50% with a sufficiently large
/// sample set. This check assumes logarithmic growth of the expected number of throws of one coin
/// size.
fn check_coin_distribution(num_samples: usize, count_true: usize, count_false: usize) {
2018-06-14 04:28:38 -07:00
// Maximum 40% expectation in case of 400 samples or more.
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
const EXPECTED_SHARE: f64 = 0.33;
2018-06-11 09:00:23 -07:00
let max_gain = GOOD_SAMPLE_SET.log2();
let num_samples_f64 = num_samples as f64;
let gain = num_samples_f64.log2().min(max_gain);
2018-06-11 09:00:23 -07:00
let step = EXPECTED_SHARE / max_gain;
let min_throws = (num_samples_f64 * gain * step) as usize;
2018-06-11 09:00:23 -07:00
info!(
"Expecting a minimum of {} throws for each coin side. Throws of true: {}. Throws of false: {}.",
min_throws, count_true, count_false
);
assert!(count_true > min_throws);
assert!(count_false > min_throws);
}
fn test_coin_different_sizes<A, F>(new_adversary: F, num_samples: usize, seed: TestRngSeed)
where
A: Adversary<ThresholdSign<NodeId>>,
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
F: Fn() -> A,
2018-06-11 09:00:23 -07:00
{
assert!(num_samples > 0);
// This returns an error in all but the first test.
let _ = env_logger::try_init();
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
let mut rng: TestRng = TestRng::from_seed(seed);
2018-06-11 09:00:23 -07:00
let mut last_size = 1;
let mut sizes = vec![last_size];
let num_sizes = (GOOD_SAMPLE_SET.log2() - (num_samples as f64).log2()) as usize;
for _ in 0..num_sizes {
last_size += rng.gen_range(3, 7);
sizes.push(last_size);
}
for size in sizes {
let num_faulty_nodes = util::max_faulty(size);
2018-06-11 09:00:23 -07:00
info!(
"Network size: {} good nodes, {} faulty nodes",
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
size - num_faulty_nodes,
num_faulty_nodes
2018-06-11 09:00:23 -07:00
);
let unique_id: u64 = rng.gen();
let mut count_true = 0;
let mut count_false = 0;
for i in 0..num_samples {
let nonce = format!("My very unique nonce {:x}:{}", unique_id, i);
info!("Nonce: {}", nonce);
let mut net = new_net(size, num_faulty_nodes, new_adversary(), nonce, &mut rng);
net.broadcast_input(&(), &mut rng)
.expect("threshold sign input failed");
// Handle messages until all good nodes have terminated.
while !net.nodes().all(|node| node.algorithm().terminated()) {
let _ = net.crank_expect(&mut rng);
}
let node0 = net.correct_nodes().next().unwrap();
// Verify that all instances output the same value.
assert_eq!(1, node0.outputs().len());
assert!(net.nodes().all(|node| node.outputs() == node0.outputs()));
let coin = node0.outputs()[0].parity();
2018-06-11 09:00:23 -07:00
if coin {
count_true += 1;
} else {
count_false += 1;
}
}
check_coin_distribution(num_samples, count_true, count_false);
}
}
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
proptest! {
#![proptest_config(ProptestConfig {
cases: 1, .. ProptestConfig::default()
})]
#[test]
fn test_coin_random_silent_200_samples(seed in gen_seed()) {
let new_adversary = || ReorderingAdversary::new();
test_coin_different_sizes(new_adversary, 200, seed);
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
}
#[test]
fn test_coin_first_silent_50_samples(seed in gen_seed()) {
let new_adversary = || NodeOrderAdversary::new();
test_coin_different_sizes(new_adversary, 50, seed);
Ported more integration tests to the new net simulator (#387) * Ported threshold_sign test to the new framework * Ported the first three broadcast tests to the new framework * Extracted messages storting and random swapping to reusable functions Used to compose ProposeAdversary's behavior without having to duplicate code * Implemented ProposeAdversary for the new integration testing framework Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation. Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node. Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds. * Migrated test_broadcast_random_delivery_adv_propose to the new network simulator Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library. Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation. * Ported RandomAdversary to the new network simulator library Ported all broadcast integration tests and replaced the old tests with the new. * Eliminated the old broadcast integration test, replaced with the new * Ported subset test to the new framework Adjusted message queue size as suggested by Andreas * Ported the first three honey_badger tests to the new framework * Re-implemented FaultyShareAdversary for the new framework Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework * Fixed issues reported by clippy * Fixed issues reported on code review * Fixed issues reported by clippy * Implemented a broadcast test dropping messages similar to the tests written in the old framework * Picking the proposer id at random, verifying all possible output cases If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output. If the proposer was correct all correct nodes need to output its proposed value. * Eliminated duplicated semicolon * Consistently using TestRng and proptest in all newly ported tests * Increased the drop_and_re_add test message limit to 20k per node * Removed unnecessary closure * Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 06:41:23 -07:00
}
2018-06-11 09:00:23 -07:00
#[test]
fn test_threshold_sign(seed in gen_seed()) {
let new_adversary = || ReorderingAdversary::new();
test_threshold_sign_different_sizes(new_adversary, seed);
}
2018-06-11 09:00:23 -07:00
}