From 4d34eb97ce793b3900c1df3fa3b40149288a6f32 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Wed, 29 Mar 2023 15:56:40 +0200 Subject: [PATCH] build: fixup new linter issues --- client_test.go | 18 ++++++++++-------- liquidity/loopin.go | 9 +++++---- liquidity/loopout.go | 15 +++++++++------ test/context.go | 2 +- test/lnd_services_mock.go | 4 +++- testcontext_test.go | 28 ++++++++++++++-------------- 6 files changed, 42 insertions(+), 34 deletions(-) diff --git a/client_test.go b/client_test.go index a6297dd..2e58574 100644 --- a/client_test.go +++ b/client_test.go @@ -65,7 +65,7 @@ func TestLoopOutSuccess(t *testing.T) { signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) // Expect client to register for conf. - confIntent := ctx.AssertRegisterConf(false, req.HtlcConfirmations) + confIntent := ctx.Context.AssertRegisterConf(false, req.HtlcConfirmations) testLoopOutSuccess(ctx, testRequest.Amount, info.SwapHash, signalPrepaymentResult, signalSwapPaymentResult, false, @@ -89,7 +89,7 @@ func TestLoopOutFailOffchain(t *testing.T) { signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc) signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) - ctx.AssertRegisterConf(false, defaultConfirmations) + ctx.Context.AssertRegisterConf(false, defaultConfirmations) signalSwapPaymentResult( errors.New(lndclient.PaymentResultUnknownPaymentHash), @@ -274,7 +274,9 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed, signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) // Expect client to register for our expected number of confirmations. - confIntent := ctx.AssertRegisterConf(preimageRevealed, int32(confs)) + confIntent := ctx.Context.AssertRegisterConf( + preimageRevealed, int32(confs), + ) htlc, err := GetHtlc( hash, &pendingSwap.Contract.SwapContract, @@ -325,7 +327,7 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash, // Expect a signing request in the non taproot case. if scriptVersion != swap.HtlcV3 { - <-ctx.Lnd.SignOutputRawChannel + <-ctx.Context.Lnd.SignOutputRawChannel } if !preimageRevealed { @@ -345,14 +347,14 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash, ctx.expiryChan <- testTime ctx.assertPreimagePush(testPreimage) } - <-ctx.Lnd.SignOutputRawChannel + <-ctx.Context.Lnd.SignOutputRawChannel } // Expect client on-chain sweep of HTLC. sweepTx := ctx.ReceiveTx() require.Equal( - ctx.T, htlcOutpoint.Hash[:], + ctx.Context.T, htlcOutpoint.Hash[:], sweepTx.TxIn[0].PreviousOutPoint.Hash[:], "client not sweeping from htlc tx", ) @@ -369,12 +371,12 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash, // Check preimage. clientPreImage := sweepTx.TxIn[0].Witness[preImageIndex] clientPreImageHash := sha256.Sum256(clientPreImage) - require.Equal(ctx.T, hash, lntypes.Hash(clientPreImageHash)) + require.Equal(ctx.Context.T, hash, lntypes.Hash(clientPreImageHash)) // Since we successfully published our sweep, we expect the preimage to // have been pushed to our mock server. preimage, err := lntypes.MakePreimage(clientPreImage) - require.NoError(ctx.T, err) + require.NoError(ctx.Context.T, err) if scriptVersion != swap.HtlcV3 { ctx.assertPreimagePush(preimage) diff --git a/liquidity/loopin.go b/liquidity/loopin.go index 15eed77..ca98885 100644 --- a/liquidity/loopin.go +++ b/liquidity/loopin.go @@ -19,13 +19,14 @@ type loopInSwapSuggestion struct { // amount returns the amount of the swap suggestion. func (l *loopInSwapSuggestion) amount() btcutil.Amount { - return l.Amount + return l.LoopInRequest.Amount } // fees returns the highest fees that we could pay for the swap suggestion. func (l *loopInSwapSuggestion) fees() btcutil.Amount { return worstCaseInFees( - l.MaxMinerFee, l.MaxSwapFee, defaultLoopInSweepFee, + l.LoopInRequest.MaxMinerFee, l.LoopInRequest.MaxSwapFee, + defaultLoopInSweepFee, ) } @@ -37,12 +38,12 @@ func (l *loopInSwapSuggestion) channels() []lnwire.ShortChannelID { // peers returns the peer that a loop in swap is restricted to, if it is set. func (l *loopInSwapSuggestion) peers(_ map[uint64]route.Vertex) []route.Vertex { - if l.LastHop == nil { + if l.LoopInRequest.LastHop == nil { return nil } return []route.Vertex{ - *l.LastHop, + *l.LoopInRequest.LastHop, } } diff --git a/liquidity/loopout.go b/liquidity/loopout.go index 747f91d..13b2ee6 100644 --- a/liquidity/loopout.go +++ b/liquidity/loopout.go @@ -20,22 +20,25 @@ type loopOutSwapSuggestion struct { // amount returns the amount being swapped. func (l *loopOutSwapSuggestion) amount() btcutil.Amount { - return l.Amount + return l.OutRequest.Amount } // fees returns the maximum fees we could possibly pay for this swap. func (l *loopOutSwapSuggestion) fees() btcutil.Amount { return worstCaseOutFees( - l.MaxPrepayRoutingFee, l.MaxSwapRoutingFee, l.MaxSwapFee, - l.MaxMinerFee, l.MaxPrepayAmount, + l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee, + l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee, + l.OutRequest.MaxPrepayAmount, ) } // channels returns the set of channels the loop out swap is restricted to. func (l *loopOutSwapSuggestion) channels() []lnwire.ShortChannelID { - channels := make([]lnwire.ShortChannelID, len(l.OutgoingChanSet)) + channels := make( + []lnwire.ShortChannelID, len(l.OutRequest.OutgoingChanSet), + ) - for i, id := range l.OutgoingChanSet { + for i, id := range l.OutRequest.OutgoingChanSet { channels[i] = lnwire.NewShortChanIDFromInt(id) } @@ -48,7 +51,7 @@ func (l *loopOutSwapSuggestion) peers( peers := make(map[route.Vertex]struct{}, len(knownChans)) - for _, channel := range l.OutgoingChanSet { + for _, channel := range l.OutRequest.OutgoingChanSet { peer, ok := knownChans[channel] if !ok { log.Warnf("peer for channel: %v unknown", channel) diff --git a/test/context.go b/test/context.go index be46a9a..638bcc7 100644 --- a/test/context.go +++ b/test/context.go @@ -161,7 +161,7 @@ func (ctx *Context) AssertPaid( expectedMemo) } - payReq := ctx.DecodeInvoice(swapPayment.Invoice) + payReq := ctx.DecodeInvoice(swapPayment.SendPaymentRequest.Invoice) _, ok := ctx.PaidInvoices[*payReq.Description] require.False( diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index e349a64..1dad7cc 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -262,5 +262,7 @@ func (s *LndMockServices) DecodeInvoice(request string) (*zpay32.Invoice, func (s *LndMockServices) SetFeeEstimate(confTarget int32, feeEstimate chainfee.SatPerKWeight) { - s.WalletKit.(*mockWalletKit).setFeeEstimate(confTarget, feeEstimate) + s.LndServices.WalletKit.(*mockWalletKit).setFeeEstimate( + confTarget, feeEstimate, + ) } diff --git a/testcontext_test.go b/testcontext_test.go index 8abe9db..2e4b996 100644 --- a/testcontext_test.go +++ b/testcontext_test.go @@ -140,45 +140,45 @@ func (ctx *testContext) finish() { ctx.stop() select { case err := <-ctx.runErr: - require.NoError(ctx.T, err) + require.NoError(ctx.Context.T, err) case <-time.After(test.Timeout): - ctx.T.Fatal("client not stopping") + ctx.Context.T.Fatal("client not stopping") } ctx.assertIsDone() } func (ctx *testContext) assertIsDone() { - require.NoError(ctx.T, ctx.Lnd.IsDone()) - require.NoError(ctx.T, ctx.store.isDone()) + require.NoError(ctx.Context.T, ctx.Context.Lnd.IsDone()) + require.NoError(ctx.Context.T, ctx.store.isDone()) select { case <-ctx.statusChan: - ctx.T.Fatalf("not all status updates read") + ctx.Context.T.Fatalf("not all status updates read") default: } } func (ctx *testContext) assertStored() { - ctx.T.Helper() + ctx.Context.T.Helper() ctx.store.assertLoopOutStored() } func (ctx *testContext) assertStorePreimageReveal() { - ctx.T.Helper() + ctx.Context.T.Helper() ctx.store.assertStorePreimageReveal() } func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) { - ctx.T.Helper() + ctx.Context.T.Helper() ctx.store.assertStoreFinished(expectedResult) } func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) { - ctx.T.Helper() + ctx.Context.T.Helper() for { select { @@ -191,7 +191,7 @@ func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) { return } case <-time.After(test.Timeout): - ctx.T.Fatalf("expected status %v not "+ + ctx.Context.T.Fatalf("expected status %v not "+ "received in time", expectedState) } } @@ -218,7 +218,7 @@ func (ctx *testContext) publishHtlc(script []byte, Tx: &htlcTx, }: case <-time.After(test.Timeout): - ctx.T.Fatalf("htlc confirmed not consumed") + ctx.Context.T.Fatalf("htlc confirmed not consumed") } return wire.OutPoint{ @@ -238,7 +238,7 @@ func (ctx *testContext) trackPayment(status lnrpc.Payment_PaymentStatus) { }: case <-time.After(test.Timeout): - ctx.T.Fatalf("could not send payment update") + ctx.Context.T.Fatalf("could not send payment update") } } @@ -247,9 +247,9 @@ func (ctx *testContext) trackPayment(status lnrpc.Payment_PaymentStatus) { func (ctx *testContext) assertPreimagePush(preimage lntypes.Preimage) { select { case pushedPreimage := <-ctx.serverMock.preimagePush: - require.Equal(ctx.T, preimage, pushedPreimage) + require.Equal(ctx.Context.T, preimage, pushedPreimage) case <-time.After(test.Timeout): - ctx.T.Fatalf("preimage not pushed") + ctx.Context.T.Fatalf("preimage not pushed") } }