routing: rm hardcoded channel id in router test

This commit is contained in:
yyforyongyu 2021-04-10 19:27:58 +08:00
parent ae6d8a9a8f
commit 8172811e74
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

@ -334,6 +334,11 @@ func TestSendPaymentRouteFailureFallback(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))
// Get the channel ID.
roasbeefSongoku := lnwire.NewShortChanIDFromInt(
ctx.getChannelIDFromAlias(t, "roasbeef", "songoku"),
)
// We'll modify the SendToSwitch method that's been set within the // We'll modify the SendToSwitch method that's been set within the
// router's configuration to ignore the path that has son goku as the // router's configuration to ignore the path that has son goku as the
// first hop. This should force the router to instead take the // first hop. This should force the router to instead take the
@ -341,7 +346,6 @@ func TestSendPaymentRouteFailureFallback(t *testing.T) {
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(12345)
if firstHop == roasbeefSongoku { if firstHop == roasbeefSongoku {
return [32]byte{}, htlcswitch.NewForwardingError( return [32]byte{}, htlcswitch.NewForwardingError(
// TODO(roasbeef): temp node failure // TODO(roasbeef): temp node failure
@ -548,11 +552,6 @@ 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( ctx, cleanUp, err := createTestCtxFromFile(
startingBlockHeight, basicGraphFilePath, startingBlockHeight, basicGraphFilePath,
@ -562,6 +561,14 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
// Get the channel ID.
roasbeefSongokuChanID := ctx.getChannelIDFromAlias(
t, "roasbeef", "songoku",
)
songokuSophonChanID := ctx.getChannelIDFromAlias(
t, "songoku", "sophon",
)
// Craft a LightningPayment struct that'll send a payment from roasbeef // Craft a LightningPayment struct that'll send a payment from roasbeef
// to sophon for 1000 satoshis. // to sophon for 1000 satoshis.
var payHash lntypes.Hash var payHash lntypes.Hash
@ -673,6 +680,11 @@ func TestSendPaymentErrorFeeInsufficientPrivateEdge(t *testing.T) {
require.NoError(t, err, "unable to create router") require.NoError(t, err, "unable to create router")
defer cleanUp() defer cleanUp()
// Get the channel ID.
roasbeefSongoku := lnwire.NewShortChanIDFromInt(
ctx.getChannelIDFromAlias(t, "roasbeef", "songoku"),
)
// Craft a LightningPayment struct that'll send a payment from roasbeef // Craft a LightningPayment struct that'll send a payment from roasbeef
// to elst, through a private channel between son goku and elst for // to elst, through a private channel between son goku and elst for
// 1000 satoshis. This route has lower fees compared with the route // 1000 satoshis. This route has lower fees compared with the route
@ -729,7 +741,7 @@ func TestSendPaymentErrorFeeInsufficientPrivateEdge(t *testing.T) {
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) {
if errorReturned { if firstHop != roasbeefSongoku || errorReturned {
return preImage, nil return preImage, nil
} }
@ -818,8 +830,9 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
// son goku. This edge will be included in the time lock related expiry // son goku. This edge will be included in the time lock related expiry
// errors that we'll get back due to disagrements in what the current // errors that we'll get back due to disagrements in what the current
// block height is. // block height is.
chanID := uint64(12345) chanID := ctx.getChannelIDFromAlias(t, "roasbeef", "songoku")
roasbeefSongoku := lnwire.NewShortChanIDFromInt(chanID) roasbeefSongoku := lnwire.NewShortChanIDFromInt(chanID)
_, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(chanID) _, _, edgeUpdateToFail, err := ctx.graph.FetchChannelEdgesByID(chanID)
if err != nil { if err != nil {
t.Fatalf("unable to fetch chan id: %v", err) t.Fatalf("unable to fetch chan id: %v", err)
@ -947,8 +960,12 @@ func TestSendPaymentErrorPathPruning(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))
roasbeefSongoku := lnwire.NewShortChanIDFromInt(12345) roasbeefSongoku := lnwire.NewShortChanIDFromInt(
roasbeefPhanNuwen := lnwire.NewShortChanIDFromInt(999991) ctx.getChannelIDFromAlias(t, "roasbeef", "songoku"),
)
roasbeefPhanNuwen := lnwire.NewShortChanIDFromInt(
ctx.getChannelIDFromAlias(t, "roasbeef", "phamnuwen"),
)
// First, we'll modify the SendToSwitch method to return an error // First, we'll modify the SendToSwitch method to return an error
// indicating that the channel from roasbeef to son goku is not operable // indicating that the channel from roasbeef to son goku is not operable