Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions blockprod/src/detail/tests/collect_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
use common::{
chain::block::timestamp::BlockTimestamp,
primitives::{H256, Id},
time_getter::TimeGetter,
};
use mempool::{
error::{BlockConstructionError, TxValidationError},
tx_accumulator::{DefaultTxAccumulator, PackingStrategy},
};
use mocks::MockMempoolInterface;
use subsystem::error::ResponseError;
use test_utils::assert_matches;
use utils::once_destructor::OnceDestructor;

use crate::{
BlockProductionError, detail::collect_transactions, tests::helpers::setup_blockprod_test,
BlockProductionError, detail::collect_transactions, tests::helpers::BlockprodTestSetupBuilder,
};

// A dummy timestamp for tests where the block timestamp is irrelevant
Expand All @@ -37,8 +37,7 @@ const DUMMY_TIMESTAMP: BlockTimestamp = BlockTimestamp::from_int_seconds(0u64);

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn collect_txs_failed() {
let (mut manager, chain_config, _chainstate, _mempool, _p2p) =
setup_blockprod_test(None, TimeGetter::default());
let (blockprod_setup, mut manager) = BlockprodTestSetupBuilder::new().build();

let mut mock_mempool = MockMempoolInterface::default();
mock_mempool.expect_collect_txs().return_once(|_, _, _| {
Expand All @@ -55,7 +54,7 @@ async fn collect_txs_failed() {
let tester = tokio::spawn(async move {
let transactions = collect_transactions(
&mock_mempool_subsystem,
&chain_config,
&blockprod_setup.chain_config,
current_tip,
DUMMY_TIMESTAMP,
vec![],
Expand All @@ -64,12 +63,12 @@ async fn collect_txs_failed() {
)
.await;

match transactions {
assert_matches!(
transactions,
Err(BlockProductionError::MempoolBlockConstruction(
BlockConstructionError::Validity(TxValidationError::SubsystemCallError(_)),
)) => {}
_ => panic!("Expected collect_tx() to fail"),
};
))
);

shutdown.initiate();
});
Expand All @@ -79,8 +78,7 @@ async fn collect_txs_failed() {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn subsystem_error() {
let (mut manager, chain_config, _chainstate, _mempool, _p2p) =
setup_blockprod_test(None, TimeGetter::default());
let (blockprod_setup, mut manager) = BlockprodTestSetupBuilder::new().build();

let mock_mempool = MockMempoolInterface::default();
let mock_mempool_subsystem = manager.add_subsystem("mock-mempool", mock_mempool);
Expand All @@ -102,7 +100,7 @@ async fn subsystem_error() {
tokio::spawn(async move {
let transactions = collect_transactions(
&mock_mempool_subsystem,
&chain_config,
&blockprod_setup.chain_config,
current_tip,
DUMMY_TIMESTAMP,
vec![],
Expand All @@ -118,13 +116,12 @@ async fn subsystem_error() {
};
})
.await
.expect("Subsystem error thread failed");
.unwrap();
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn succeeded() {
let (mut manager, chain_config, _chainstate, _mempool, _p2p) =
setup_blockprod_test(None, TimeGetter::default());
let (blockprod_setup, mut manager) = BlockprodTestSetupBuilder::new().build();

let mut mock_mempool = MockMempoolInterface::default();

Expand Down Expand Up @@ -153,7 +150,7 @@ async fn succeeded() {

let transactions = collect_transactions(
&mock_mempool_subsystem,
&chain_config,
&blockprod_setup.chain_config,
current_tip,
DUMMY_TIMESTAMP,
vec![],
Expand Down
36 changes: 6 additions & 30 deletions blockprod/src/detail/tests/process_block_with_custom_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use rstest::rstest;

use common::time_getter::TimeGetter;
use mempool::tx_accumulator::PackingStrategy;
use randomness::RngExt as _;
use test_utils::random::{Seed, make_seedable_rng};
use utils::once_destructor::OnceDestructor;

use crate::{
BlockProduction, BlockProductionError,
BlockProductionError,
detail::{GenerateBlockInputData, job_manager::JobManagerError},
prepare_thread_pool, test_blockprod_config,
tests::helpers::setup_blockprod_test,
tests::helpers::BlockprodTestSetupBuilder,
};

#[rstest]
#[trace]
#[case(Seed::from_entropy())]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn multiple_jobs_with_wait(#[case] seed: Seed) {
let (manager, chain_config, chainstate, mempool, p2p) =
setup_blockprod_test(None, TimeGetter::default());
let (blockprod_setup, manager) = BlockprodTestSetupBuilder::new().build();

let mut rng = make_seedable_rng(seed);

let jobs_to_create = rng.random_range(1..=20);

let block_production = BlockProduction::new(
chain_config,
Arc::new(test_blockprod_config()),
chainstate,
mempool,
p2p,
Default::default(),
prepare_thread_pool(1),
)
.expect("Error initializing blockprod");
let block_production = blockprod_setup.make_blockprod_builder().build();

let join_handle = tokio::spawn({
let shutdown_trigger = manager.make_shutdown_trigger();
Expand Down Expand Up @@ -95,23 +81,13 @@ async fn multiple_jobs_with_wait(#[case] seed: Seed) {
#[case(Seed::from_entropy())]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn multiple_jobs_without_wait_same_jobkey(#[case] seed: Seed) {
let (manager, chain_config, chainstate, mempool, p2p) =
setup_blockprod_test(None, TimeGetter::default());
let (blockprod_setup, manager) = BlockprodTestSetupBuilder::new().build();

let mut rng = make_seedable_rng(seed);

let jobs_to_create = 10 + rng.random_range(1..=20);

let block_production = BlockProduction::new(
chain_config,
Arc::new(test_blockprod_config()),
chainstate,
mempool,
p2p,
Default::default(),
prepare_thread_pool(1),
)
.expect("Error initializing blockprod");
let block_production = blockprod_setup.make_blockprod_builder().build();

let join_handle = tokio::spawn({
let shutdown_trigger = manager.make_shutdown_trigger();
Expand Down
Loading
Loading