chainntnfs: expand historical dispatch test case to detect early dispatches
In this commit, we extend the existing historical dispatch test case to detect any instances of early dispatches. This catches a class of bug within a ChainNotifier when the notifier will *always* dispatch early no matter the number of confirmations. Currently, this test fails for the neutrino notifier.
This commit is contained in:
parent
0ba80f5b40
commit
d329502e8d
@ -577,11 +577,15 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
|||||||
// will generate the confirmations in chunks.
|
// will generate the confirmations in chunks.
|
||||||
numConfs = 6
|
numConfs = 6
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 2)
|
||||||
|
|
||||||
// First, generate 2 confirmations.
|
// First, generate 2 confirmations.
|
||||||
if _, err := miner.Node.Generate(2); err != nil {
|
if _, err := miner.Node.Generate(2); err != nil {
|
||||||
t.Fatalf("unable to generate blocks: %v", err)
|
t.Fatalf("unable to generate blocks: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 2)
|
||||||
|
|
||||||
// Next, register for the notification *after* the transition has
|
// Next, register for the notification *after* the transition has
|
||||||
// already been partially confirmed.
|
// already been partially confirmed.
|
||||||
confIntent, err = notifier.RegisterConfirmationsNtfn(txid, numConfs,
|
confIntent, err = notifier.RegisterConfirmationsNtfn(txid, numConfs,
|
||||||
@ -590,9 +594,33 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
|||||||
t.Fatalf("unable to register ntfn: %v", err)
|
t.Fatalf("unable to register ntfn: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the notification registered, generate another 4 blocks, this
|
// We shouldn't receive a notification at this point, as the
|
||||||
// should dispatch the notification.
|
// transaction hasn't yet been fully confirmed.
|
||||||
if _, err := miner.Node.Generate(4); err != nil {
|
select {
|
||||||
|
case <-confIntent.Confirmed:
|
||||||
|
t.Fatalf("received confirmation notification but shouldn't " +
|
||||||
|
"have")
|
||||||
|
default:
|
||||||
|
// Expected case
|
||||||
|
}
|
||||||
|
|
||||||
|
// With the notification registered, generate another 3 blocks, this
|
||||||
|
// shouldn't yet dispatch the notification.
|
||||||
|
if _, err := miner.Node.Generate(3); err != nil {
|
||||||
|
t.Fatalf("unable to generate blocks: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-confIntent.Confirmed:
|
||||||
|
t.Fatalf("received confirmation notification but shouldn't " +
|
||||||
|
"have")
|
||||||
|
default:
|
||||||
|
// Expected case
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, we'll mine the final block which should dispatch the
|
||||||
|
// notification.
|
||||||
|
if _, err := miner.Node.Generate(1); err != nil {
|
||||||
t.Fatalf("unable to generate blocks: %v", err)
|
t.Fatalf("unable to generate blocks: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user