Skip to content

Commit 747bf45

Browse files
committed
Tweak some scan_block tests
One has an unclear story. Others have a pattern of checking a single message (less than the threshold) causes no events, but doesn't check all messages less than the threshold cause no events.
1 parent 84e50fc commit 747bf45

2 files changed

Lines changed: 35 additions & 36 deletions

File tree

coordinator/tributary/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ pub(crate) fn assert_block_side_effects(
239239
transactions: &[tributary_sdk::Transaction<Transaction>],
240240
) {
241241
for tx in transactions {
242+
// TODO: Expand from checking the message is `Some(_)` to the exact expected message
242243
match tx {
243244
tributary_sdk::Transaction::Application(app_tx) => match app_tx {
244245
Transaction::DkgParticipation { .. } => {

coordinator/tributary/src/tests/scan_block.rs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -401,25 +401,9 @@ mod handle_application_tx {
401401
let mut txn = db.txn();
402402
let block_number = OsRng.next_u64();
403403

404-
// Below threshold: no DkgConfirmationMessages sent
405404
{
406405
let mut scan_block = new_scan_block(&mut txn, &set_info, &validators, total_weight, &weights);
407-
408-
scan_block.handle_application_tx(
409-
block_number,
410-
Transaction::DkgConfirmationPreprocess {
411-
attempt: 0,
412-
preprocess: random_bytes(&mut OsRng),
413-
signed: new_signed(key0),
414-
},
415-
);
416-
}
417-
assert!(DkgConfirmationMessages::try_recv(&mut txn, set).is_none());
418-
419-
// Threshold crossed: sends DkgConfirmationMessages (Preprocesses)
420-
{
421-
let mut scan_block = new_scan_block(&mut txn, &set_info, &validators, total_weight, &weights);
422-
for key in [key1, key2] {
406+
for (i, key) in [key0, key1, key2].into_iter().enumerate() {
423407
scan_block.handle_application_tx(
424408
block_number,
425409
Transaction::DkgConfirmationPreprocess {
@@ -428,8 +412,14 @@ mod handle_application_tx {
428412
signed: new_signed(key),
429413
},
430414
);
415+
if i != 2 {
416+
// Below threshold: no DkgConfirmationMessages sent
417+
assert!(DkgConfirmationMessages::try_recv(&mut txn, set).is_none());
418+
}
431419
}
432420
}
421+
// Threshold crossed: sends DkgConfirmationMessages (Preprocesses)
422+
// TODO: Check the received message is the expected one
433423
assert!(DkgConfirmationMessages::try_recv(&mut txn, set).is_some());
434424
}
435425

@@ -471,7 +461,7 @@ mod handle_application_tx {
471461
// All 3 validators submit preprocesses (threshold crossed -> DkgConfirmationMessages sent)
472462
{
473463
let mut scan_block = new_scan_block(&mut txn, &set_info, &validators, total_weight, &weights);
474-
for key in [key0, key1, key2] {
464+
for (i, key) in [key0, key1, key2].into_iter().enumerate() {
475465
scan_block.handle_application_tx(
476466
block_number,
477467
Transaction::DkgConfirmationPreprocess {
@@ -480,34 +470,21 @@ mod handle_application_tx {
480470
signed: new_signed(key),
481471
},
482472
);
473+
if i != 2 {
474+
assert!(DkgConfirmationMessages::try_recv(&mut txn, set).is_none());
475+
}
483476
}
484477
}
478+
// TODO: Check the exact message received
485479
assert!(
486480
DkgConfirmationMessages::try_recv(&mut txn, set).is_some(),
487481
"preprocesses crossing threshold should produce DkgConfirmationMessages"
488482
);
489483

490-
// Below threshold: no DkgConfirmationMessages sent
491-
{
492-
let mut scan_block = new_scan_block(&mut txn, &set_info, &validators, total_weight, &weights);
493-
scan_block.handle_application_tx(
494-
block_number,
495-
Transaction::DkgConfirmationShare {
496-
attempt: 0,
497-
share: random_bytes(&mut OsRng),
498-
signed: new_signed(key0),
499-
},
500-
);
501-
}
502-
assert!(
503-
DkgConfirmationMessages::try_recv(&mut txn, set).is_none(),
504-
"single share should not produce DkgConfirmationMessages"
505-
);
506-
507484
// Threshold crossed: sends DkgConfirmationMessages (Shares)
508485
{
509486
let mut scan_block = new_scan_block(&mut txn, &set_info, &validators, total_weight, &weights);
510-
for key in [key1, key2] {
487+
for (i, key) in [key0, key1, key2].into_iter().enumerate() {
511488
scan_block.handle_application_tx(
512489
block_number,
513490
Transaction::DkgConfirmationShare {
@@ -516,8 +493,15 @@ mod handle_application_tx {
516493
signed: new_signed(key),
517494
},
518495
);
496+
if i != 2 {
497+
assert!(
498+
DkgConfirmationMessages::try_recv(&mut txn, set).is_none(),
499+
"less than threshold should not produce DkgConfirmationMessages"
500+
);
501+
}
519502
}
520503
}
504+
// TODO: Check the exact message received
521505
assert!(
522506
DkgConfirmationMessages::try_recv(&mut txn, set).is_some(),
523507
"shares crossing threshold should produce DkgConfirmationMessages"
@@ -635,6 +619,20 @@ mod handle_application_tx {
635619
}
636620

637621
// Does not finish active cosign when block doesn't match
622+
/*
623+
TODO: The story for this test is unclear.
624+
625+
The intent is that if we are to cosign block #500, then block #501, we don't interrupt
626+
cosigning block #500 to begin on block #501. Instead, we finish #500, by which point we may
627+
be asked to cosign block #501, or maybe even #502. The intent is by finishing #500, we
628+
inherently begin the latest block to cosign.
629+
630+
This test asserts that if we're cosigning X, but then finish Y (which should be an
631+
unreachable invariant, as we shouldn't start cosinging while already cosigning), that we
632+
continue on X. Presumably, this is a byproduct of how if we finish #500 but have #501
633+
pending, we're intended to immediately rollover to #501, presented here as explicit
634+
functionality to test for. This has to be straightened out.
635+
*/
638636
{
639637
let mut db = MemDb::new();
640638
let active_hash = random_block_hash(&mut OsRng);

0 commit comments

Comments
 (0)