routing: fix TestSendPaymentErrorRepeatedFeeInsufficient

The simulated error returned was rejected due to signature failure,
and didn't simulate correctly the insufficient fees error as
intended. Fix error by including correct signature.
This commit is contained in:
bluetegu 2018-12-10 07:42:57 -05:00 committed by yyforyongyu
parent fc113c7508
commit 242a844012
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

@ -206,6 +206,30 @@ func createTestCtxFromFile(startingHeight uint32, testGraph string) (*testCtx, f
return createTestCtxFromGraphInstance(startingHeight, graphInstance, false) return createTestCtxFromGraphInstance(startingHeight, graphInstance, false)
} }
// Add valid signature to channel update simulated as error received from the
// network.
func signErrChanUpdate(key *btcec.PrivateKey,
errChanUpdate *lnwire.ChannelUpdate) error {
chanUpdateMsg, err := errChanUpdate.DataToSign()
if err != nil {
return err
}
digest := chainhash.DoubleHashB(chanUpdateMsg)
sig, err := key.Sign(digest)
if err != nil {
return err
}
errChanUpdate.Signature, err = lnwire.NewSigFromSignature(sig)
if err != nil {
return err
}
return nil
}
// TestFindRoutesWithFeeLimit asserts that routes found by the FindRoutes method // TestFindRoutesWithFeeLimit asserts that routes found by the FindRoutes method
// within the channel router contain a total fee less than or equal to the fee // within the channel router contain a total fee less than or equal to the fee
// limit. // limit.
@ -504,15 +528,22 @@ func TestChannelUpdateValidation(t *testing.T) {
func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) { func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
t.Parallel() t.Parallel()
var (
roasbeefSongokuChanID = uint64(12345)
songokuSophonChanID = uint64(3495345)
)
const startingBlockHeight = 101 const startingBlockHeight = 101
ctx, cleanUp, err := createTestCtxFromFile(startingBlockHeight, basicGraphFilePath) ctx, cleanUp, err := createTestCtxFromFile(
startingBlockHeight, basicGraphFilePath,
)
if err != nil { if err != nil {
t.Fatalf("unable to create router: %v", err) t.Fatalf("unable to create router: %v", err)
} }
defer cleanUp() defer cleanUp()
// Craft a LightningPayment struct that'll send a payment from roasbeef // Craft a LightningPayment struct that'll send a payment from roasbeef
// to luo ji for 100 satoshis. // to sophon for 1000 satoshis.
var payHash lntypes.Hash var payHash lntypes.Hash
amt := lnwire.NewMSatFromSatoshis(1000) amt := lnwire.NewMSatFromSatoshis(1000)
payment := LightningPayment{ payment := LightningPayment{
@ -525,17 +556,20 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
var preImage [32]byte var preImage [32]byte
copy(preImage[:], bytes.Repeat([]byte{9}, 32)) copy(preImage[:], bytes.Repeat([]byte{9}, 32))
// We'll also fetch the first outgoing channel edge from roasbeef to // We'll also fetch the first outgoing channel edge from son goku
// son goku. We'll obtain this as we'll need to to generate the // to sophon. We'll obtain this as we'll need to to generate the
// FeeInsufficient error that we'll send back. // FeeInsufficient error that we'll send back.
chanID := uint64(12345) _, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(
_, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(chanID) songokuSophonChanID,
)
if err != nil { if err != nil {
t.Fatalf("unable to fetch chan id: %v", err) t.Fatalf("unable to fetch chan id: %v", err)
} }
errChanUpdate := lnwire.ChannelUpdate{ errChanUpdate := lnwire.ChannelUpdate{
ShortChannelID: lnwire.NewShortChanIDFromInt(chanID), ShortChannelID: lnwire.NewShortChanIDFromInt(
songokuSophonChanID,
),
Timestamp: uint32(edgeUpdateToFail.LastUpdate.Unix()), Timestamp: uint32(edgeUpdateToFail.LastUpdate.Unix()),
MessageFlags: edgeUpdateToFail.MessageFlags, MessageFlags: edgeUpdateToFail.MessageFlags,
ChannelFlags: edgeUpdateToFail.ChannelFlags, ChannelFlags: edgeUpdateToFail.ChannelFlags,
@ -546,13 +580,20 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
FeeRate: uint32(edgeUpdateToFail.FeeProportionalMillionths), FeeRate: uint32(edgeUpdateToFail.FeeProportionalMillionths),
} }
err = signErrChanUpdate(ctx.privKeys["songoku"], &errChanUpdate)
if err != nil {
t.Fatalf("Failed to sign channel update error: %v ", err)
}
// We'll now modify the SendToSwitch method to return an error for the // We'll now modify the SendToSwitch method to return an error for the
// outgoing channel to Son goku. This will be a fee related error, so // outgoing channel to Son goku. This will be a fee related error, so
// it should only cause the edge to be pruned after the second attempt. // it should only cause the edge to be pruned after the second attempt.
ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcher).setPaymentResult( ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcher).setPaymentResult(
func(firstHop lnwire.ShortChannelID) ([32]byte, error) { func(firstHop lnwire.ShortChannelID) ([32]byte, error) {
roasbeefSongoku := lnwire.NewShortChanIDFromInt(chanID) roasbeefSongoku := lnwire.NewShortChanIDFromInt(
roasbeefSongokuChanID,
)
if firstHop == roasbeefSongoku { if firstHop == roasbeefSongoku {
return [32]byte{}, htlcswitch.NewForwardingError( return [32]byte{}, htlcswitch.NewForwardingError(
// Within our error, we'll add a // Within our error, we'll add a
@ -590,7 +631,7 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
// The route should have pham nuwen as the first hop. // The route should have pham nuwen as the first hop.
if route.Hops[0].PubKeyBytes != ctx.aliases["phamnuwen"] { if route.Hops[0].PubKeyBytes != ctx.aliases["phamnuwen"] {
t.Fatalf("route should go through satoshi as first hop, "+ t.Fatalf("route should go through pham nuwen as first hop, "+
"instead passes through: %v", "instead passes through: %v",
getAliasFromPubKey(route.Hops[0].PubKeyBytes, getAliasFromPubKey(route.Hops[0].PubKeyBytes,
ctx.aliases)) ctx.aliases))