build: fixup new linter issues

pull/561/head
Andras Banki-Horvath 1 year ago
parent 451311d582
commit 4d34eb97ce
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8

@ -65,7 +65,7 @@ func TestLoopOutSuccess(t *testing.T) {
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
// Expect client to register for conf. // 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, testLoopOutSuccess(ctx, testRequest.Amount, info.SwapHash,
signalPrepaymentResult, signalSwapPaymentResult, false, signalPrepaymentResult, signalSwapPaymentResult, false,
@ -89,7 +89,7 @@ func TestLoopOutFailOffchain(t *testing.T) {
signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc) signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc)
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
ctx.AssertRegisterConf(false, defaultConfirmations) ctx.Context.AssertRegisterConf(false, defaultConfirmations)
signalSwapPaymentResult( signalSwapPaymentResult(
errors.New(lndclient.PaymentResultUnknownPaymentHash), errors.New(lndclient.PaymentResultUnknownPaymentHash),
@ -274,7 +274,9 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
// Expect client to register for our expected number of confirmations. // 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( htlc, err := GetHtlc(
hash, &pendingSwap.Contract.SwapContract, 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. // Expect a signing request in the non taproot case.
if scriptVersion != swap.HtlcV3 { if scriptVersion != swap.HtlcV3 {
<-ctx.Lnd.SignOutputRawChannel <-ctx.Context.Lnd.SignOutputRawChannel
} }
if !preimageRevealed { if !preimageRevealed {
@ -345,14 +347,14 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
ctx.expiryChan <- testTime ctx.expiryChan <- testTime
ctx.assertPreimagePush(testPreimage) ctx.assertPreimagePush(testPreimage)
} }
<-ctx.Lnd.SignOutputRawChannel <-ctx.Context.Lnd.SignOutputRawChannel
} }
// Expect client on-chain sweep of HTLC. // Expect client on-chain sweep of HTLC.
sweepTx := ctx.ReceiveTx() sweepTx := ctx.ReceiveTx()
require.Equal( require.Equal(
ctx.T, htlcOutpoint.Hash[:], ctx.Context.T, htlcOutpoint.Hash[:],
sweepTx.TxIn[0].PreviousOutPoint.Hash[:], sweepTx.TxIn[0].PreviousOutPoint.Hash[:],
"client not sweeping from htlc tx", "client not sweeping from htlc tx",
) )
@ -369,12 +371,12 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
// Check preimage. // Check preimage.
clientPreImage := sweepTx.TxIn[0].Witness[preImageIndex] clientPreImage := sweepTx.TxIn[0].Witness[preImageIndex]
clientPreImageHash := sha256.Sum256(clientPreImage) 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 // Since we successfully published our sweep, we expect the preimage to
// have been pushed to our mock server. // have been pushed to our mock server.
preimage, err := lntypes.MakePreimage(clientPreImage) preimage, err := lntypes.MakePreimage(clientPreImage)
require.NoError(ctx.T, err) require.NoError(ctx.Context.T, err)
if scriptVersion != swap.HtlcV3 { if scriptVersion != swap.HtlcV3 {
ctx.assertPreimagePush(preimage) ctx.assertPreimagePush(preimage)

@ -19,13 +19,14 @@ type loopInSwapSuggestion struct {
// amount returns the amount of the swap suggestion. // amount returns the amount of the swap suggestion.
func (l *loopInSwapSuggestion) amount() btcutil.Amount { 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. // fees returns the highest fees that we could pay for the swap suggestion.
func (l *loopInSwapSuggestion) fees() btcutil.Amount { func (l *loopInSwapSuggestion) fees() btcutil.Amount {
return worstCaseInFees( 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. // 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 { func (l *loopInSwapSuggestion) peers(_ map[uint64]route.Vertex) []route.Vertex {
if l.LastHop == nil { if l.LoopInRequest.LastHop == nil {
return nil return nil
} }
return []route.Vertex{ return []route.Vertex{
*l.LastHop, *l.LoopInRequest.LastHop,
} }
} }

@ -20,22 +20,25 @@ type loopOutSwapSuggestion struct {
// amount returns the amount being swapped. // amount returns the amount being swapped.
func (l *loopOutSwapSuggestion) amount() btcutil.Amount { 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. // fees returns the maximum fees we could possibly pay for this swap.
func (l *loopOutSwapSuggestion) fees() btcutil.Amount { func (l *loopOutSwapSuggestion) fees() btcutil.Amount {
return worstCaseOutFees( return worstCaseOutFees(
l.MaxPrepayRoutingFee, l.MaxSwapRoutingFee, l.MaxSwapFee, l.OutRequest.MaxPrepayRoutingFee, l.OutRequest.MaxSwapRoutingFee,
l.MaxMinerFee, l.MaxPrepayAmount, l.OutRequest.MaxSwapFee, l.OutRequest.MaxMinerFee,
l.OutRequest.MaxPrepayAmount,
) )
} }
// channels returns the set of channels the loop out swap is restricted to. // channels returns the set of channels the loop out swap is restricted to.
func (l *loopOutSwapSuggestion) channels() []lnwire.ShortChannelID { 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) channels[i] = lnwire.NewShortChanIDFromInt(id)
} }
@ -48,7 +51,7 @@ func (l *loopOutSwapSuggestion) peers(
peers := make(map[route.Vertex]struct{}, len(knownChans)) peers := make(map[route.Vertex]struct{}, len(knownChans))
for _, channel := range l.OutgoingChanSet { for _, channel := range l.OutRequest.OutgoingChanSet {
peer, ok := knownChans[channel] peer, ok := knownChans[channel]
if !ok { if !ok {
log.Warnf("peer for channel: %v unknown", channel) log.Warnf("peer for channel: %v unknown", channel)

@ -161,7 +161,7 @@ func (ctx *Context) AssertPaid(
expectedMemo) expectedMemo)
} }
payReq := ctx.DecodeInvoice(swapPayment.Invoice) payReq := ctx.DecodeInvoice(swapPayment.SendPaymentRequest.Invoice)
_, ok := ctx.PaidInvoices[*payReq.Description] _, ok := ctx.PaidInvoices[*payReq.Description]
require.False( require.False(

@ -262,5 +262,7 @@ func (s *LndMockServices) DecodeInvoice(request string) (*zpay32.Invoice,
func (s *LndMockServices) SetFeeEstimate(confTarget int32, func (s *LndMockServices) SetFeeEstimate(confTarget int32,
feeEstimate chainfee.SatPerKWeight) { feeEstimate chainfee.SatPerKWeight) {
s.WalletKit.(*mockWalletKit).setFeeEstimate(confTarget, feeEstimate) s.LndServices.WalletKit.(*mockWalletKit).setFeeEstimate(
confTarget, feeEstimate,
)
} }

@ -140,45 +140,45 @@ func (ctx *testContext) finish() {
ctx.stop() ctx.stop()
select { select {
case err := <-ctx.runErr: case err := <-ctx.runErr:
require.NoError(ctx.T, err) require.NoError(ctx.Context.T, err)
case <-time.After(test.Timeout): case <-time.After(test.Timeout):
ctx.T.Fatal("client not stopping") ctx.Context.T.Fatal("client not stopping")
} }
ctx.assertIsDone() ctx.assertIsDone()
} }
func (ctx *testContext) assertIsDone() { func (ctx *testContext) assertIsDone() {
require.NoError(ctx.T, ctx.Lnd.IsDone()) require.NoError(ctx.Context.T, ctx.Context.Lnd.IsDone())
require.NoError(ctx.T, ctx.store.isDone()) require.NoError(ctx.Context.T, ctx.store.isDone())
select { select {
case <-ctx.statusChan: case <-ctx.statusChan:
ctx.T.Fatalf("not all status updates read") ctx.Context.T.Fatalf("not all status updates read")
default: default:
} }
} }
func (ctx *testContext) assertStored() { func (ctx *testContext) assertStored() {
ctx.T.Helper() ctx.Context.T.Helper()
ctx.store.assertLoopOutStored() ctx.store.assertLoopOutStored()
} }
func (ctx *testContext) assertStorePreimageReveal() { func (ctx *testContext) assertStorePreimageReveal() {
ctx.T.Helper() ctx.Context.T.Helper()
ctx.store.assertStorePreimageReveal() ctx.store.assertStorePreimageReveal()
} }
func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) { func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) {
ctx.T.Helper() ctx.Context.T.Helper()
ctx.store.assertStoreFinished(expectedResult) ctx.store.assertStoreFinished(expectedResult)
} }
func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) { func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) {
ctx.T.Helper() ctx.Context.T.Helper()
for { for {
select { select {
@ -191,7 +191,7 @@ func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) {
return return
} }
case <-time.After(test.Timeout): case <-time.After(test.Timeout):
ctx.T.Fatalf("expected status %v not "+ ctx.Context.T.Fatalf("expected status %v not "+
"received in time", expectedState) "received in time", expectedState)
} }
} }
@ -218,7 +218,7 @@ func (ctx *testContext) publishHtlc(script []byte,
Tx: &htlcTx, Tx: &htlcTx,
}: }:
case <-time.After(test.Timeout): case <-time.After(test.Timeout):
ctx.T.Fatalf("htlc confirmed not consumed") ctx.Context.T.Fatalf("htlc confirmed not consumed")
} }
return wire.OutPoint{ return wire.OutPoint{
@ -238,7 +238,7 @@ func (ctx *testContext) trackPayment(status lnrpc.Payment_PaymentStatus) {
}: }:
case <-time.After(test.Timeout): 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) { func (ctx *testContext) assertPreimagePush(preimage lntypes.Preimage) {
select { select {
case pushedPreimage := <-ctx.serverMock.preimagePush: case pushedPreimage := <-ctx.serverMock.preimagePush:
require.Equal(ctx.T, preimage, pushedPreimage) require.Equal(ctx.Context.T, preimage, pushedPreimage)
case <-time.After(test.Timeout): case <-time.After(test.Timeout):
ctx.T.Fatalf("preimage not pushed") ctx.Context.T.Fatalf("preimage not pushed")
} }
} }

Loading…
Cancel
Save