multi: context.Background() -> t.Context()

Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
This commit is contained in:
Boris Nagaev committed 2025-08-30 14:13:44 -03:00
1 parent 6ffe257004
commit dee8ad3754
71 files changed
+361 -393

No files matched your search

+11 -11
View File
@@ -153,7 +153,7 @@ func assertUnknownEventFail(t *testing.T, startingState ProtocolState) {
defer closeHarness.stopAndAssert()
closeHarness.sendEventAndExpectFailure(
context.Background(), &unknownEvent{},
t.Context(), &unknownEvent{},
ErrInvalidStateTransition,
)
})
@@ -173,7 +173,7 @@ func assertSpendEventCloseFin(t *testing.T, startingState ProtocolState) {
defer closeHarness.stopAndAssert()
closeHarness.chanCloser.SendEvent(
context.Background(), &SpendEvent{},
t.Context(), &SpendEvent{},
)
closeHarness.assertStateTransitions(&CloseFin{})
@@ -539,7 +539,7 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
initEvent ProtocolEvent, balanceAfterClose, absoluteFee btcutil.Amount,
dustExpect dustExpectation, iteration bool) {
ctx := context.Background()
ctx := r.T.Context()
numFeeCalls := 2
// If we're using the SendOfferEvent as a trigger, we only need to call
@@ -645,7 +645,7 @@ func (r *rbfCloserTestHarness) assertSingleRbfIteration(
initEvent ProtocolEvent, balanceAfterClose, absoluteFee btcutil.Amount,
dustExpect dustExpectation, iteration bool) {
ctx := context.Background()
ctx := r.T.Context()
// We'll now send in the send offer event, which should trigger 1/2 of
// the RBF loop, ending us in the LocalOfferSent state.
@@ -686,7 +686,7 @@ func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
absoluteFee btcutil.Amount, sequence uint32, iteration bool,
sendInit bool) {
ctx := context.Background()
ctx := r.T.Context()
// When we receive the signature below, our local state machine should
// move to finalize the close.
@@ -744,7 +744,7 @@ func assertStateT[T ProtocolState](h *rbfCloserTestHarness) T {
func newRbfCloserTestHarness(t *testing.T,
cfg *harnessCfg) *rbfCloserTestHarness {
ctx := context.Background()
ctx := t.Context()
startingHeight := 200
@@ -850,7 +850,7 @@ func newCloser(t *testing.T, cfg *harnessCfg) *rbfCloserTestHarness {
// TestRbfChannelActiveTransitions tests the transitions of from the
// ChannelActive state.
func TestRbfChannelActiveTransitions(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
localAddr := lnwire.DeliveryAddress(bytes.Repeat([]byte{0x01}, 20))
remoteAddr := lnwire.DeliveryAddress(bytes.Repeat([]byte{0x02}, 20))
@@ -1001,7 +1001,7 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
// shutdown ourselves.
func TestRbfShutdownPendingTransitions(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
startingState := &ShutdownPending{}
@@ -1229,7 +1229,7 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
// transition to the negotiation state.
func TestRbfChannelFlushingTransitions(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
localBalance := lnwire.NewMSatFromSatoshis(10_000)
remoteBalance := lnwire.NewMSatFromSatoshis(50_000)
@@ -1406,7 +1406,7 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
// rate.
func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
localBalance := lnwire.NewMSatFromSatoshis(40_000)
remoteBalance := lnwire.NewMSatFromSatoshis(50_000)
@@ -1687,7 +1687,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
localBalance := lnwire.NewMSatFromSatoshis(40_000)
remoteBalance := lnwire.NewMSatFromSatoshis(50_000)
+1 -1
View File
@@ -3836,7 +3836,7 @@ func TestQuitDuringSignNextCommitment(t *testing.T) {
)
quitDelay := time.Millisecond * 20
quit, quitFunc := context.WithCancel(context.Background())
quit, quitFunc := context.WithCancel(t.Context())
// Alice's channel will be stuck waiting for aux sig job responses until
// we send the quit signal. We add an explicit sleep here so that we can