routing/pathfind_test: fmt whitespace

This commit is contained in:
Conner Fromknecht 2018-07-31 00:20:22 -07:00
parent 614b3b3862
commit 9eff876f52
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -543,13 +543,13 @@ func TestFindLowestFeePath(t *testing.T) {
t.Fatalf("unable to find path: %v", err)
}
route, err := newRoute(
paymentAmt, infinity, sourceVertex, path, startingHeight,
paymentAmt, infinity, sourceVertex, path, startingHeight,
finalHopCLTV)
if err != nil {
t.Fatalf("unable to create path: %v", err)
}
// Assert that the lowest fee route is returned.
// Assert that the lowest fee route is returned.
if !bytes.Equal(route.Hops[0].Channel.Node.PubKeyBytes[:],
aliases["b"].SerializeCompressed()) {
t.Fatalf("expected route to pass through b, "+
@ -899,47 +899,47 @@ func TestNewRoute(t *testing.T) {
)
createHop := func(baseFee lnwire.MilliSatoshi,
feeRate lnwire.MilliSatoshi,
feeRate lnwire.MilliSatoshi,
capacity btcutil.Amount,
timeLockDelta uint16) (*ChannelHop) {
timeLockDelta uint16) *ChannelHop {
return &ChannelHop {
ChannelEdgePolicy: &channeldb.ChannelEdgePolicy {
return &ChannelHop{
ChannelEdgePolicy: &channeldb.ChannelEdgePolicy{
Node: &channeldb.LightningNode{},
FeeProportionalMillionths: feeRate,
FeeBaseMSat: baseFee,
TimeLockDelta: timeLockDelta,
FeeBaseMSat: baseFee,
TimeLockDelta: timeLockDelta,
},
Capacity: capacity,
}
}
testCases := []struct {
testCases := []struct {
// 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
// the call to newRoute.
hops []*ChannelHop
hops []*ChannelHop
// paymentAmount is the amount that is send into the route
// indicated by hops.
paymentAmount lnwire.MilliSatoshi
paymentAmount lnwire.MilliSatoshi
// expectedFees is a list of fees that every hop is expected
// to charge for forwarding.
expectedFees []lnwire.MilliSatoshi
expectedFees []lnwire.MilliSatoshi
// expectedTimeLocks is a list of time lock values that every
// hop is expected to specify in its outgoing HTLC. The time
// lock values in this list are relative to the current block
// height.
expectedTimeLocks []uint32
expectedTimeLocks []uint32
// expectedTotalAmount is the total amount that is expected to
// be returned from newRoute. This amount should include all
// the fees to be paid to intermediate hops.
expectedTotalAmount lnwire.MilliSatoshi
expectedTotalAmount lnwire.MilliSatoshi
// expectedTotalTimeLock is the time lock that is expected to
// 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
// to fail or succeed.
expectError bool
expectError bool
// expectedErrorCode indicates the expected error code when
// expectError is true.
expectedErrorCode errorCode
} {
{
// For a single hop payment, no fees are expected to be paid.
name: "single hop",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(100, 1000, 1000, 10),
},
expectedFees: []lnwire.MilliSatoshi {0},
expectedTimeLocks: []uint32 {1},
expectedTotalAmount: 100000,
expectedTotalTimeLock: 1,
}, {
// For a two hop payment, only the fee for the first hop
// needs to be paid. The destination hop does not require
// a fee to receive the payment.
name: "two hop",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(0, 1000, 1000, 10),
createHop(30, 1000, 1000, 5),
},
expectedFees: []lnwire.MilliSatoshi {130, 0},
expectedTimeLocks: []uint32 {1, 1},
expectedTotalAmount: 100130,
expectedTotalTimeLock: 6,
}, {
// Insufficient capacity in first channel when fees are added.
name: "two hop insufficient",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(0, 1000, 100, 10),
createHop(0, 1000, 1000, 5),
},
expectError: true,
expectedErrorCode: ErrInsufficientCapacity,
}, {
// A three hop payment where the first and second hop
// will both charge 1 msat. The fee for the first hop
// is actually slightly higher than 1, because the amount
// to forward also includes the fee for the second hop. This
// gets rounded down to 1.
name: "three hop",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(0, 10, 1000, 10),
createHop(0, 10, 1000, 5),
createHop(0, 10, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi {1, 1, 0},
expectedTotalAmount: 100002,
expectedTimeLocks: []uint32 {4, 1, 1},
expectedTotalTimeLock: 9,
}, {
// A three hop payment where the fee of the first hop
// is slightly higher (11) than the fee at the second hop,
// because of the increase amount to forward.
name: "three hop with fee carry over",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(0, 10000, 1000, 10),
createHop(0, 10000, 1000, 5),
createHop(0, 10000, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi {1010, 1000, 0},
expectedTotalAmount: 102010,
expectedTimeLocks: []uint32 {4, 1, 1},
expectedTotalTimeLock: 9,
}, {
// A three hop payment where the fee policies of the first and
// second hop are just high enough to show the fee carry over
// effect.
name: "three hop with minimal fees for carry over",
paymentAmount: 100000,
hops: []*ChannelHop {
createHop(0, 10000, 1000, 10),
// First hop charges 0.1% so the second hop fee
// should show up in the first hop fee as 1 msat
// extra.
createHop(0, 1000, 1000, 5),
expectedErrorCode errorCode
}{
{
// For a single hop payment, no fees are expected to be paid.
name: "single hop",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(100, 1000, 1000, 10),
},
expectedFees: []lnwire.MilliSatoshi{0},
expectedTimeLocks: []uint32{1},
expectedTotalAmount: 100000,
expectedTotalTimeLock: 1,
}, {
// For a two hop payment, only the fee for the first hop
// needs to be paid. The destination hop does not require
// a fee to receive the payment.
name: "two hop",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(0, 1000, 1000, 10),
createHop(30, 1000, 1000, 5),
},
expectedFees: []lnwire.MilliSatoshi{130, 0},
expectedTimeLocks: []uint32{1, 1},
expectedTotalAmount: 100130,
expectedTotalTimeLock: 6,
}, {
// Insufficient capacity in first channel when fees are added.
name: "two hop insufficient",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(0, 1000, 100, 10),
createHop(0, 1000, 1000, 5),
},
expectError: true,
expectedErrorCode: ErrInsufficientCapacity,
}, {
// A three hop payment where the first and second hop
// will both charge 1 msat. The fee for the first hop
// is actually slightly higher than 1, because the amount
// to forward also includes the fee for the second hop. This
// gets rounded down to 1.
name: "three hop",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(0, 10, 1000, 10),
createHop(0, 10, 1000, 5),
createHop(0, 10, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi{1, 1, 0},
expectedTotalAmount: 100002,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
}, {
// A three hop payment where the fee of the first hop
// is slightly higher (11) than the fee at the second hop,
// because of the increase amount to forward.
name: "three hop with fee carry over",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(0, 10000, 1000, 10),
createHop(0, 10000, 1000, 5),
createHop(0, 10000, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi{1010, 1000, 0},
expectedTotalAmount: 102010,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
}, {
// A three hop payment where the fee policies of the first and
// second hop are just high enough to show the fee carry over
// effect.
name: "three hop with minimal fees for carry over",
paymentAmount: 100000,
hops: []*ChannelHop{
createHop(0, 10000, 1000, 10),
// First hop charges 0.1% so the second hop fee
// should show up in the first hop fee as 1 msat
// extra.
createHop(0, 1000, 1000, 5),
// Second hop charges a fixed 1000 msat.
createHop(1000, 0, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi{101, 1000, 0},
expectedTotalAmount: 101101,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
}}
// Second hop charges a fixed 1000 msat.
createHop(1000, 0, 1000, 3),
},
expectedFees: []lnwire.MilliSatoshi {101, 1000, 0},
expectedTotalAmount: 101101,
expectedTimeLocks: []uint32 {4, 1, 1},
expectedTotalTimeLock: 9,
} }
for _, testCase := range testCases {
assertRoute := func(t *testing.T, route *Route) {
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",
testCase.expectedTotalAmount,
route.TotalAmount)
@ -1057,42 +1057,42 @@ func TestNewRoute(t *testing.T) {
for i := 0; i < len(testCase.expectedFees); i++ {
if testCase.expectedFees[i] !=
route.Hops[i].Fee {
t.Errorf("Expected fee for hop %v to " +
"be %v, but got %v instead",
i, testCase.expectedFees[i],
route.Hops[i].Fee)
t.Errorf("Expected fee for hop %v to "+
"be %v, but got %v instead",
i, testCase.expectedFees[i],
route.Hops[i].Fee)
}
}
expectedTimeLockHeight := startingHeight +
expectedTimeLockHeight := startingHeight +
testCase.expectedTotalTimeLock
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",
expectedTimeLockHeight,
route.TotalTimeLock)
}
for i := 0; i < len(testCase.expectedTimeLocks); i++ {
expectedTimeLockHeight := startingHeight +
expectedTimeLockHeight := startingHeight +
testCase.expectedTimeLocks[i]
if expectedTimeLockHeight !=
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",
i, expectedTimeLockHeight,
route.Hops[i].OutgoingTimeLock)
i, expectedTimeLockHeight,
route.Hops[i].OutgoingTimeLock)
}
}
}
t.Run(testCase.name, func(t *testing.T) {
route, err := newRoute(testCase.paymentAmount,
route, err := newRoute(testCase.paymentAmount,
noFeeLimit,
sourceVertex, testCase.hops, startingHeight,
finalHopCLTV)
@ -1100,10 +1100,10 @@ func TestNewRoute(t *testing.T) {
if testCase.expectError {
expectedCode := testCase.expectedErrorCode
if err == nil || !IsError(err, expectedCode) {
t.Errorf("expected newRoute to fail " +
"with error code %v, but got" +
"%v instead",
expectedCode, err)
t.Errorf("expected newRoute to fail "+
"with error code %v, but got"+
"%v instead",
expectedCode, err)
}
} else {
if err != nil {