multi: move many t.Fatalf calls to require.NoError
This commit is contained in:
1 parent
9e6f0ef46b
commit
9a10c80bcb
92 files changed
+1905
-5565
No files matched your search
+22
-63
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -126,9 +127,7 @@ func newCircuitMap(t *testing.T, resMsg bool) (*htlcswitch.CircuitMapConfig,
|
||||
}
|
||||
|
||||
circuitMap, err := htlcswitch.NewCircuitMap(circuitMapCfg)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create persistent circuit map: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create persistent circuit map")
|
||||
|
||||
return circuitMapCfg, circuitMap
|
||||
}
|
||||
@@ -489,9 +488,7 @@ func TestCircuitMapPersistence(t *testing.T) {
|
||||
|
||||
// Test removing circuits and the subsequent lookups.
|
||||
err = circuitMap.DeleteCircuits(circuit1.Incoming)
|
||||
if err != nil {
|
||||
t.Fatalf("Remove returned unexpected error: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Remove returned unexpected error")
|
||||
|
||||
// There should be exactly one remaining circuit with hash1, and it
|
||||
// should be circuit4.
|
||||
@@ -514,9 +511,7 @@ func TestCircuitMapPersistence(t *testing.T) {
|
||||
|
||||
// Remove last remaining circuit with payment hash hash1.
|
||||
err = circuitMap.DeleteCircuits(circuit4.Incoming)
|
||||
if err != nil {
|
||||
t.Fatalf("Remove returned unexpected error: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Remove returned unexpected error")
|
||||
|
||||
assertNumCircuitsWithHash(t, circuitMap, hash1, 0)
|
||||
assertNumCircuitsWithHash(t, circuitMap, hash2, 1)
|
||||
@@ -528,9 +523,7 @@ func TestCircuitMapPersistence(t *testing.T) {
|
||||
|
||||
// Remove last remaining circuit with payment hash hash2.
|
||||
err = circuitMap.DeleteCircuits(circuit2.Incoming)
|
||||
if err != nil {
|
||||
t.Fatalf("Remove returned unexpected error: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Remove returned unexpected error")
|
||||
|
||||
// There should now only be one remaining circuit, with hash3.
|
||||
assertNumCircuitsWithHash(t, circuitMap, hash2, 0)
|
||||
@@ -639,9 +632,7 @@ func makeCircuitDB(t *testing.T, path string) *channeldb.DB {
|
||||
}
|
||||
|
||||
db, err := channeldb.Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channel db: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channel db")
|
||||
|
||||
return db
|
||||
}
|
||||
@@ -666,9 +657,7 @@ func restartCircuitMap(t *testing.T, cfg *htlcswitch.CircuitMapConfig) (
|
||||
CheckResolutionMsg: cfg.CheckResolutionMsg,
|
||||
}
|
||||
cm2, err := htlcswitch.NewCircuitMap(cfg2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to recreate persistent circuit map: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to recreate persistent circuit map")
|
||||
|
||||
return cfg2, cm2
|
||||
}
|
||||
@@ -699,9 +688,7 @@ func TestCircuitMapCommitCircuits(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
actions, err := circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
if len(actions.Drops) > 0 {
|
||||
t.Fatalf("new circuit should not have been dropped")
|
||||
}
|
||||
@@ -723,9 +710,7 @@ func TestCircuitMapCommitCircuits(t *testing.T) {
|
||||
// in the circuit being dropped. This can happen if the incoming link
|
||||
// flaps.
|
||||
actions, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
if len(actions.Adds) > 0 {
|
||||
t.Fatalf("duplicate circuit should not have been added to circuit map")
|
||||
}
|
||||
@@ -744,9 +729,7 @@ func TestCircuitMapCommitCircuits(t *testing.T) {
|
||||
_, circuitMap = restartCircuitMap(t, cfg)
|
||||
|
||||
actions, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
if len(actions.Adds) > 0 {
|
||||
t.Fatalf("duplicate circuit with incomplete forwarding " +
|
||||
"decision should not have been added to circuit map")
|
||||
@@ -795,9 +778,7 @@ func TestCircuitMapOpenCircuits(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
keystone := htlcswitch.Keystone{
|
||||
InKey: circuit.Incoming,
|
||||
@@ -809,9 +790,7 @@ func TestCircuitMapOpenCircuits(t *testing.T) {
|
||||
|
||||
// Open the circuit for the first time.
|
||||
err = circuitMap.OpenCircuits(keystone)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to open circuits")
|
||||
|
||||
// Check that we can retrieve the open circuit if the circuit map before
|
||||
// the circuit map is restarted.
|
||||
@@ -841,9 +820,7 @@ func TestCircuitMapOpenCircuits(t *testing.T) {
|
||||
// flaps OR the switch is entirely restarted and the outgoing link has
|
||||
// not received a response.
|
||||
actions, err := circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
if len(actions.Adds) > 0 {
|
||||
t.Fatalf("duplicate circuit should not have been added to circuit map")
|
||||
}
|
||||
@@ -882,9 +859,7 @@ func TestCircuitMapOpenCircuits(t *testing.T) {
|
||||
// if the incoming link flaps OR the switch is entirely restarted and
|
||||
// the outgoing link has not received a response.
|
||||
actions, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
if len(actions.Adds) > 0 {
|
||||
t.Fatalf("duplicate circuit should not have been added to circuit map")
|
||||
}
|
||||
@@ -1012,9 +987,7 @@ func TestCircuitMapTrimOpenCircuits(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuits...)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
// Now create a list of the keystones that we will use to preemptively
|
||||
// open the circuits. We set the index as the outgoing HtlcID to i
|
||||
@@ -1032,9 +1005,7 @@ func TestCircuitMapTrimOpenCircuits(t *testing.T) {
|
||||
|
||||
// Open the circuits for the first time.
|
||||
err = circuitMap.OpenCircuits(keystones...)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to open circuits")
|
||||
|
||||
// Check that all circuits are marked open.
|
||||
assertCircuitsOpenedPreRestart(t, circuitMap, circuits, keystones)
|
||||
@@ -1152,9 +1123,7 @@ func TestCircuitMapCloseOpenCircuits(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
keystone := htlcswitch.Keystone{
|
||||
InKey: circuit.Incoming,
|
||||
@@ -1166,9 +1135,7 @@ func TestCircuitMapCloseOpenCircuits(t *testing.T) {
|
||||
|
||||
// Open the circuit for the first time.
|
||||
err = circuitMap.OpenCircuits(keystone)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to open circuits")
|
||||
|
||||
// Check that we can retrieve the open circuit if the circuit map before
|
||||
// the circuit map is restarted.
|
||||
@@ -1243,9 +1210,7 @@ func TestCircuitMapCloseUnopenedCircuit(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
// Close the open circuit for the first time, which should succeed.
|
||||
_, err = circuitMap.FailCircuit(circuit.Incoming)
|
||||
@@ -1300,9 +1265,7 @@ func TestCircuitMapDeleteUnopenedCircuit(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
// Close the open circuit for the first time, which should succeed.
|
||||
_, err = circuitMap.FailCircuit(circuit.Incoming)
|
||||
@@ -1359,9 +1322,7 @@ func TestCircuitMapDeleteOpenCircuit(t *testing.T) {
|
||||
// First we will try to add an new circuit to the circuit map, this
|
||||
// should succeed.
|
||||
_, err = circuitMap.CommitCircuits(circuit)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to commit circuits")
|
||||
|
||||
keystone := htlcswitch.Keystone{
|
||||
InKey: circuit.Incoming,
|
||||
@@ -1373,9 +1334,7 @@ func TestCircuitMapDeleteOpenCircuit(t *testing.T) {
|
||||
|
||||
// Open the circuit for the first time.
|
||||
err = circuitMap.OpenCircuits(keystone)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open circuits: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to open circuits")
|
||||
|
||||
// Close the open circuit for the first time, which should succeed.
|
||||
_, err = circuitMap.FailCircuit(circuit.Incoming)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,9 +23,7 @@ const (
|
||||
// decayed log instance.
|
||||
func tempDecayedLogPath(t *testing.T) string {
|
||||
dir, err := ioutil.TempDir("", "decayedlog")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temporary decayed log dir: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temporary decayed log dir")
|
||||
|
||||
return dir
|
||||
}
|
||||
@@ -99,16 +98,12 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
|
||||
dbPath := tempDecayedLogPath(t)
|
||||
|
||||
d, notifier, hashedSecret, _, err := startup(dbPath, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to start up DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to start up DecayedLog")
|
||||
defer shutdown(dbPath, d)
|
||||
|
||||
// Store <hashedSecret, cltv> in the sharedHashBucket.
|
||||
err = d.Put(hashedSecret, cltv)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to store in channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to store in channeldb")
|
||||
|
||||
// Wait for database write (GC is in a goroutine)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
@@ -123,9 +118,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
|
||||
|
||||
// Assert that hashedSecret is still in the sharedHashBucket
|
||||
val, err := d.Get(hashedSecret)
|
||||
if err != nil {
|
||||
t.Fatalf("Get failed - received an error upon Get: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Get failed - received an error upon Get")
|
||||
|
||||
if val != cltv {
|
||||
t.Fatalf("GC incorrectly deleted CLTV")
|
||||
@@ -160,9 +153,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
|
||||
dbPath := tempDecayedLogPath(t)
|
||||
|
||||
d, _, hashedSecret, stop, err := startup(dbPath, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to start up DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to start up DecayedLog")
|
||||
defer shutdown(dbPath, d)
|
||||
|
||||
// Store <hashedSecret, cltv> in the sharedHashBucket
|
||||
@@ -180,9 +171,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
|
||||
stop()
|
||||
|
||||
d2, notifier2, _, _, err := startup(dbPath, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to restart DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to restart DecayedLog")
|
||||
defer shutdown(dbPath, d2)
|
||||
|
||||
// Check that the hash prefix still exists in the new db instance.
|
||||
@@ -216,22 +205,16 @@ func TestDecayedLogInsertionAndDeletion(t *testing.T) {
|
||||
dbPath := tempDecayedLogPath(t)
|
||||
|
||||
d, _, hashedSecret, _, err := startup(dbPath, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to start up DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to start up DecayedLog")
|
||||
defer shutdown(dbPath, d)
|
||||
|
||||
// Store <hashedSecret, cltv> in the sharedHashBucket.
|
||||
err = d.Put(hashedSecret, cltv)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to store in channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to store in channeldb")
|
||||
|
||||
// Delete hashedSecret from the sharedHashBucket.
|
||||
err = d.Delete(hashedSecret)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to delete from channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to delete from channeldb")
|
||||
|
||||
// Assert that hashedSecret is not in the sharedHashBucket
|
||||
_, err = d.Get(hashedSecret)
|
||||
@@ -254,31 +237,23 @@ func TestDecayedLogStartAndStop(t *testing.T) {
|
||||
dbPath := tempDecayedLogPath(t)
|
||||
|
||||
d, _, hashedSecret, stop, err := startup(dbPath, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to start up DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to start up DecayedLog")
|
||||
defer shutdown(dbPath, d)
|
||||
|
||||
// Store <hashedSecret, cltv> in the sharedHashBucket.
|
||||
err = d.Put(hashedSecret, cltv)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to store in channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to store in channeldb")
|
||||
|
||||
// Shutdown the DecayedLog's channeldb
|
||||
stop()
|
||||
|
||||
d2, _, hashedSecret2, stop, err := startup(dbPath, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to restart DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to restart DecayedLog")
|
||||
defer shutdown(dbPath, d2)
|
||||
|
||||
// Retrieve the stored cltv value given the hashedSecret key.
|
||||
value, err := d2.Get(hashedSecret)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to retrieve from channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to retrieve from channeldb")
|
||||
|
||||
// Check that the original cltv value matches the retrieved cltv
|
||||
// value.
|
||||
@@ -288,17 +263,13 @@ func TestDecayedLogStartAndStop(t *testing.T) {
|
||||
|
||||
// Delete hashedSecret from sharedHashBucket
|
||||
err = d2.Delete(hashedSecret2)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to delete from channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to delete from channeldb")
|
||||
|
||||
// Shutdown the DecayedLog's channeldb
|
||||
stop()
|
||||
|
||||
d3, _, hashedSecret3, _, err := startup(dbPath, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to restart DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to restart DecayedLog")
|
||||
defer shutdown(dbPath, d3)
|
||||
|
||||
// Assert that hashedSecret is not in the sharedHashBucket
|
||||
@@ -320,22 +291,16 @@ func TestDecayedLogStorageAndRetrieval(t *testing.T) {
|
||||
dbPath := tempDecayedLogPath(t)
|
||||
|
||||
d, _, hashedSecret, _, err := startup(dbPath, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to start up DecayedLog: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to start up DecayedLog")
|
||||
defer shutdown(dbPath, d)
|
||||
|
||||
// Store <hashedSecret, cltv> in the sharedHashBucket
|
||||
err = d.Put(hashedSecret, cltv)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to store in channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to store in channeldb")
|
||||
|
||||
// Retrieve the stored cltv value given the hashedSecret key.
|
||||
value, err := d.Get(hashedSecret)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to retrieve from channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to retrieve from channeldb")
|
||||
|
||||
// If the original cltv value does not match the value retrieved,
|
||||
// then the test failed.
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestSphinxHopIteratorForwardingInstructions tests that we're able to
|
||||
@@ -44,9 +45,7 @@ func TestSphinxHopIteratorForwardingInstructions(t *testing.T) {
|
||||
record.NewNextHopIDRecord(&nextAddrInt),
|
||||
}
|
||||
tlvStream, err := tlv.NewStream(tlvRecords...)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create stream: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create stream")
|
||||
if err := tlvStream.Encode(&b); err != nil {
|
||||
t.Fatalf("unable to encode stream: %v", err)
|
||||
}
|
||||
|
||||
+115
-345
File diff suppressed because it is too large.
Load diff
@@ -122,13 +122,9 @@ func TestMailBoxCouriers(t *testing.T) {
|
||||
// With the packets drained and partially acked, we reset the mailbox,
|
||||
// simulating a link shutting down and then coming back up.
|
||||
err := ctx.mailbox.ResetMessages()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reset messages: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reset messages")
|
||||
err = ctx.mailbox.ResetPackets()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reset packets: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reset packets")
|
||||
|
||||
// Now, we'll use the same alternating strategy to read from our
|
||||
// mailbox. All wire messages are dropped on startup, but any unacked
|
||||
@@ -348,9 +344,7 @@ func TestMailBoxFailAdd(t *testing.T) {
|
||||
// the link flapping and coming back up before the second batch's
|
||||
// expiries have elapsed. We should see no failures sent back.
|
||||
err := ctx.mailbox.ResetPackets()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reset packets: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reset packets")
|
||||
ctx.checkFails(nil)
|
||||
|
||||
// Redeliver the second batch to the link and hold them there.
|
||||
@@ -369,9 +363,7 @@ func TestMailBoxFailAdd(t *testing.T) {
|
||||
// Finally, reset the link which should cause the second batch to be
|
||||
// cancelled immediately.
|
||||
err = ctx.mailbox.ResetPackets()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reset packets: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reset packets")
|
||||
ctx.checkFails(secondBatch)
|
||||
}
|
||||
|
||||
|
||||
@@ -155,9 +155,7 @@ func TestNetworkResultStore(t *testing.T) {
|
||||
// Let the third one subscribe now. THe result should be received
|
||||
// immediately.
|
||||
sub, err := store.subscribeResult(2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to subscribe: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to subscribe")
|
||||
select {
|
||||
case <-sub:
|
||||
case <-time.After(1 * time.Second):
|
||||
@@ -173,14 +171,10 @@ func TestNetworkResultStore(t *testing.T) {
|
||||
|
||||
// Add the result and try again.
|
||||
err = store.storeResult(3, results[3])
|
||||
if err != nil {
|
||||
t.Fatalf("unable to store result: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to store result")
|
||||
|
||||
_, err = store.getResult(3)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get result: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get result")
|
||||
|
||||
// Since we don't delete results from the store (yet), make sure we
|
||||
// will get subscriptions for all of them.
|
||||
|
||||
+91
-273
@@ -44,14 +44,10 @@ func TestSwitchAddDuplicateLink(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -76,9 +72,7 @@ func TestSwitchAddDuplicateLink(t *testing.T) {
|
||||
// Update the short chan id of the channel, so that the link goes live.
|
||||
aliceChannelLink.setLiveShortChanID(aliceChanID)
|
||||
err = s.UpdateShortChanID(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update alice short_chan_id: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update alice short_chan_id")
|
||||
|
||||
// Alice should have a live link, adding again should fail.
|
||||
if err := s.AddLink(aliceChannelLink); err == nil {
|
||||
@@ -104,14 +98,10 @@ func TestSwitchHasActiveLink(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -138,9 +128,7 @@ func TestSwitchHasActiveLink(t *testing.T) {
|
||||
// Update the short chan id of the channel, so that the link goes live.
|
||||
aliceChannelLink.setLiveShortChanID(aliceChanID)
|
||||
err = s.UpdateShortChanID(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update alice short_chan_id: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update alice short_chan_id")
|
||||
|
||||
// UpdateShortChanID will cause the mock link to become eligible to
|
||||
// forward. However, we can simulate the event where the short chan id
|
||||
@@ -174,21 +162,15 @@ func TestSwitchSendPending(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -215,9 +197,7 @@ func TestSwitchSendPending(t *testing.T) {
|
||||
// Create request which should is being forwarded from Bob channel
|
||||
// link to Alice channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
packet := &htlcPacket{
|
||||
incomingChanID: bobChanID,
|
||||
@@ -269,9 +249,7 @@ func TestSwitchSendPending(t *testing.T) {
|
||||
// move the link to the live state.
|
||||
aliceChannelLink.setLiveShortChanID(aliceChanID)
|
||||
err = s.UpdateShortChanID(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update alice short_chan_id: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update alice short_chan_id")
|
||||
|
||||
// Increment the packet's HTLC index, so that it does not collide with
|
||||
// the prior attempt.
|
||||
@@ -298,20 +276,14 @@ func TestSwitchForward(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -335,9 +307,7 @@ func TestSwitchForward(t *testing.T) {
|
||||
// Create request which should be forwarded from Alice channel link to
|
||||
// bob channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
packet := &htlcPacket{
|
||||
incomingChanID: aliceChannelLink.ShortChanID(),
|
||||
@@ -411,30 +381,20 @@ func TestSwitchForwardFailAfterFullAdd(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -522,14 +482,10 @@ func TestSwitchForwardFailAfterFullAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb2, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s2.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -610,30 +566,20 @@ func TestSwitchForwardSettleAfterFullAdd(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -721,14 +667,10 @@ func TestSwitchForwardSettleAfterFullAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb2, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s2.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -812,30 +754,20 @@ func TestSwitchForwardDropAfterFullAdd(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -915,14 +847,10 @@ func TestSwitchForwardDropAfterFullAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb2, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s2.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -977,30 +905,20 @@ func TestSwitchForwardFailAfterHalfAdd(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1075,14 +993,10 @@ func TestSwitchForwardFailAfterHalfAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb2, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s2.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -1143,30 +1057,20 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1240,14 +1144,10 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb2, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s2.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -1333,14 +1233,10 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
|
||||
}
|
||||
|
||||
cdb3, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to reopen channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to reopen channeldb")
|
||||
|
||||
s3, err := initSwitchWithDB(testStartingHeight, cdb3)
|
||||
if err != nil {
|
||||
t.Fatalf("unable reinit switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable reinit switch")
|
||||
if err := s3.Start(); err != nil {
|
||||
t.Fatalf("unable to restart switch: %v", err)
|
||||
}
|
||||
@@ -1617,20 +1513,14 @@ func testSkipIneligibleLinksMultiHopForward(t *testing.T,
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1747,14 +1637,10 @@ func testSkipLinkLocalForward(t *testing.T, eligible bool,
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1773,9 +1659,7 @@ func testSkipLinkLocalForward(t *testing.T, eligible bool,
|
||||
}
|
||||
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
addMsg := &lnwire.UpdateAddHTLC{
|
||||
PaymentHash: rhash,
|
||||
@@ -1803,20 +1687,14 @@ func TestSwitchCancel(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1840,9 +1718,7 @@ func TestSwitchCancel(t *testing.T) {
|
||||
// Create request which should be forwarder from alice channel link
|
||||
// to bob channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
request := &htlcPacket{
|
||||
incomingChanID: aliceChannelLink.ShortChanID(),
|
||||
@@ -1920,20 +1796,14 @@ func TestSwitchAddSamePayment(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -1955,9 +1825,7 @@ func TestSwitchAddSamePayment(t *testing.T) {
|
||||
// Create request which should be forwarder from alice channel link
|
||||
// to bob channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
request := &htlcPacket{
|
||||
incomingChanID: aliceChannelLink.ShortChanID(),
|
||||
@@ -2083,14 +1951,10 @@ func TestSwitchSendPayment(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -2108,9 +1972,7 @@ func TestSwitchSendPayment(t *testing.T) {
|
||||
// Create request which should be forwarder from alice channel link
|
||||
// to bob channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
update := &lnwire.UpdateAddHTLC{
|
||||
PaymentHash: rhash,
|
||||
@@ -2183,9 +2045,7 @@ func TestSwitchSendPayment(t *testing.T) {
|
||||
obfuscator := NewMockObfuscator()
|
||||
failure := lnwire.NewFailIncorrectDetails(update.Amount, 100)
|
||||
reason, err := obfuscator.EncryptFirstHop(failure)
|
||||
if err != nil {
|
||||
t.Fatalf("unable obfuscate failure: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable obfuscate failure")
|
||||
|
||||
if s.IsForwardedHTLC(aliceChannelLink.ShortChanID(), update.ID) {
|
||||
t.Fatal("htlc should be identified as not forwarded")
|
||||
@@ -2224,9 +2084,7 @@ func TestLocalPaymentNoForwardingEvents(t *testing.T) {
|
||||
channels, cleanUp, _, err := createClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create channel")
|
||||
defer cleanUp()
|
||||
|
||||
n := newThreeHopNetwork(t, channels.aliceToBob, channels.bobToAlice,
|
||||
@@ -2250,9 +2108,7 @@ func TestLocalPaymentNoForwardingEvents(t *testing.T) {
|
||||
n.aliceServer, receiver, firstHop, hops, amount, htlcAmt,
|
||||
totalTimelock,
|
||||
).Wait(30 * time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make the payment: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to make the payment")
|
||||
|
||||
// At this point, we'll forcibly stop the three hop network. Doing
|
||||
// this will cause any pending forwarding events to be flushed by the
|
||||
@@ -2286,9 +2142,7 @@ func TestMultiHopPaymentForwardingEvents(t *testing.T) {
|
||||
channels, cleanUp, _, err := createClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create channel")
|
||||
defer cleanUp()
|
||||
|
||||
n := newThreeHopNetwork(t, channels.aliceToBob, channels.bobToAlice,
|
||||
@@ -2443,9 +2297,7 @@ func TestUpdateFailMalformedHTLCErrorConversion(t *testing.T) {
|
||||
channels, cleanUp, _, err := createClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3, btcutil.SatoshiPerBitcoin*5,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create channel")
|
||||
defer cleanUp()
|
||||
|
||||
n := newThreeHopNetwork(
|
||||
@@ -2518,9 +2370,7 @@ func TestSwitchGetPaymentResult(t *testing.T) {
|
||||
preimg[0] = 3
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -2549,9 +2399,7 @@ func TestSwitchGetPaymentResult(t *testing.T) {
|
||||
resultChan, err := s.GetPaymentResult(
|
||||
paymentID, lntypes.Hash{}, newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get payment result: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get payment result")
|
||||
|
||||
// Add the result to the store.
|
||||
n := &networkResult{
|
||||
@@ -2563,9 +2411,7 @@ func TestSwitchGetPaymentResult(t *testing.T) {
|
||||
}
|
||||
|
||||
err = s.networkResults.storeResult(paymentID, n)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to store result: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to store result")
|
||||
|
||||
// The result should be available.
|
||||
select {
|
||||
@@ -2594,9 +2440,7 @@ func TestSwitchGetPaymentResult(t *testing.T) {
|
||||
resultChan, err = s.GetPaymentResult(
|
||||
paymentID, lntypes.Hash{}, newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get payment result: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get payment result")
|
||||
|
||||
select {
|
||||
case res, ok := <-resultChan:
|
||||
@@ -2626,14 +2470,10 @@ func TestInvalidFailure(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -2651,9 +2491,7 @@ func TestInvalidFailure(t *testing.T) {
|
||||
|
||||
// Create a request which should be forwarded to the mock channel link.
|
||||
preimage, err := genPreimage()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate preimage: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate preimage")
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
update := &lnwire.UpdateAddHTLC{
|
||||
PaymentHash: rhash,
|
||||
@@ -2666,9 +2504,7 @@ func TestInvalidFailure(t *testing.T) {
|
||||
err = s.SendHTLC(
|
||||
aliceChannelLink.ShortChanID(), paymentID, update,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payment: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to send payment")
|
||||
|
||||
// Catch the packet and complete the circuit so that the switch is ready
|
||||
// for a response.
|
||||
@@ -2860,9 +2696,7 @@ func testHtcNotifier(t *testing.T, testOpts []serverOption, iterations int,
|
||||
channels, cleanUp, _, err := createClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create channel")
|
||||
defer cleanUp()
|
||||
|
||||
// Mock time so that all events are reported with a static timestamp.
|
||||
@@ -3009,9 +2843,7 @@ func (n *threeHopNetwork) sendThreeHopPayment(t *testing.T) (*lnwire.UpdateAddHT
|
||||
}
|
||||
|
||||
err = n.carolServer.registry.AddInvoice(*invoice, htlc.PaymentHash)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to add invoice in carol registry: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to add invoice in carol registry")
|
||||
|
||||
if err := n.aliceServer.htlcSwitch.SendHTLC(
|
||||
n.firstBobChannelLink.ShortChanID(), pid, htlc,
|
||||
@@ -3219,30 +3051,20 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
alicePeer, err := newMockServer(
|
||||
t, "alice", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobPeer, err := newMockServer(
|
||||
t, "bob", testStartingHeight, nil, testDefaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
tempPath, err := ioutil.TempDir("", "circuitdb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to temporary path: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to temporary path")
|
||||
|
||||
cdb, err := channeldb.Open(tempPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
s, err := initSwitchWithDB(testStartingHeight, cdb)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init switch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init switch")
|
||||
if err := s.Start(); err != nil {
|
||||
t.Fatalf("unable to start switch: %v", err)
|
||||
}
|
||||
@@ -3320,9 +3142,7 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
packet.incomingTimeout = testStartingHeight + cltvRejectDelta - 1
|
||||
|
||||
err = switchForwardInterceptor.ForwardPackets(linkQuit, false, packet)
|
||||
if err != nil {
|
||||
t.Fatalf("can't forward htlc packet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "can't forward htlc packet")
|
||||
assertOutgoingLinkReceive(t, bobChannelLink, false)
|
||||
assertOutgoingLinkReceiveIntercepted(t, aliceChannelLink)
|
||||
assertNumCircuits(t, s, 0, 0)
|
||||
@@ -3340,9 +3160,7 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
}
|
||||
|
||||
err = switchForwardInterceptor.ForwardPackets(linkQuit, false, packet)
|
||||
if err != nil {
|
||||
t.Fatalf("can't forward htlc packet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "can't forward htlc packet")
|
||||
receivedPkt := assertOutgoingLinkReceive(t, bobChannelLink, true)
|
||||
assertNumCircuits(t, s, 1, 1)
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -966,21 +967,15 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
aliceServer, err := newMockServer(
|
||||
t, "alice", startingHeight, aliceDb, hopNetwork.defaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobServer, err := newMockServer(
|
||||
t, "bob", startingHeight, bobDb, hopNetwork.defaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
carolServer, err := newMockServer(
|
||||
t, "carol", startingHeight, carolDb, hopNetwork.defaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create carol server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create carol server")
|
||||
|
||||
// Apply all additional functional options to the servers before
|
||||
// creating any links.
|
||||
@@ -1231,15 +1226,11 @@ func newTwoHopNetwork(t testing.TB,
|
||||
aliceServer, err := newMockServer(
|
||||
t, "alice", startingHeight, aliceDb, hopNetwork.defaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create alice server")
|
||||
bobServer, err := newMockServer(
|
||||
t, "bob", startingHeight, bobDb, hopNetwork.defaultDelta,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob server: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob server")
|
||||
|
||||
// Create mock decoder instead of sphinx one in order to mock the route
|
||||
// which htlc should follow.
|
||||
|
||||
Reference in new issue
Block a user