From d329502e8d62cdec35596396634d051f8e7b1bbc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 7 Dec 2017 19:05:35 -0800 Subject: [PATCH] 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. --- chainntnfs/interface_test.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index 31846bc0..65955da4 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -577,11 +577,15 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness, // will generate the confirmations in chunks. numConfs = 6 + time.Sleep(time.Second * 2) + // First, generate 2 confirmations. if _, err := miner.Node.Generate(2); err != nil { t.Fatalf("unable to generate blocks: %v", err) } + time.Sleep(time.Second * 2) + // Next, register for the notification *after* the transition has // already been partially confirmed. confIntent, err = notifier.RegisterConfirmationsNtfn(txid, numConfs, @@ -590,9 +594,33 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness, t.Fatalf("unable to register ntfn: %v", err) } - // With the notification registered, generate another 4 blocks, this - // should dispatch the notification. - if _, err := miner.Node.Generate(4); err != nil { + // We shouldn't receive a notification at this point, as the + // transaction hasn't yet been fully confirmed. + 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) }