chainntnfs/txconfnotifier_test: use tcn instead of txConfNotifier

This commit is contained in:
Conner Fromknecht 2018-08-24 18:51:30 -07:00
parent 3b9aa2e7b5
commit d3bde428ea
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

View File

@ -113,7 +113,7 @@ func TestTxConfFutureDispatch(t *testing.T) {
)
hintCache := newMockHintCache()
txConfNotifier := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
tcn := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
// Create the test transactions and register them with the
// TxConfNotifier before including them in a block to receive future
@ -124,7 +124,7 @@ func TestTxConfFutureDispatch(t *testing.T) {
NumConfirmations: tx1NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx1NumConfs),
}
if err := txConfNotifier.Register(&ntfn1); err != nil {
if err := tcn.Register(&ntfn1); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -134,7 +134,7 @@ func TestTxConfFutureDispatch(t *testing.T) {
NumConfirmations: tx2NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx2NumConfs),
}
if err := txConfNotifier.Register(&ntfn2); err != nil {
if err := tcn.Register(&ntfn2); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -162,7 +162,7 @@ func TestTxConfFutureDispatch(t *testing.T) {
Transactions: []*wire.MsgTx{&tx1, &tx2, &tx3},
})
err := txConfNotifier.ConnectTip(
err = tcn.ConnectTip(
block1.Hash(), 11, block1.Transactions(),
)
if err != nil {
@ -225,7 +225,7 @@ func TestTxConfFutureDispatch(t *testing.T) {
Transactions: []*wire.MsgTx{&tx3},
})
err = txConfNotifier.ConnectTip(block2.Hash(), 12, block2.Transactions())
err = tcn.ConnectTip(block2.Hash(), 12, block2.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -287,7 +287,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
)
hintCache := newMockHintCache()
txConfNotifier := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
tcn := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
// Create the test transactions at a height before the TxConfNotifier's
// starting height so that they are confirmed once registering them.
@ -298,7 +298,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
NumConfirmations: tx1NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx1NumConfs),
}
if err := txConfNotifier.Register(&ntfn1); err != nil {
if err := tcn.Register(&ntfn1); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -309,7 +309,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
NumConfirmations: tx2NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx2NumConfs),
}
if err := txConfNotifier.Register(&ntfn2); err != nil {
if err := tcn.Register(&ntfn2); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -320,7 +320,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
BlockHeight: 9,
TxIndex: 1,
}
err := txConfNotifier.UpdateConfDetails(tx1Hash, ntfn1.ConfID, &txConf1)
err := tcn.UpdateConfDetails(tx1Hash, ntfn1.ConfID, &txConf1)
if err != nil {
t.Fatalf("unable to update conf details: %v", err)
}
@ -353,7 +353,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
BlockHeight: 9,
TxIndex: 2,
}
err = txConfNotifier.UpdateConfDetails(tx2Hash, ntfn2.ConfID, &txConf2)
err = tcn.UpdateConfDetails(tx2Hash, ntfn2.ConfID, &txConf2)
if err != nil {
t.Fatalf("unable to update conf details: %v", err)
}
@ -381,7 +381,7 @@ func TestTxConfHistoricalDispatch(t *testing.T) {
Transactions: []*wire.MsgTx{&tx3},
})
err = txConfNotifier.ConnectTip(block.Hash(), 11, block.Transactions())
err = tcn.ConnectTip(block.Hash(), 11, block.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -439,7 +439,7 @@ func TestTxConfChainReorg(t *testing.T) {
)
hintCache := newMockHintCache()
txConfNotifier := chainntnfs.NewTxConfNotifier(7, 100, hintCache)
tcn := chainntnfs.NewTxConfNotifier(7, 100, hintCache)
// Tx 1 will be confirmed in block 9 and requires 2 confs.
tx1Hash := tx1.TxHash()
@ -448,7 +448,7 @@ func TestTxConfChainReorg(t *testing.T) {
NumConfirmations: tx1NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx1NumConfs),
}
if err := txConfNotifier.Register(&ntfn1); err != nil {
if err := tcn.Register(&ntfn1); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -459,7 +459,7 @@ func TestTxConfChainReorg(t *testing.T) {
NumConfirmations: tx2NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx2NumConfs),
}
if err := txConfNotifier.Register(&ntfn2); err != nil {
if err := tcn.Register(&ntfn2); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -470,7 +470,7 @@ func TestTxConfChainReorg(t *testing.T) {
NumConfirmations: tx3NumConfs,
Event: chainntnfs.NewConfirmationEvent(tx3NumConfs),
}
if err := txConfNotifier.Register(&ntfn3); err != nil {
if err := tcn.Register(&ntfn3); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -478,11 +478,11 @@ func TestTxConfChainReorg(t *testing.T) {
block1 := btcutil.NewBlock(&wire.MsgBlock{
Transactions: []*wire.MsgTx{&tx1},
})
err := txConfNotifier.ConnectTip(nil, 8, block1.Transactions())
err := tcn.ConnectTip(nil, 8, block1.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
err = txConfNotifier.ConnectTip(nil, 9, nil)
err = tcn.ConnectTip(nil, 9, nil)
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -490,7 +490,7 @@ func TestTxConfChainReorg(t *testing.T) {
block2 := btcutil.NewBlock(&wire.MsgBlock{
Transactions: []*wire.MsgTx{&tx2, &tx3},
})
err = txConfNotifier.ConnectTip(nil, 10, block2.Transactions())
err = tcn.ConnectTip(nil, 10, block2.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -547,17 +547,17 @@ func TestTxConfChainReorg(t *testing.T) {
// The block that included tx2 and tx3 is disconnected and two next
// blocks without them are connected.
err = txConfNotifier.DisconnectTip(10)
err = tcn.DisconnectTip(10)
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
err = txConfNotifier.ConnectTip(nil, 10, nil)
err = tcn.ConnectTip(nil, 10, nil)
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
err = txConfNotifier.ConnectTip(nil, 11, nil)
err = tcn.ConnectTip(nil, 11, nil)
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -605,12 +605,12 @@ func TestTxConfChainReorg(t *testing.T) {
})
block4 := btcutil.NewBlock(&wire.MsgBlock{})
err = txConfNotifier.ConnectTip(block3.Hash(), 12, block3.Transactions())
err = tcn.ConnectTip(block3.Hash(), 12, block3.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
err = txConfNotifier.ConnectTip(block4.Hash(), 13, block4.Transactions())
err = tcn.ConnectTip(block4.Hash(), 13, block4.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -687,7 +687,7 @@ func TestTxConfHeightHintCache(t *testing.T) {
// Initialize our TxConfNotifier instance backed by a height hint cache.
hintCache := newMockHintCache()
txConfNotifier := chainntnfs.NewTxConfNotifier(
tcn := chainntnfs.NewTxConfNotifier(
startingHeight, 100, hintCache,
)
@ -708,10 +708,10 @@ func TestTxConfHeightHintCache(t *testing.T) {
Event: chainntnfs.NewConfirmationEvent(2),
}
if err := txConfNotifier.Register(ntfn1); err != nil {
if err := tcn.Register(ntfn1); err != nil {
t.Fatalf("unable to register tx1: %v", err)
}
if err := txConfNotifier.Register(ntfn2); err != nil {
if err := tcn.Register(ntfn2); err != nil {
t.Fatalf("unable to register tx2: %v", err)
}
@ -739,7 +739,7 @@ func TestTxConfHeightHintCache(t *testing.T) {
Transactions: []*wire.MsgTx{&tx1},
})
err = txConfNotifier.ConnectTip(
err = tcn.ConnectTip(
block1.Hash(), tx1Height, block1.Transactions(),
)
if err != nil {
@ -772,7 +772,7 @@ func TestTxConfHeightHintCache(t *testing.T) {
Transactions: []*wire.MsgTx{&tx2},
})
err = txConfNotifier.ConnectTip(
err = tcn.ConnectTip(
block2.Hash(), tx2Height, block2.Transactions(),
)
if err != nil {
@ -800,7 +800,7 @@ func TestTxConfHeightHintCache(t *testing.T) {
// Now, we'll attempt do disconnect the last block in order to simulate
// a chain reorg.
if err := txConfNotifier.DisconnectTip(tx2Height); err != nil {
if err := tcn.DisconnectTip(tx2Height); err != nil {
t.Fatalf("Failed to disconnect block: %v", err)
}
@ -824,7 +824,7 @@ func TestTxConfTearDown(t *testing.T) {
)
hintCache := newMockHintCache()
txConfNotifier := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
tcn := chainntnfs.NewTxConfNotifier(10, 100, hintCache)
// Create the test transactions and register them with the
// TxConfNotifier to receive notifications.
@ -834,7 +834,7 @@ func TestTxConfTearDown(t *testing.T) {
NumConfirmations: 1,
Event: chainntnfs.NewConfirmationEvent(1),
}
if err := txConfNotifier.Register(&ntfn1); err != nil {
if err := tcn.Register(&ntfn1); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -844,7 +844,7 @@ func TestTxConfTearDown(t *testing.T) {
NumConfirmations: 2,
Event: chainntnfs.NewConfirmationEvent(2),
}
if err := txConfNotifier.Register(&ntfn2); err != nil {
if err := tcn.Register(&ntfn2); err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
@ -854,7 +854,7 @@ func TestTxConfTearDown(t *testing.T) {
Transactions: []*wire.MsgTx{&tx1, &tx2},
})
err := txConfNotifier.ConnectTip(block.Hash(), 11, block.Transactions())
err := tcn.ConnectTip(block.Hash(), 11, block.Transactions())
if err != nil {
t.Fatalf("Failed to connect block: %v", err)
}
@ -890,7 +890,7 @@ func TestTxConfTearDown(t *testing.T) {
// The notification channels should be closed for notifications that
// have not been dispatched yet, so we should not expect to receive any
// more updates.
txConfNotifier.TearDown()
tcn.TearDown()
// tx1 should not receive any more updates because it has already been
// confirmed and the TxConfNotifier has been shut down.