multi: move many t.Fatalf calls to require.NoError

This commit is contained in:
Tommy Volk committed 2022-06-17 04:26:55 +00:00
1 parent 9e6f0ef46b
commit 9a10c80bcb
92 files changed
+1905 -5565

No files matched your search

+39 -117
View File
@@ -203,9 +203,7 @@ func createTestChannel(t *testing.T, cdb *ChannelStateDB,
// Mark the channel as open with the short channel id provided.
err = params.channel.MarkAsOpen(params.channel.ShortChannelID)
if err != nil {
t.Fatalf("unable to mark channel open: %v", err)
}
require.NoError(t, err, "unable to mark channel open")
return params.channel
}
@@ -213,9 +211,7 @@ func createTestChannel(t *testing.T, cdb *ChannelStateDB,
func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
// Simulate 1000 channel updates.
producer, err := shachain.NewRevocationProducerFromBytes(key[:])
if err != nil {
t.Fatalf("could not get producer: %v", err)
}
require.NoError(t, err, "could not get producer")
store := shachain.NewRevocationStore()
for i := 0; i < 1; i++ {
preImage, err := producer.AtIndex(uint64(i))
@@ -351,9 +347,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -388,9 +382,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
)
openChannels, err := cdb.FetchOpenChannels(state.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch open channel: %v", err)
}
require.NoError(t, err, "unable to fetch open channel")
newState := openChannels[0]
@@ -405,17 +397,13 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
// next revocation for the state machine. This tests the initial
// post-funding revocation exchange.
nextRevKey, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to create new private key: %v", err)
}
require.NoError(t, err, "unable to create new private key")
if err := state.InsertNextRevocation(nextRevKey.PubKey()); err != nil {
t.Fatalf("unable to update revocation: %v", err)
}
openChannels, err = cdb.FetchOpenChannels(state.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch open channel: %v", err)
}
require.NoError(t, err, "unable to fetch open channel")
updatedChan := openChannels[0]
// Ensure that the revocation was set properly.
@@ -442,9 +430,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
// As the channel is now closed, attempting to fetch all open channels
// for our fake node ID should return an empty slice.
openChans, err := cdb.FetchOpenChannels(state.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch open channels: %v", err)
}
require.NoError(t, err, "unable to fetch open channels")
if len(openChans) != 0 {
t.Fatalf("all channels not deleted, found %v", len(openChans))
}
@@ -587,9 +573,7 @@ func TestChannelStateTransition(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -661,15 +645,11 @@ func TestChannelStateTransition(t *testing.T) {
}
err = channel.UpdateCommitment(&commitment, unsignedAckedUpdates)
if err != nil {
t.Fatalf("unable to update commitment: %v", err)
}
require.NoError(t, err, "unable to update commitment")
// Assert that update is correctly written to the database.
dbUnsignedAckedUpdates, err := channel.UnsignedAckedUpdates()
if err != nil {
t.Fatalf("unable to fetch dangling remote updates: %v", err)
}
require.NoError(t, err, "unable to fetch dangling remote updates")
if len(dbUnsignedAckedUpdates) != 1 {
t.Fatalf("unexpected number of dangling remote updates")
}
@@ -686,14 +666,10 @@ func TestChannelStateTransition(t *testing.T) {
// commitment transaction along with the modified signature should all
// have been updated.
updatedChannel, err := cdb.FetchOpenChannels(channel.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch updated channel: %v", err)
}
require.NoError(t, err, "unable to fetch updated channel")
assertCommitmentEqual(t, &commitment, &updatedChannel[0].LocalCommitment)
numDiskUpdates, err := updatedChannel[0].CommitmentHeight()
if err != nil {
t.Fatalf("unable to read commitment height from disk: %v", err)
}
require.NoError(t, err, "unable to read commitment height from disk")
if numDiskUpdates != uint64(commitment.CommitHeight) {
t.Fatalf("num disk updates doesn't match: %v vs %v",
numDiskUpdates, commitment.CommitHeight)
@@ -757,9 +733,7 @@ func TestChannelStateTransition(t *testing.T) {
// The commitment tip should now match the commitment that we just
// inserted.
diskCommitDiff, err := channel.RemoteCommitChainTip()
if err != nil {
t.Fatalf("unable to fetch commit diff: %v", err)
}
require.NoError(t, err, "unable to fetch commit diff")
if !reflect.DeepEqual(commitDiff, diskCommitDiff) {
t.Fatalf("commit diffs don't match: %v vs %v", spew.Sdump(remoteCommit),
spew.Sdump(diskCommitDiff))
@@ -775,9 +749,7 @@ func TestChannelStateTransition(t *testing.T) {
// by the remote party.
channel.RemoteCurrentRevocation = channel.RemoteNextRevocation
newPriv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
require.NoError(t, err, "unable to generate key")
channel.RemoteNextRevocation = newPriv.PubKey()
fwdPkg := NewFwdPkg(channel.ShortChanID(), oldRemoteCommit.CommitHeight,
@@ -786,9 +758,7 @@ func TestChannelStateTransition(t *testing.T) {
err = channel.AdvanceCommitChainTail(
fwdPkg, nil, dummyLocalOutputIndex, dummyRemoteOutIndex,
)
if err != nil {
t.Fatalf("unable to append to revocation log: %v", err)
}
require.NoError(t, err, "unable to append to revocation log")
// At this point, the remote commit chain should be nil, and the posted
// remote commitment should match the one we added as a diff above.
@@ -801,9 +771,7 @@ func TestChannelStateTransition(t *testing.T) {
diskPrevCommit, _, err := channel.FindPreviousState(
oldRemoteCommit.CommitHeight,
)
if err != nil {
t.Fatalf("unable to fetch past delta: %v", err)
}
require.NoError(t, err, "unable to fetch past delta")
// Check the output indexes are saved as expected.
require.EqualValues(
@@ -820,9 +788,7 @@ func TestChannelStateTransition(t *testing.T) {
// The state number recovered from the tail of the revocation log
// should be identical to this current state.
logTailHeight, err := channel.revocationLogTailCommitHeight()
if err != nil {
t.Fatalf("unable to retrieve log: %v", err)
}
require.NoError(t, err, "unable to retrieve log")
if logTailHeight != oldRemoteCommit.CommitHeight {
t.Fatal("update number doesn't match")
}
@@ -844,17 +810,13 @@ func TestChannelStateTransition(t *testing.T) {
err = channel.AdvanceCommitChainTail(
fwdPkg, nil, dummyLocalOutputIndex, dummyRemoteOutIndex,
)
if err != nil {
t.Fatalf("unable to append to revocation log: %v", err)
}
require.NoError(t, err, "unable to append to revocation log")
// Once again, fetch the state and ensure it has been properly updated.
prevCommit, _, err := channel.FindPreviousState(
oldRemoteCommit.CommitHeight,
)
if err != nil {
t.Fatalf("unable to fetch past delta: %v", err)
}
require.NoError(t, err, "unable to fetch past delta")
// Check the output indexes are saved as expected.
require.EqualValues(
@@ -869,18 +831,14 @@ func TestChannelStateTransition(t *testing.T) {
// Once again, state number recovered from the tail of the revocation
// log should be identical to this current state.
logTailHeight, err = channel.revocationLogTailCommitHeight()
if err != nil {
t.Fatalf("unable to retrieve log: %v", err)
}
require.NoError(t, err, "unable to retrieve log")
if logTailHeight != oldRemoteCommit.CommitHeight {
t.Fatal("update number doesn't match")
}
// The revocation state stored on-disk should now also be identical.
updatedChannel, err = cdb.FetchOpenChannels(channel.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch updated channel: %v", err)
}
require.NoError(t, err, "unable to fetch updated channel")
if !channel.RemoteCurrentRevocation.IsEqual(updatedChannel[0].RemoteCurrentRevocation) {
t.Fatalf("revocation state was not synced")
}
@@ -908,9 +866,7 @@ func TestChannelStateTransition(t *testing.T) {
// If we attempt to fetch the target channel again, it shouldn't be
// found.
channels, err := cdb.FetchOpenChannels(channel.IdentityPub)
if err != nil {
t.Fatalf("unable to fetch updated channels: %v", err)
}
require.NoError(t, err, "unable to fetch updated channels")
if len(channels) != 0 {
t.Fatalf("%v channels, found, but none should be",
len(channels))
@@ -934,9 +890,7 @@ func TestFetchPendingChannels(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -946,9 +900,7 @@ func TestFetchPendingChannels(t *testing.T) {
createTestChannel(t, cdb, pendingHeightOption(broadcastHeight))
pendingChannels, err := cdb.FetchPendingChannels()
if err != nil {
t.Fatalf("unable to list pending channels: %v", err)
}
require.NoError(t, err, "unable to list pending channels")
if len(pendingChannels) != 1 {
t.Fatalf("incorrect number of pending channels: expecting %v,"+
@@ -969,9 +921,7 @@ func TestFetchPendingChannels(t *testing.T) {
TxPosition: 15,
}
err = pendingChannels[0].MarkAsOpen(chanOpenLoc)
if err != nil {
t.Fatalf("unable to mark channel as open: %v", err)
}
require.NoError(t, err, "unable to mark channel as open")
if pendingChannels[0].IsPending {
t.Fatalf("channel marked open should no longer be pending")
@@ -986,9 +936,7 @@ func TestFetchPendingChannels(t *testing.T) {
// Next, we'll re-fetch the channel to ensure that the open height was
// properly set.
openChans, err := cdb.FetchAllChannels()
if err != nil {
t.Fatalf("unable to fetch channels: %v", err)
}
require.NoError(t, err, "unable to fetch channels")
if openChans[0].ShortChanID() != chanOpenLoc {
t.Fatalf("channel opening heights don't match: expected %v, "+
"got %v", spew.Sdump(openChans[0].ShortChanID()),
@@ -1001,9 +949,7 @@ func TestFetchPendingChannels(t *testing.T) {
}
pendingChannels, err = cdb.FetchPendingChannels()
if err != nil {
t.Fatalf("unable to list pending channels: %v", err)
}
require.NoError(t, err, "unable to list pending channels")
if len(pendingChannels) != 0 {
t.Fatalf("incorrect number of pending channels: expecting %v,"+
@@ -1015,9 +961,7 @@ func TestFetchClosedChannels(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -1046,9 +990,7 @@ func TestFetchClosedChannels(t *testing.T) {
// closed. We should get the same result whether querying for pending
// channels only, or not.
pendingClosed, err := cdb.FetchClosedChannels(true)
if err != nil {
t.Fatalf("failed fetching closed channels: %v", err)
}
require.NoError(t, err, "failed fetching closed channels")
if len(pendingClosed) != 1 {
t.Fatalf("incorrect number of pending closed channels: expecting %v,"+
"got %v", 1, len(pendingClosed))
@@ -1058,9 +1000,7 @@ func TestFetchClosedChannels(t *testing.T) {
spew.Sdump(summary), spew.Sdump(pendingClosed[0]))
}
closed, err := cdb.FetchClosedChannels(false)
if err != nil {
t.Fatalf("failed fetching all closed channels: %v", err)
}
require.NoError(t, err, "failed fetching all closed channels")
if len(closed) != 1 {
t.Fatalf("incorrect number of closed channels: expecting %v, "+
"got %v", 1, len(closed))
@@ -1072,24 +1012,18 @@ func TestFetchClosedChannels(t *testing.T) {
// Mark the channel as fully closed.
err = cdb.MarkChanFullyClosed(&state.FundingOutpoint)
if err != nil {
t.Fatalf("failed fully closing channel: %v", err)
}
require.NoError(t, err, "failed fully closing channel")
// The channel should no longer be considered pending, but should still
// be retrieved when fetching all the closed channels.
closed, err = cdb.FetchClosedChannels(false)
if err != nil {
t.Fatalf("failed fetching closed channels: %v", err)
}
require.NoError(t, err, "failed fetching closed channels")
if len(closed) != 1 {
t.Fatalf("incorrect number of closed channels: expecting %v, "+
"got %v", 1, len(closed))
}
pendingClose, err := cdb.FetchClosedChannels(true)
if err != nil {
t.Fatalf("failed fetching channels pending close: %v", err)
}
require.NoError(t, err, "failed fetching channels pending close")
if len(pendingClose) != 0 {
t.Fatalf("incorrect number of closed channels: expecting %v, "+
"got %v", 0, len(closed))
@@ -1108,9 +1042,7 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
// them will have their funding transaction confirmed on-chain, while
// the other one will remain unconfirmed.
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -1172,9 +1104,7 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
// database. We should expect to see both channels above, even if any of
// them haven't had their funding transaction confirm on-chain.
waitingCloseChannels, err := cdb.FetchWaitingCloseChannels()
if err != nil {
t.Fatalf("unable to fetch all waiting close channels: %v", err)
}
require.NoError(t, err, "unable to fetch all waiting close channels")
if len(waitingCloseChannels) != numChannels {
t.Fatalf("expected %d channels waiting to be closed, got %d", 2,
len(waitingCloseChannels))
@@ -1225,9 +1155,7 @@ func TestRefreshShortChanID(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -1262,9 +1190,7 @@ func TestRefreshShortChanID(t *testing.T) {
}
err = state.MarkAsOpen(chanOpenLoc)
if err != nil {
t.Fatalf("unable to mark channel open: %v", err)
}
require.NoError(t, err, "unable to mark channel open")
// The short_chan_id of the receiver to MarkAsOpen should reflect the
// open location, but the other pending channel should remain unchanged.
@@ -1285,9 +1211,7 @@ func TestRefreshShortChanID(t *testing.T) {
// Now, refresh the short channel ID of the pending channel.
err = pendingChannel.RefreshShortChanID()
if err != nil {
t.Fatalf("unable to refresh short_chan_id: %v", err)
}
require.NoError(t, err, "unable to refresh short_chan_id")
// This should result in both OpenChannel's now having the same
// ShortChanID.
@@ -1447,9 +1371,7 @@ func TestCloseChannelStatus(t *testing.T) {
histChan, err := channel.Db.FetchHistoricalChannel(
&channel.FundingOutpoint,
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
require.NoError(t, err, "unexpected error")
if !histChan.HasChanStatus(ChanStatusRemoteCloseInitiator) {
t.Fatalf("channel should have status")
+26 -78
View File
@@ -33,23 +33,17 @@ func TestOpenWithCreate(t *testing.T) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := ioutil.TempDir("", "channeldb")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
require.NoError(t, err, "unable to create temp dir")
defer os.RemoveAll(tempDirName)
// Next, open thereby creating channeldb for the first time.
dbPath := filepath.Join(tempDirName, "cdb")
backend, cleanup, err := kvdb.GetTestBackend(dbPath, "cdb")
if err != nil {
t.Fatalf("unable to get test db backend: %v", err)
}
require.NoError(t, err, "unable to get test db backend")
defer cleanup()
cdb, err := CreateWithBackend(backend)
if err != nil {
t.Fatalf("unable to create channeldb: %v", err)
}
require.NoError(t, err, "unable to create channeldb")
if err := cdb.Close(); err != nil {
t.Fatalf("unable to close channeldb: %v", err)
}
@@ -62,9 +56,7 @@ func TestOpenWithCreate(t *testing.T) {
// Now, reopen the same db in dry run migration mode. Since we have not
// applied any migrations, this should ignore the flag and not fail.
cdb, err = Open(dbPath, OptionDryRunMigration(true))
if err != nil {
t.Fatalf("unable to create channeldb: %v", err)
}
require.NoError(t, err, "unable to create channeldb")
if err := cdb.Close(); err != nil {
t.Fatalf("unable to close channeldb: %v", err)
}
@@ -79,23 +71,17 @@ func TestWipe(t *testing.T) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := ioutil.TempDir("", "channeldb")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
require.NoError(t, err, "unable to create temp dir")
defer os.RemoveAll(tempDirName)
// Next, open thereby creating channeldb for the first time.
dbPath := filepath.Join(tempDirName, "cdb")
backend, cleanup, err := kvdb.GetTestBackend(dbPath, "cdb")
if err != nil {
t.Fatalf("unable to get test db backend: %v", err)
}
require.NoError(t, err, "unable to get test db backend")
defer cleanup()
fullDB, err := CreateWithBackend(backend)
if err != nil {
t.Fatalf("unable to create channeldb: %v", err)
}
require.NoError(t, err, "unable to create channeldb")
defer fullDB.Close()
if err := fullDB.Wipe(); err != nil {
@@ -122,9 +108,7 @@ func TestFetchClosedChannelForID(t *testing.T) {
const numChans = 101
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -195,9 +179,7 @@ func TestAddrsForNode(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
graph := fullDB.ChannelGraph()
@@ -206,9 +188,7 @@ func TestAddrsForNode(t *testing.T) {
// node, but this node will only have half the number of addresses it
// usually does.
testNode, err := createTestVertex(fullDB)
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
testNode.Addresses = []net.Addr{testAddr}
if err := graph.SetSourceNode(testNode); err != nil {
t.Fatalf("unable to set source node: %v", err)
@@ -217,9 +197,7 @@ func TestAddrsForNode(t *testing.T) {
// Next, we'll make a link node with the same pubkey, but with an
// additional address.
nodePub, err := testNode.PubKey()
if err != nil {
t.Fatalf("unable to recv node pub: %v", err)
}
require.NoError(t, err, "unable to recv node pub")
linkNode := NewLinkNode(
fullDB.channelStateDB.linkNodeDB, wire.MainNet, nodePub,
anotherAddr,
@@ -231,9 +209,7 @@ func TestAddrsForNode(t *testing.T) {
// Now that we've created a link node, as well as a vertex for the
// node, we'll query for all its addresses.
nodeAddrs, err := fullDB.AddrsForNode(nodePub)
if err != nil {
t.Fatalf("unable to obtain node addrs: %v", err)
}
require.NoError(t, err, "unable to obtain node addrs")
expectedAddrs := make(map[string]struct{})
expectedAddrs[testAddr.String()] = struct{}{}
@@ -257,9 +233,7 @@ func TestFetchChannel(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -269,9 +243,7 @@ func TestFetchChannel(t *testing.T) {
// Next, attempt to fetch the channel by its chan point.
dbChannel, err := cdb.FetchChannel(nil, channelState.FundingOutpoint)
if err != nil {
t.Fatalf("unable to fetch channel: %v", err)
}
require.NoError(t, err, "unable to fetch channel")
// The decoded channel state should be identical to what we stored
// above.
@@ -283,9 +255,7 @@ func TestFetchChannel(t *testing.T) {
// If we attempt to query for a non-exist ante channel, then we should
// get an error.
channelState2 := createTestChannelState(t, cdb)
if err != nil {
t.Fatalf("unable to create channel state: %v", err)
}
require.NoError(t, err, "unable to create channel state")
channelState2.FundingOutpoint.Index ^= 1
_, err = cdb.FetchChannel(nil, channelState2.FundingOutpoint)
@@ -361,9 +331,7 @@ func TestRestoreChannelShells(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -372,9 +340,7 @@ func TestRestoreChannelShells(t *testing.T) {
// amount of information required for us to initiate the data loss
// protection feature.
channelShell, err := genRandomChannelShell()
if err != nil {
t.Fatalf("unable to gen channel shell: %v", err)
}
require.NoError(t, err, "unable to gen channel shell")
// With the channel shell constructed, we'll now insert it into the
// database with the restoration method.
@@ -388,9 +354,7 @@ func TestRestoreChannelShells(t *testing.T) {
// First, we'll attempt to query for all channels that we have with the
// node public key that was restored.
nodeChans, err := cdb.FetchOpenChannels(channelShell.Chan.IdentityPub)
if err != nil {
t.Fatalf("unable find channel: %v", err)
}
require.NoError(t, err, "unable find channel")
// We should now find a single channel from the database.
if len(nodeChans) != 1 {
@@ -432,18 +396,14 @@ func TestRestoreChannelShells(t *testing.T) {
// We should also be able to find the channel if we query for it
// directly.
_, err = cdb.FetchChannel(nil, channelShell.Chan.FundingOutpoint)
if err != nil {
t.Fatalf("unable to fetch channel: %v", err)
}
require.NoError(t, err, "unable to fetch channel")
// We should also be able to find the link node that was inserted by
// its public key.
linkNode, err := fullDB.channelStateDB.linkNodeDB.FetchLinkNode(
channelShell.Chan.IdentityPub,
)
if err != nil {
t.Fatalf("unable to fetch link node: %v", err)
}
require.NoError(t, err, "unable to fetch link node")
// The node should have the same address, as specified in the channel
// shell.
@@ -461,9 +421,7 @@ func TestAbandonChannel(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -483,9 +441,7 @@ func TestAbandonChannel(t *testing.T) {
// We should now be able to abandon the channel without any errors.
closeHeight := uint32(11)
err = cdb.AbandonChannel(&chanState.FundingOutpoint, closeHeight)
if err != nil {
t.Fatalf("unable to abandon channel: %v", err)
}
require.NoError(t, err, "unable to abandon channel")
// At this point, the channel should no longer be found in the set of
// open channels.
@@ -497,16 +453,12 @@ func TestAbandonChannel(t *testing.T) {
// However we should be able to retrieve a close channel summary for
// the channel.
_, err = cdb.FetchClosedChannel(&chanState.FundingOutpoint)
if err != nil {
t.Fatalf("unable to fetch closed channel: %v", err)
}
require.NoError(t, err, "unable to fetch closed channel")
// Finally, if we attempt to abandon the channel again, we should get a
// nil error as the channel has already been abandoned.
err = cdb.AbandonChannel(&chanState.FundingOutpoint, closeHeight)
if err != nil {
t.Fatalf("unable to abandon channel: %v", err)
}
require.NoError(t, err, "unable to abandon channel")
}
// TestFetchChannels tests the filtering of open channels in fetchChannels.
@@ -707,9 +659,7 @@ func TestFetchChannels(t *testing.T) {
// TestFetchHistoricalChannel tests lookup of historical channels.
func TestFetchHistoricalChannel(t *testing.T) {
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -737,9 +687,7 @@ func TestFetchHistoricalChannel(t *testing.T) {
}
histChannel, err := cdb.FetchHistoricalChannel(&channel.FundingOutpoint)
if err != nil {
t.Fatalf("unexpected error getting channel: %v", err)
}
require.NoError(t, err, "unexpected error getting channel")
// FetchHistoricalChannel will attach the cdb to channel.Db, we set it
// here so that we can check that all other fields on the channel equal
+10 -27
View File
@@ -9,6 +9,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestForwardingLogBasicStorageAndQuery tests that we're able to store and
@@ -20,9 +21,7 @@ func TestForwardingLogBasicStorageAndQuery(t *testing.T) {
// forwarding event log that we'll be using for the duration of the
// test.
db, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
defer cleanUp()
log := ForwardingLog{
@@ -63,9 +62,7 @@ func TestForwardingLogBasicStorageAndQuery(t *testing.T) {
NumMaxEvents: 1000,
}
timeSlice, err := log.Query(eventQuery)
if err != nil {
t.Fatalf("unable to query for events: %v", err)
}
require.NoError(t, err, "unable to query for events")
// The set of returned events should match identically, as they should
// be returned in sorted order.
@@ -93,9 +90,7 @@ func TestForwardingLogQueryOptions(t *testing.T) {
// forwarding event log that we'll be using for the duration of the
// test.
db, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
defer cleanUp()
log := ForwardingLog{
@@ -136,9 +131,7 @@ func TestForwardingLogQueryOptions(t *testing.T) {
NumMaxEvents: 10,
}
timeSlice, err := log.Query(eventQuery)
if err != nil {
t.Fatalf("unable to query for events: %v", err)
}
require.NoError(t, err, "unable to query for events")
// We should get exactly 10 events back.
if len(timeSlice.ForwardingEvents) != 10 {
@@ -164,9 +157,7 @@ func TestForwardingLogQueryOptions(t *testing.T) {
// more events, that are the last 10 events we wrote.
eventQuery.IndexOffset = 10
timeSlice, err = log.Query(eventQuery)
if err != nil {
t.Fatalf("unable to query for events: %v", err)
}
require.NoError(t, err, "unable to query for events")
// We should get exactly 10 events back once again.
if len(timeSlice.ForwardingEvents) != 10 {
@@ -199,9 +190,7 @@ func TestForwardingLogQueryLimit(t *testing.T) {
// forwarding event log that we'll be using for the duration of the
// test.
db, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
defer cleanUp()
log := ForwardingLog{
@@ -242,9 +231,7 @@ func TestForwardingLogQueryLimit(t *testing.T) {
NumMaxEvents: 100,
}
timeSlice, err := log.Query(eventQuery)
if err != nil {
t.Fatalf("unable to query for events: %v", err)
}
require.NoError(t, err, "unable to query for events")
// We should get exactly 100 events back.
if len(timeSlice.ForwardingEvents) != 100 {
@@ -315,9 +302,7 @@ func TestForwardingLogStoreEvent(t *testing.T) {
// forwarding event log that we'll be using for the duration of the
// test.
db, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
defer cleanUp()
log := ForwardingLog{
@@ -362,9 +347,7 @@ func TestForwardingLogStoreEvent(t *testing.T) {
NumMaxEvents: uint32(numEvents * 3),
}
timeSlice, err := log.Query(eventQuery)
if err != nil {
t.Fatalf("unable to query for events: %v", err)
}
require.NoError(t, err, "unable to query for events")
// We should get exactly 40 events back.
if len(timeSlice.ForwardingEvents) != numEvents*2 {
+1 -3
View File
@@ -855,9 +855,7 @@ func makeFwdPkgDB(t *testing.T, path string) kvdb.Backend { // nolint:unparam
bdb, err := kvdb.Create(
kvdb.BoltBackendName, path, true, kvdb.DefaultDBTimeout,
)
if err != nil {
t.Fatalf("unable to open boltdb: %v", err)
}
require.NoError(t, err, "unable to open boltdb")
return bdb
}
+122 -366
View File
File diff suppressed because it is too large. Load diff
+20 -60
View File
@@ -151,16 +151,12 @@ func TestInvoiceWorkflow(t *testing.T) {
func testInvoiceWorkflow(t *testing.T, test invWorkflowTest) {
db, cleanUp, err := MakeTestDB()
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
// Create a fake invoice which we'll use several times in the tests
// below.
fakeInvoice, err := randInvoice(10000)
if err != nil {
t.Fatalf("unable to create invoice: %v", err)
}
require.NoError(t, err, "unable to create invoice")
invPayHash := fakeInvoice.Terms.PaymentPreimage.Hash()
// Select the payment hash and payment address we will use to lookup or
@@ -216,13 +212,9 @@ func testInvoiceWorkflow(t *testing.T, test invWorkflowTest) {
// SettledDate
payAmt := fakeInvoice.Terms.Value * 2
_, err = db.UpdateInvoice(ref, nil, getUpdateInvoice(payAmt))
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
require.NoError(t, err, "unable to settle invoice")
dbInvoice2, err := db.LookupInvoice(ref)
if err != nil {
t.Fatalf("unable to fetch invoice: %v", err)
}
require.NoError(t, err, "unable to fetch invoice")
if dbInvoice2.State != ContractSettled {
t.Fatalf("invoice should now be settled but isn't")
}
@@ -284,9 +276,7 @@ func testInvoiceWorkflow(t *testing.T, test invWorkflowTest) {
}
response, err := db.QueryInvoices(query)
if err != nil {
t.Fatalf("invoice query failed: %v", err)
}
require.NoError(t, err, "invoice query failed")
// The retrieve list of invoices should be identical as since we're
// using big endian, the invoices should be retrieved in ascending
@@ -443,9 +433,7 @@ func TestInvoiceCancelSingleHtlc(t *testing.T) {
db, cleanUp, err := MakeTestDB()
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
preimage := lntypes.Preimage{1}
paymentHash := preimage.Hash()
@@ -479,9 +467,7 @@ func TestInvoiceCancelSingleHtlc(t *testing.T) {
},
}, nil
})
if err != nil {
t.Fatalf("unable to add invoice htlc: %v", err)
}
require.NoError(t, err, "unable to add invoice htlc")
if len(invoice.Htlcs) != 1 {
t.Fatalf("expected the htlc to be added")
}
@@ -498,9 +484,7 @@ func TestInvoiceCancelSingleHtlc(t *testing.T) {
},
}, nil
})
if err != nil {
t.Fatalf("unable to cancel htlc: %v", err)
}
require.NoError(t, err, "unable to cancel htlc")
if len(invoice.Htlcs) != 1 {
t.Fatalf("expected the htlc to be present")
}
@@ -571,9 +555,7 @@ func TestInvoiceCancelSingleHtlcAMP(t *testing.T) {
SetID: (*SetID)(setID1),
}, nil
})
if err != nil {
t.Fatalf("unable to cancel htlc: %v", err)
}
require.NoError(t, err, "unable to cancel htlc")
freshInvoice, err := db.LookupInvoice(ref)
require.Nil(t, err)
@@ -623,9 +605,7 @@ func TestInvoiceCancelSingleHtlcAMP(t *testing.T) {
SetID: (*SetID)(setID2),
}, nil
})
if err != nil {
t.Fatalf("unable to cancel htlc: %v", err)
}
require.NoError(t, err, "unable to cancel htlc")
freshInvoice, err = db.LookupInvoice(ref)
require.Nil(t, err)
@@ -653,9 +633,7 @@ func TestInvoiceCancelSingleHtlcAMP(t *testing.T) {
SetID: (*SetID)(setID2),
}, nil
})
if err != nil {
t.Fatalf("unable to cancel htlc: %v", err)
}
require.NoError(t, err, "unable to cancel htlc")
freshInvoice, err = db.LookupInvoice(ref)
require.Nil(t, err)
@@ -680,9 +658,7 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
_, err = db.InvoicesAddedSince(0)
require.NoError(t, err)
@@ -995,9 +971,7 @@ func TestScanInvoices(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
var invoices map[lntypes.Hash]*Invoice
callCount := 0
@@ -1056,16 +1030,12 @@ func TestDuplicateSettleInvoice(t *testing.T) {
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
// We'll start out by creating an invoice and writing it to the DB.
amt := lnwire.NewMSatFromSatoshis(1000)
invoice, err := randInvoice(amt)
if err != nil {
t.Fatalf("unable to create invoice: %v", err)
}
require.NoError(t, err, "unable to create invoice")
payHash := invoice.Terms.PaymentPreimage.Hash()
@@ -1076,9 +1046,7 @@ func TestDuplicateSettleInvoice(t *testing.T) {
// With the invoice in the DB, we'll now attempt to settle the invoice.
ref := InvoiceRefByHash(payHash)
dbInvoice, err := db.UpdateInvoice(ref, nil, getUpdateInvoice(amt))
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
require.NoError(t, err, "unable to settle invoice")
// We'll update what we expect the settle invoice to be so that our
// comparison below has the correct assumption.
@@ -1121,9 +1089,7 @@ func TestQueryInvoices(t *testing.T) {
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
// To begin the test, we'll add 50 invoices to the database. We'll
// assume that the index of the invoice within the database is the same
@@ -1436,9 +1402,7 @@ func TestCustomRecords(t *testing.T) {
db, cleanUp, err := MakeTestDB()
defer cleanUp()
if err != nil {
t.Fatalf("unable to make test db: %v", err)
}
require.NoError(t, err, "unable to make test db")
preimage := lntypes.Preimage{1}
paymentHash := preimage.Hash()
@@ -1477,16 +1441,12 @@ func TestCustomRecords(t *testing.T) {
}, nil
},
)
if err != nil {
t.Fatalf("unable to add invoice htlc: %v", err)
}
require.NoError(t, err, "unable to add invoice htlc")
// Retrieve the invoice from that database and verify that the custom
// records are present.
dbInvoice, err := db.LookupInvoice(ref)
if err != nil {
t.Fatalf("unable to lookup invoice: %v", err)
}
require.NoError(t, err, "unable to lookup invoice")
if len(dbInvoice.Htlcs) != 1 {
t.Fatalf("expected the htlc to be added")
+5 -12
View File
@@ -8,6 +8,7 @@ import (
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/stretchr/testify/require"
)
// applyMigration is a helper test function that encapsulates the general steps
@@ -425,14 +426,10 @@ func TestMigrationReversion(t *testing.T) {
defer func() {
os.RemoveAll(tempDirName)
}()
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
require.NoError(t, err, "unable to create temp dir")
backend, cleanup, err := kvdb.GetTestBackend(tempDirName, "cdb")
if err != nil {
t.Fatalf("unable to get test db backend: %v", err)
}
require.NoError(t, err, "unable to get test db backend")
cdb, err := CreateWithBackend(backend)
if err != nil {
@@ -454,14 +451,10 @@ func TestMigrationReversion(t *testing.T) {
cdb.Close()
cleanup()
if err != nil {
t.Fatalf("unable to increase db version: %v", err)
}
require.NoError(t, err, "unable to increase db version")
backend, cleanup, err = kvdb.GetTestBackend(tempDirName, "cdb")
if err != nil {
t.Fatalf("unable to get test db backend: %v", err)
}
require.NoError(t, err, "unable to get test db backend")
defer cleanup()
_, err = CreateWithBackend(backend)
+7 -18
View File
@@ -8,15 +8,14 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/stretchr/testify/require"
)
func TestLinkNodeEncodeDecode(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
@@ -26,13 +25,9 @@ func TestLinkNodeEncodeDecode(t *testing.T) {
_, pub1 := btcec.PrivKeyFromBytes(key[:])
_, pub2 := btcec.PrivKeyFromBytes(rev[:])
addr1, err := net.ResolveTCPAddr("tcp", "10.0.0.1:9000")
if err != nil {
t.Fatalf("unable to create test addr: %v", err)
}
require.NoError(t, err, "unable to create test addr")
addr2, err := net.ResolveTCPAddr("tcp", "10.0.0.2:9000")
if err != nil {
t.Fatalf("unable to create test addr: %v", err)
}
require.NoError(t, err, "unable to create test addr")
// Create two fresh link node instances with the above dummy data, then
// fully sync both instances to disk.
@@ -49,9 +44,7 @@ func TestLinkNodeEncodeDecode(t *testing.T) {
// match the two created above.
originalNodes := []*LinkNode{node2, node1}
linkNodes, err := cdb.linkNodeDB.FetchAllLinkNodes()
if err != nil {
t.Fatalf("unable to fetch nodes: %v", err)
}
require.NoError(t, err, "unable to fetch nodes")
for i, node := range linkNodes {
if originalNodes[i].Network != node.Network {
t.Fatalf("node networks don't match: expected %v, got %v",
@@ -85,9 +78,7 @@ func TestLinkNodeEncodeDecode(t *testing.T) {
// Fetch the same node from the database according to its public key.
node1DB, err := cdb.linkNodeDB.FetchLinkNode(pub1)
if err != nil {
t.Fatalf("unable to find node: %v", err)
}
require.NoError(t, err, "unable to find node")
// Both the last seen timestamp and the list of reachable addresses for
// the node should be updated.
@@ -113,9 +104,7 @@ func TestDeleteLinkNode(t *testing.T) {
t.Parallel()
fullDB, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
cdb := fullDB.ChannelStateDB()
+25 -75
View File
@@ -56,22 +56,16 @@ func TestPaymentControlSwitchFail(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewPaymentControl(db)
info, attempt, preimg, err := genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
// Sends base htlc message which initiate StatusInFlight.
err = pControl.InitPayment(info.PaymentIdentifier, info)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
@@ -82,9 +76,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
// Fail the payment, which should moved it to Failed.
failReason := FailureReasonNoRoute
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
if err != nil {
t.Fatalf("unable to fail payment hash: %v", err)
}
require.NoError(t, err, "unable to fail payment hash")
// Verify the status is indeed Failed.
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusFailed)
@@ -100,9 +92,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
// Sends the htlc again, which should succeed since the prior payment
// failed.
err = pControl.InitPayment(info.PaymentIdentifier, info)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
// Check that our index has been updated, and the old index has been
// removed.
@@ -118,9 +108,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
// However, this is not communicated to control tower in the current
// implementation. It only registers the initiation of the attempt.
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
if err != nil {
t.Fatalf("unable to register attempt: %v", err)
}
require.NoError(t, err, "unable to register attempt")
htlcReason := HTLCFailUnreadable
_, err = pControl.FailAttempt(
@@ -144,9 +132,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
// Record another attempt.
attempt.AttemptID = 1
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
htlc = &htlcStatus{
@@ -165,9 +151,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
Preimage: preimg,
},
)
if err != nil {
t.Fatalf("error shouldn't have been received, got: %v", err)
}
require.NoError(t, err, "error shouldn't have been received, got")
if len(payment.HTLCs) != 2 {
t.Fatalf("payment should have two htlcs, got: %d",
@@ -204,23 +188,17 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewPaymentControl(db)
info, attempt, preimg, err := genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
// Sends base htlc message which initiate base status and move it to
// StatusInFlight and verifies that it was changed.
err = pControl.InitPayment(info.PaymentIdentifier, info)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
@@ -239,9 +217,7 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
// Record an attempt.
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
htlc := &htlcStatus{
@@ -265,9 +241,7 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
Preimage: preimg,
},
)
if err != nil {
t.Fatalf("error shouldn't have been received, got: %v", err)
}
require.NoError(t, err, "error shouldn't have been received, got")
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusSucceeded)
htlc.settle = &preimg
@@ -287,16 +261,12 @@ func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewPaymentControl(db)
info, _, preimg, err := genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
// Attempt to complete the payment should fail.
_, err = pControl.SettleAttempt(
@@ -320,16 +290,12 @@ func TestPaymentControlFailsWithoutInFlight(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewPaymentControl(db)
info, _, _, err := genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
// Calling Fail should return an error.
_, err = pControl.Fail(info.PaymentIdentifier, FailureReasonNoRoute)
@@ -348,9 +314,7 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
// Create a sequence number for duplicate payments that will not collide
// with the sequence numbers for the payments we create. These values
@@ -963,22 +927,16 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
db, cleanup, err := MakeTestDB()
defer cleanup()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewPaymentControl(db)
info, attempt, _, err := genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
// Init the payment.
err = pControl.InitPayment(info.PaymentIdentifier, info)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
// Create three unique attempts we'll use for the test, and
// register them with the payment control. We set each
@@ -991,9 +949,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
)
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
// Now try to register a non-MPP attempt, which should fail.
b := *attempt
@@ -1025,20 +981,14 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
// Create and init a new payment. This time we'll check that we cannot
// register an MPP attempt if we already registered a non-MPP one.
info, attempt, _, err = genInfo()
if err != nil {
t.Fatalf("unable to generate htlc message: %v", err)
}
require.NoError(t, err, "unable to generate htlc message")
err = pControl.InitPayment(info.PaymentIdentifier, info)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
attempt.Route.FinalHop().MPP = nil
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
if err != nil {
t.Fatalf("unable to send htlc message: %v", err)
}
require.NoError(t, err, "unable to send htlc message")
// Attempt to register an MPP attempt, which should fail.
b = *attempt
+3 -9
View File
@@ -87,9 +87,7 @@ func TestSentPaymentSerialization(t *testing.T) {
}
newCreationInfo, err := deserializePaymentCreationInfo(&b)
if err != nil {
t.Fatalf("unable to deserialize creation info: %v", err)
}
require.NoError(t, err, "unable to deserialize creation info")
if !reflect.DeepEqual(c, newCreationInfo) {
t.Fatalf("Payments do not match after "+
@@ -104,9 +102,7 @@ func TestSentPaymentSerialization(t *testing.T) {
}
newWireInfo, err := deserializeHTLCAttemptInfo(&b)
if err != nil {
t.Fatalf("unable to deserialize info: %v", err)
}
require.NoError(t, err, "unable to deserialize info")
newWireInfo.AttemptID = s.AttemptID
// First we verify all the records match up porperly, as they aren't
@@ -673,9 +669,7 @@ func appendDuplicatePayment(t *testing.T, db *DB, paymentHash lntypes.Hash,
return nil
}, func() {})
if err != nil {
t.Fatalf("could not create payment: %v", err)
}
require.NoError(t, err, "could not create payment")
}
// putDuplicatePayment creates a duplicate payment in the duplicates bucket
+3 -6
View File
@@ -7,6 +7,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
// TestWaitingProofStore tests add/get/remove functions of the waiting proof
@@ -15,9 +16,7 @@ func TestWaitingProofStore(t *testing.T) {
t.Parallel()
db, cleanup, err := MakeTestDB()
if err != nil {
t.Fatalf("failed to make test database: %s", err)
}
require.NoError(t, err, "failed to make test database")
defer cleanup()
proof1 := NewWaitingProof(true, &lnwire.AnnounceSignatures{
@@ -37,9 +36,7 @@ func TestWaitingProofStore(t *testing.T) {
}
proof2, err := store.Get(proof1.Key())
if err != nil {
t.Fatalf("unable retrieve proof from storage: %v", err)
}
require.NoError(t, err, "unable retrieve proof from storage")
if !reflect.DeepEqual(proof1, proof2) {
t.Fatalf("wrong proof retrieved: expected %v, got %v",
spew.Sdump(proof1), spew.Sdump(proof2))
+9 -24
View File
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
)
// TestWitnessCacheSha256Retrieval tests that we're able to add and lookup new
@@ -13,9 +14,7 @@ func TestWitnessCacheSha256Retrieval(t *testing.T) {
t.Parallel()
cdb, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
wCache := cdb.NewWitnessCache()
@@ -30,9 +29,7 @@ func TestWitnessCacheSha256Retrieval(t *testing.T) {
// First, we'll attempt to add the preimages to the database.
err = wCache.AddSha256Witnesses(preimages...)
if err != nil {
t.Fatalf("unable to add witness: %v", err)
}
require.NoError(t, err, "unable to add witness")
// With the preimages stored, we'll now attempt to look them up.
for i, hash := range hashes {
@@ -58,9 +55,7 @@ func TestWitnessCacheSha256Deletion(t *testing.T) {
t.Parallel()
cdb, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
wCache := cdb.NewWitnessCache()
@@ -83,9 +78,7 @@ func TestWitnessCacheSha256Deletion(t *testing.T) {
// We'll now delete the first preimage. If we attempt to look it up, we
// should get ErrNoWitnesses.
err = wCache.DeleteSha256Witness(hash1)
if err != nil {
t.Fatalf("unable to delete witness: %v", err)
}
require.NoError(t, err, "unable to delete witness")
_, err = wCache.LookupSha256Witness(hash1)
if err != ErrNoWitnesses {
t.Fatalf("expected ErrNoWitnesses instead got: %v", err)
@@ -109,9 +102,7 @@ func TestWitnessCacheUnknownWitness(t *testing.T) {
t.Parallel()
cdb, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
wCache := cdb.NewWitnessCache()
@@ -128,9 +119,7 @@ func TestWitnessCacheUnknownWitness(t *testing.T) {
// identically to the insertion via the generalized interface.
func TestAddSha256Witnesses(t *testing.T) {
cdb, cleanUp, err := MakeTestDB()
if err != nil {
t.Fatalf("unable to make test database: %v", err)
}
require.NoError(t, err, "unable to make test database")
defer cleanUp()
wCache := cdb.NewWitnessCache()
@@ -152,9 +141,7 @@ func TestAddSha256Witnesses(t *testing.T) {
)
err = wCache.legacyAddWitnesses(Sha256HashWitness, witnesses...)
if err != nil {
t.Fatalf("unable to add witness: %v", err)
}
require.NoError(t, err, "unable to add witness")
for i, hash := range hashes {
preimage := preimages[i]
@@ -181,9 +168,7 @@ func TestAddSha256Witnesses(t *testing.T) {
// Now, add the same witnesses using the type-safe interface for
// lntypes.Preimages..
err = wCache.AddSha256Witnesses(preimages...)
if err != nil {
t.Fatalf("unable to add sha256 preimage: %v", err)
}
require.NoError(t, err, "unable to add sha256 preimage")
// Finally, iterate over the keys and assert that the returned witnesses
// match the original witnesses. This asserts that the specialized