mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-02 00:51:14 +01:00
routing/pathfind_test: fmt whitespace
This commit is contained in:
@@ -901,14 +901,14 @@ func TestNewRoute(t *testing.T) {
|
|||||||
createHop := func(baseFee lnwire.MilliSatoshi,
|
createHop := func(baseFee lnwire.MilliSatoshi,
|
||||||
feeRate lnwire.MilliSatoshi,
|
feeRate lnwire.MilliSatoshi,
|
||||||
capacity btcutil.Amount,
|
capacity btcutil.Amount,
|
||||||
timeLockDelta uint16) (*ChannelHop) {
|
timeLockDelta uint16) *ChannelHop {
|
||||||
|
|
||||||
return &ChannelHop {
|
return &ChannelHop{
|
||||||
ChannelEdgePolicy: &channeldb.ChannelEdgePolicy {
|
ChannelEdgePolicy: &channeldb.ChannelEdgePolicy{
|
||||||
Node: &channeldb.LightningNode{},
|
Node: &channeldb.LightningNode{},
|
||||||
FeeProportionalMillionths: feeRate,
|
FeeProportionalMillionths: feeRate,
|
||||||
FeeBaseMSat: baseFee,
|
FeeBaseMSat: baseFee,
|
||||||
TimeLockDelta: timeLockDelta,
|
TimeLockDelta: timeLockDelta,
|
||||||
},
|
},
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
}
|
}
|
||||||
@@ -916,30 +916,30 @@ func TestNewRoute(t *testing.T) {
|
|||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
// name identifies the test case in the test output.
|
// name identifies the test case in the test output.
|
||||||
name string
|
name string
|
||||||
|
|
||||||
// hops is the list of hops (the route) that gets passed into
|
// hops is the list of hops (the route) that gets passed into
|
||||||
// the call to newRoute.
|
// the call to newRoute.
|
||||||
hops []*ChannelHop
|
hops []*ChannelHop
|
||||||
|
|
||||||
// paymentAmount is the amount that is send into the route
|
// paymentAmount is the amount that is send into the route
|
||||||
// indicated by hops.
|
// indicated by hops.
|
||||||
paymentAmount lnwire.MilliSatoshi
|
paymentAmount lnwire.MilliSatoshi
|
||||||
|
|
||||||
// expectedFees is a list of fees that every hop is expected
|
// expectedFees is a list of fees that every hop is expected
|
||||||
// to charge for forwarding.
|
// to charge for forwarding.
|
||||||
expectedFees []lnwire.MilliSatoshi
|
expectedFees []lnwire.MilliSatoshi
|
||||||
|
|
||||||
// expectedTimeLocks is a list of time lock values that every
|
// expectedTimeLocks is a list of time lock values that every
|
||||||
// hop is expected to specify in its outgoing HTLC. The time
|
// hop is expected to specify in its outgoing HTLC. The time
|
||||||
// lock values in this list are relative to the current block
|
// lock values in this list are relative to the current block
|
||||||
// height.
|
// height.
|
||||||
expectedTimeLocks []uint32
|
expectedTimeLocks []uint32
|
||||||
|
|
||||||
// expectedTotalAmount is the total amount that is expected to
|
// expectedTotalAmount is the total amount that is expected to
|
||||||
// be returned from newRoute. This amount should include all
|
// be returned from newRoute. This amount should include all
|
||||||
// the fees to be paid to intermediate hops.
|
// the fees to be paid to intermediate hops.
|
||||||
expectedTotalAmount lnwire.MilliSatoshi
|
expectedTotalAmount lnwire.MilliSatoshi
|
||||||
|
|
||||||
// expectedTotalTimeLock is the time lock that is expected to
|
// expectedTotalTimeLock is the time lock that is expected to
|
||||||
// be returned from newRoute. This is the time lock that should
|
// be returned from newRoute. This is the time lock that should
|
||||||
@@ -949,106 +949,106 @@ func TestNewRoute(t *testing.T) {
|
|||||||
|
|
||||||
// expectError indicates whether the newRoute call is expected
|
// expectError indicates whether the newRoute call is expected
|
||||||
// to fail or succeed.
|
// to fail or succeed.
|
||||||
expectError bool
|
expectError bool
|
||||||
|
|
||||||
// expectedErrorCode indicates the expected error code when
|
// expectedErrorCode indicates the expected error code when
|
||||||
// expectError is true.
|
// expectError is true.
|
||||||
expectedErrorCode errorCode
|
expectedErrorCode errorCode
|
||||||
} {
|
}{
|
||||||
{
|
{
|
||||||
// For a single hop payment, no fees are expected to be paid.
|
// For a single hop payment, no fees are expected to be paid.
|
||||||
name: "single hop",
|
name: "single hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(100, 1000, 1000, 10),
|
createHop(100, 1000, 1000, 10),
|
||||||
},
|
},
|
||||||
expectedFees: []lnwire.MilliSatoshi {0},
|
expectedFees: []lnwire.MilliSatoshi{0},
|
||||||
expectedTimeLocks: []uint32 {1},
|
expectedTimeLocks: []uint32{1},
|
||||||
expectedTotalAmount: 100000,
|
expectedTotalAmount: 100000,
|
||||||
expectedTotalTimeLock: 1,
|
expectedTotalTimeLock: 1,
|
||||||
}, {
|
}, {
|
||||||
// For a two hop payment, only the fee for the first hop
|
// For a two hop payment, only the fee for the first hop
|
||||||
// needs to be paid. The destination hop does not require
|
// needs to be paid. The destination hop does not require
|
||||||
// a fee to receive the payment.
|
// a fee to receive the payment.
|
||||||
name: "two hop",
|
name: "two hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(0, 1000, 1000, 10),
|
createHop(0, 1000, 1000, 10),
|
||||||
createHop(30, 1000, 1000, 5),
|
createHop(30, 1000, 1000, 5),
|
||||||
},
|
},
|
||||||
expectedFees: []lnwire.MilliSatoshi {130, 0},
|
expectedFees: []lnwire.MilliSatoshi{130, 0},
|
||||||
expectedTimeLocks: []uint32 {1, 1},
|
expectedTimeLocks: []uint32{1, 1},
|
||||||
expectedTotalAmount: 100130,
|
expectedTotalAmount: 100130,
|
||||||
expectedTotalTimeLock: 6,
|
expectedTotalTimeLock: 6,
|
||||||
}, {
|
}, {
|
||||||
// Insufficient capacity in first channel when fees are added.
|
// Insufficient capacity in first channel when fees are added.
|
||||||
name: "two hop insufficient",
|
name: "two hop insufficient",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(0, 1000, 100, 10),
|
createHop(0, 1000, 100, 10),
|
||||||
createHop(0, 1000, 1000, 5),
|
createHop(0, 1000, 1000, 5),
|
||||||
},
|
},
|
||||||
expectError: true,
|
expectError: true,
|
||||||
expectedErrorCode: ErrInsufficientCapacity,
|
expectedErrorCode: ErrInsufficientCapacity,
|
||||||
}, {
|
}, {
|
||||||
// A three hop payment where the first and second hop
|
// A three hop payment where the first and second hop
|
||||||
// will both charge 1 msat. The fee for the first hop
|
// will both charge 1 msat. The fee for the first hop
|
||||||
// is actually slightly higher than 1, because the amount
|
// is actually slightly higher than 1, because the amount
|
||||||
// to forward also includes the fee for the second hop. This
|
// to forward also includes the fee for the second hop. This
|
||||||
// gets rounded down to 1.
|
// gets rounded down to 1.
|
||||||
name: "three hop",
|
name: "three hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(0, 10, 1000, 10),
|
createHop(0, 10, 1000, 10),
|
||||||
createHop(0, 10, 1000, 5),
|
createHop(0, 10, 1000, 5),
|
||||||
createHop(0, 10, 1000, 3),
|
createHop(0, 10, 1000, 3),
|
||||||
},
|
},
|
||||||
expectedFees: []lnwire.MilliSatoshi {1, 1, 0},
|
expectedFees: []lnwire.MilliSatoshi{1, 1, 0},
|
||||||
expectedTotalAmount: 100002,
|
expectedTotalAmount: 100002,
|
||||||
expectedTimeLocks: []uint32 {4, 1, 1},
|
expectedTimeLocks: []uint32{4, 1, 1},
|
||||||
expectedTotalTimeLock: 9,
|
expectedTotalTimeLock: 9,
|
||||||
}, {
|
}, {
|
||||||
// A three hop payment where the fee of the first hop
|
// A three hop payment where the fee of the first hop
|
||||||
// is slightly higher (11) than the fee at the second hop,
|
// is slightly higher (11) than the fee at the second hop,
|
||||||
// because of the increase amount to forward.
|
// because of the increase amount to forward.
|
||||||
name: "three hop with fee carry over",
|
name: "three hop with fee carry over",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(0, 10000, 1000, 10),
|
createHop(0, 10000, 1000, 10),
|
||||||
createHop(0, 10000, 1000, 5),
|
createHop(0, 10000, 1000, 5),
|
||||||
createHop(0, 10000, 1000, 3),
|
createHop(0, 10000, 1000, 3),
|
||||||
},
|
},
|
||||||
expectedFees: []lnwire.MilliSatoshi {1010, 1000, 0},
|
expectedFees: []lnwire.MilliSatoshi{1010, 1000, 0},
|
||||||
expectedTotalAmount: 102010,
|
expectedTotalAmount: 102010,
|
||||||
expectedTimeLocks: []uint32 {4, 1, 1},
|
expectedTimeLocks: []uint32{4, 1, 1},
|
||||||
expectedTotalTimeLock: 9,
|
expectedTotalTimeLock: 9,
|
||||||
}, {
|
}, {
|
||||||
// A three hop payment where the fee policies of the first and
|
// A three hop payment where the fee policies of the first and
|
||||||
// second hop are just high enough to show the fee carry over
|
// second hop are just high enough to show the fee carry over
|
||||||
// effect.
|
// effect.
|
||||||
name: "three hop with minimal fees for carry over",
|
name: "three hop with minimal fees for carry over",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*ChannelHop {
|
hops: []*ChannelHop{
|
||||||
createHop(0, 10000, 1000, 10),
|
createHop(0, 10000, 1000, 10),
|
||||||
|
|
||||||
// First hop charges 0.1% so the second hop fee
|
// First hop charges 0.1% so the second hop fee
|
||||||
// should show up in the first hop fee as 1 msat
|
// should show up in the first hop fee as 1 msat
|
||||||
// extra.
|
// extra.
|
||||||
createHop(0, 1000, 1000, 5),
|
createHop(0, 1000, 1000, 5),
|
||||||
|
|
||||||
// Second hop charges a fixed 1000 msat.
|
// Second hop charges a fixed 1000 msat.
|
||||||
createHop(1000, 0, 1000, 3),
|
createHop(1000, 0, 1000, 3),
|
||||||
},
|
},
|
||||||
expectedFees: []lnwire.MilliSatoshi {101, 1000, 0},
|
expectedFees: []lnwire.MilliSatoshi{101, 1000, 0},
|
||||||
expectedTotalAmount: 101101,
|
expectedTotalAmount: 101101,
|
||||||
expectedTimeLocks: []uint32 {4, 1, 1},
|
expectedTimeLocks: []uint32{4, 1, 1},
|
||||||
expectedTotalTimeLock: 9,
|
expectedTotalTimeLock: 9,
|
||||||
} }
|
}}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
assertRoute := func(t *testing.T, route *Route) {
|
assertRoute := func(t *testing.T, route *Route) {
|
||||||
if route.TotalAmount != testCase.expectedTotalAmount {
|
if route.TotalAmount != testCase.expectedTotalAmount {
|
||||||
t.Errorf("Expected total amount is be %v" +
|
t.Errorf("Expected total amount is be %v"+
|
||||||
", but got %v instead",
|
", but got %v instead",
|
||||||
testCase.expectedTotalAmount,
|
testCase.expectedTotalAmount,
|
||||||
route.TotalAmount)
|
route.TotalAmount)
|
||||||
@@ -1058,10 +1058,10 @@ func TestNewRoute(t *testing.T) {
|
|||||||
if testCase.expectedFees[i] !=
|
if testCase.expectedFees[i] !=
|
||||||
route.Hops[i].Fee {
|
route.Hops[i].Fee {
|
||||||
|
|
||||||
t.Errorf("Expected fee for hop %v to " +
|
t.Errorf("Expected fee for hop %v to "+
|
||||||
"be %v, but got %v instead",
|
"be %v, but got %v instead",
|
||||||
i, testCase.expectedFees[i],
|
i, testCase.expectedFees[i],
|
||||||
route.Hops[i].Fee)
|
route.Hops[i].Fee)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1070,7 +1070,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
|
|
||||||
if route.TotalTimeLock != expectedTimeLockHeight {
|
if route.TotalTimeLock != expectedTimeLockHeight {
|
||||||
|
|
||||||
t.Errorf("Expected total time lock to be %v" +
|
t.Errorf("Expected total time lock to be %v"+
|
||||||
", but got %v instead",
|
", but got %v instead",
|
||||||
expectedTimeLockHeight,
|
expectedTimeLockHeight,
|
||||||
route.TotalTimeLock)
|
route.TotalTimeLock)
|
||||||
@@ -1083,10 +1083,10 @@ func TestNewRoute(t *testing.T) {
|
|||||||
if expectedTimeLockHeight !=
|
if expectedTimeLockHeight !=
|
||||||
route.Hops[i].OutgoingTimeLock {
|
route.Hops[i].OutgoingTimeLock {
|
||||||
|
|
||||||
t.Errorf("Expected time lock for hop " +
|
t.Errorf("Expected time lock for hop "+
|
||||||
"%v to be %v, but got %v instead",
|
"%v to be %v, but got %v instead",
|
||||||
i, expectedTimeLockHeight,
|
i, expectedTimeLockHeight,
|
||||||
route.Hops[i].OutgoingTimeLock)
|
route.Hops[i].OutgoingTimeLock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1100,10 +1100,10 @@ func TestNewRoute(t *testing.T) {
|
|||||||
if testCase.expectError {
|
if testCase.expectError {
|
||||||
expectedCode := testCase.expectedErrorCode
|
expectedCode := testCase.expectedErrorCode
|
||||||
if err == nil || !IsError(err, expectedCode) {
|
if err == nil || !IsError(err, expectedCode) {
|
||||||
t.Errorf("expected newRoute to fail " +
|
t.Errorf("expected newRoute to fail "+
|
||||||
"with error code %v, but got" +
|
"with error code %v, but got"+
|
||||||
"%v instead",
|
"%v instead",
|
||||||
expectedCode, err)
|
expectedCode, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user