chainntnfs/interface_test: utilize TestChainNotifier interface in tests
Switches all ChainNotifier parameters to be TestChainNotifiers. This allows access to the extra testing methods provided by the TestChainNotifier interface.
This commit is contained in:
parent
b3a5b3b576
commit
f6ba64056a
@ -29,15 +29,15 @@ import (
|
|||||||
|
|
||||||
// Required to auto-register the bitcoind backed ChainNotifier
|
// Required to auto-register the bitcoind backed ChainNotifier
|
||||||
// implementation.
|
// implementation.
|
||||||
_ "github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify"
|
"github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify"
|
||||||
|
|
||||||
// Required to auto-register the btcd backed ChainNotifier
|
// Required to auto-register the btcd backed ChainNotifier
|
||||||
// implementation.
|
// implementation.
|
||||||
_ "github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
|
"github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
|
||||||
|
|
||||||
// Required to auto-register the neutrino backed ChainNotifier
|
// Required to auto-register the neutrino backed ChainNotifier
|
||||||
// implementation.
|
// implementation.
|
||||||
_ "github.com/lightningnetwork/lnd/chainntnfs/neutrinonotify"
|
"github.com/lightningnetwork/lnd/chainntnfs/neutrinonotify"
|
||||||
|
|
||||||
// Required to register the boltdb walletdb implementation.
|
// Required to register the boltdb walletdb implementation.
|
||||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
||||||
@ -113,7 +113,7 @@ func waitForMempoolTx(r *rpctest.Harness, txid *chainhash.Hash) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testSingleConfirmationNotification(miner *rpctest.Harness,
|
func testSingleConfirmationNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the case of being notified once a txid reaches
|
// We'd like to test the case of being notified once a txid reaches
|
||||||
// a *single* confirmation.
|
// a *single* confirmation.
|
||||||
@ -184,7 +184,7 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testMultiConfirmationNotification(miner *rpctest.Harness,
|
func testMultiConfirmationNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the case of being notified once a txid reaches
|
// We'd like to test the case of being notified once a txid reaches
|
||||||
// N confirmations, where N > 1.
|
// N confirmations, where N > 1.
|
||||||
@ -232,7 +232,7 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testBatchConfirmationNotification(miner *rpctest.Harness,
|
func testBatchConfirmationNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test a case of serving notifications to multiple
|
// We'd like to test a case of serving notifications to multiple
|
||||||
// clients, each requesting to be notified once a txid receives
|
// clients, each requesting to be notified once a txid receives
|
||||||
@ -400,7 +400,7 @@ func checkNotificationFields(ntfn *chainntnfs.SpendDetail,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testSpendNotification(miner *rpctest.Harness,
|
func testSpendNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the spend notifications for all ChainNotifier
|
// We'd like to test the spend notifications for all ChainNotifier
|
||||||
// concrete implementations.
|
// concrete implementations.
|
||||||
@ -512,7 +512,7 @@ func testSpendNotification(miner *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testBlockEpochNotification(miner *rpctest.Harness,
|
func testBlockEpochNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the case of multiple registered clients receiving
|
// We'd like to test the case of multiple registered clients receiving
|
||||||
// block epoch notifications.
|
// block epoch notifications.
|
||||||
@ -560,7 +560,7 @@ func testBlockEpochNotification(miner *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testMultiClientConfirmationNotification(miner *rpctest.Harness,
|
func testMultiClientConfirmationNotification(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the case of a multiple clients registered to
|
// We'd like to test the case of a multiple clients registered to
|
||||||
// receive a confirmation notification for the same transaction.
|
// receive a confirmation notification for the same transaction.
|
||||||
@ -626,7 +626,7 @@ func testMultiClientConfirmationNotification(miner *rpctest.Harness,
|
|||||||
// transaction that has already been included in a block. In this case, the
|
// transaction that has already been included in a block. In this case, the
|
||||||
// confirmation notification should be dispatched immediately.
|
// confirmation notification should be dispatched immediately.
|
||||||
func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// First, let's send some coins to "ourself", obtaining a txid. We're
|
// First, let's send some coins to "ourself", obtaining a txid. We're
|
||||||
// spending from a coinbase output here, so we use the dedicated
|
// spending from a coinbase output here, so we use the dedicated
|
||||||
@ -786,7 +786,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
|||||||
// checking for a confirmation. This should not cause the notifier to stop
|
// checking for a confirmation. This should not cause the notifier to stop
|
||||||
// working
|
// working
|
||||||
func testLazyNtfnConsumer(miner *rpctest.Harness,
|
func testLazyNtfnConsumer(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// Create a transaction to be notified about. We'll register for
|
// Create a transaction to be notified about. We'll register for
|
||||||
// notifications on this transaction but won't be prompt in checking them
|
// notifications on this transaction but won't be prompt in checking them
|
||||||
@ -877,7 +877,7 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
|
|||||||
// has already been included in a block. In this case, the spend notification
|
// has already been included in a block. In this case, the spend notification
|
||||||
// should be dispatched immediately.
|
// should be dispatched immediately.
|
||||||
func testSpendBeforeNtfnRegistration(miner *rpctest.Harness,
|
func testSpendBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test the spend notifications for all ChainNotifier
|
// We'd like to test the spend notifications for all ChainNotifier
|
||||||
// concrete implementations.
|
// concrete implementations.
|
||||||
@ -981,7 +981,7 @@ func testSpendBeforeNtfnRegistration(miner *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCancelSpendNtfn(node *rpctest.Harness,
|
func testCancelSpendNtfn(node *rpctest.Harness,
|
||||||
notifier chainntnfs.ChainNotifier, t *testing.T) {
|
notifier chainntnfs.TestChainNotifier, t *testing.T) {
|
||||||
|
|
||||||
// We'd like to test that once a spend notification is registered, it
|
// We'd like to test that once a spend notification is registered, it
|
||||||
// can be cancelled before the notification is dispatched.
|
// can be cancelled before the notification is dispatched.
|
||||||
@ -1072,7 +1072,7 @@ func testCancelSpendNtfn(node *rpctest.Harness,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCancelEpochNtfn(node *rpctest.Harness, notifier chainntnfs.ChainNotifier,
|
func testCancelEpochNtfn(node *rpctest.Harness, notifier chainntnfs.TestChainNotifier,
|
||||||
t *testing.T) {
|
t *testing.T) {
|
||||||
|
|
||||||
// We'd like to ensure that once a client cancels their block epoch
|
// We'd like to ensure that once a client cancels their block epoch
|
||||||
@ -1122,7 +1122,7 @@ func testCancelEpochNtfn(node *rpctest.Harness, notifier chainntnfs.ChainNotifie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testReorgConf(miner *rpctest.Harness, notifier chainntnfs.ChainNotifier,
|
func testReorgConf(miner *rpctest.Harness, notifier chainntnfs.TestChainNotifier,
|
||||||
t *testing.T) {
|
t *testing.T) {
|
||||||
|
|
||||||
// Set up a new miner that we can use to cause a reorg.
|
// Set up a new miner that we can use to cause a reorg.
|
||||||
@ -1277,7 +1277,7 @@ func testReorgConf(miner *rpctest.Harness, notifier chainntnfs.ChainNotifier,
|
|||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
|
|
||||||
test func(node *rpctest.Harness, notifier chainntnfs.ChainNotifier, t *testing.T)
|
test func(node *rpctest.Harness, notifier chainntnfs.TestChainNotifier, t *testing.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ntfnTests = []testCase{
|
var ntfnTests = []testCase{
|
||||||
@ -1361,8 +1361,10 @@ func TestInterfaces(t *testing.T) {
|
|||||||
|
|
||||||
log.Printf("Running %v ChainNotifier interface tests\n", len(ntfnTests))
|
log.Printf("Running %v ChainNotifier interface tests\n", len(ntfnTests))
|
||||||
var (
|
var (
|
||||||
notifier chainntnfs.ChainNotifier
|
notifier chainntnfs.TestChainNotifier
|
||||||
cleanUp func()
|
cleanUp func()
|
||||||
|
|
||||||
|
newNotifier func() (chainntnfs.TestChainNotifier, error)
|
||||||
)
|
)
|
||||||
for _, notifierDriver := range chainntnfs.RegisteredNotifiers() {
|
for _, notifierDriver := range chainntnfs.RegisteredNotifiers() {
|
||||||
notifierType := notifierDriver.NotifierType
|
notifierType := notifierDriver.NotifierType
|
||||||
@ -1430,18 +1432,15 @@ func TestInterfaces(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cleanUp = cleanUp3
|
cleanUp = cleanUp3
|
||||||
|
|
||||||
notifier, err = notifierDriver.New(chainConn)
|
newNotifier = func() (chainntnfs.TestChainNotifier, error) {
|
||||||
if err != nil {
|
return bitcoindnotify.New(chainConn), nil
|
||||||
t.Fatalf("unable to create %v notifier: %v",
|
|
||||||
notifierType, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "btcd":
|
case "btcd":
|
||||||
notifier, err = notifierDriver.New(&rpcConfig)
|
newNotifier = func() (chainntnfs.TestChainNotifier, error) {
|
||||||
if err != nil {
|
return btcdnotify.New(&rpcConfig)
|
||||||
t.Fatalf("unable to create %v notifier: %v",
|
|
||||||
notifierType, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUp = func() {}
|
cleanUp = func() {}
|
||||||
|
|
||||||
case "neutrino":
|
case "neutrino":
|
||||||
@ -1481,16 +1480,18 @@ func TestInterfaces(t *testing.T) {
|
|||||||
for !spvNode.IsCurrent() {
|
for !spvNode.IsCurrent() {
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
}
|
}
|
||||||
|
newNotifier = func() (chainntnfs.TestChainNotifier, error) {
|
||||||
notifier, err = notifierDriver.New(spvNode)
|
return neutrinonotify.New(spvNode)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to create %v notifier: %v",
|
|
||||||
notifierType, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running ChainNotifier interface tests for: %v", notifierType)
|
t.Logf("Running ChainNotifier interface tests for: %v", notifierType)
|
||||||
|
|
||||||
|
notifier, err = newNotifier()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create %v notifier: %v", notifierType, err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := notifier.Start(); err != nil {
|
if err := notifier.Start(); err != nil {
|
||||||
t.Fatalf("unable to start notifier %v: %v",
|
t.Fatalf("unable to start notifier %v: %v",
|
||||||
notifierType, err)
|
notifierType, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user