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

View File

@ -206,6 +206,30 @@ func createTestCtxFromFile(startingHeight uint32, testGraph string) (*testCtx, f
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
// within the channel router contain a total fee less than or equal to the fee
// limit.
@ -504,15 +528,22 @@ func TestChannelUpdateValidation(t *testing.T) {
func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
t.Parallel()
var (
roasbeefSongokuChanID = uint64(12345)
songokuSophonChanID = uint64(3495345)
)
const startingBlockHeight = 101
ctx, cleanUp, err := createTestCtxFromFile(startingBlockHeight, basicGraphFilePath)
ctx, cleanUp, err := createTestCtxFromFile(
startingBlockHeight, basicGraphFilePath,
)
if err != nil {
t.Fatalf("unable to create router: %v", err)
}
defer cleanUp()
// 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
amt := lnwire.NewMSatFromSatoshis(1000)
payment := LightningPayment{
@ -525,17 +556,20 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
var preImage [32]byte
copy(preImage[:], bytes.Repeat([]byte{9}, 32))
// We'll also fetch the first outgoing channel edge from roasbeef to
// son goku. We'll obtain this as we'll need to to generate the
// We'll also fetch the first outgoing channel edge from son goku
// to sophon. We'll obtain this as we'll need to to generate the
// FeeInsufficient error that we'll send back.
chanID := uint64(12345)
_, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(chanID)
_, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(
songokuSophonChanID,
)
if err != nil {
t.Fatalf("unable to fetch chan id: %v", err)
}
errChanUpdate := lnwire.ChannelUpdate{
ShortChannelID: lnwire.NewShortChanIDFromInt(chanID),
ShortChannelID: lnwire.NewShortChanIDFromInt(
songokuSophonChanID,
),
Timestamp: uint32(edgeUpdateToFail.LastUpdate.Unix()),
MessageFlags: edgeUpdateToFail.MessageFlags,
ChannelFlags: edgeUpdateToFail.ChannelFlags,
@ -546,13 +580,20 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
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
// 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.
ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcher).setPaymentResult(
func(firstHop lnwire.ShortChannelID) ([32]byte, error) {
roasbeefSongoku := lnwire.NewShortChanIDFromInt(chanID)
roasbeefSongoku := lnwire.NewShortChanIDFromInt(
roasbeefSongokuChanID,
)
if firstHop == roasbeefSongoku {
return [32]byte{}, htlcswitch.NewForwardingError(
// 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.
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",
getAliasFromPubKey(route.Hops[0].PubKeyBytes,
ctx.aliases))