diff --git a/funding/manager_test.go b/funding/manager_test.go index 633b3b89a..a1b33d43b 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -568,7 +568,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey, &lnwallet.MockAuxLeafStore{}, ), AuxSigner: fn.Some[lnwallet.AuxSigner]( - &lnwallet.MockAuxSigner{}, + lnwallet.NewAuxSignerMock(lnwallet.EmptyMockJobHandler), ), } diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 5e9028578..ac18c8be6 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -3469,8 +3469,9 @@ func TestChanSyncOweCommitmentAuxSigner(t *testing.T) { aliceChannel, bobChannel, err := CreateTestChannels(t, chanType) require.NoError(t, err, "unable to create test channels") - // We'll now manually attach an aux signer to Alice's channel. - auxSigner := &MockAuxSigner{} + // We'll now manually attach an aux signer to Alice's channel. We'll + // set each aux sig job to receive an instant response. + auxSigner := NewAuxSignerMock(EmptyMockJobHandler) aliceChannel.auxSigner = fn.Some[AuxSigner](auxSigner) var fakeOnionBlob [lnwire.OnionPacketSize]byte @@ -3494,8 +3495,8 @@ func TestChanSyncOweCommitmentAuxSigner(t *testing.T) { _, err = aliceChannel.AddHTLC(h, nil) require.NoError(t, err, "unable to recv bob's htlc: %v", err) - // We'll set up the mock to expect calls to PackSigs and also - // SubmitSubmitSecondLevelSigBatch. + // We'll set up the mock aux signer to expect calls to PackSigs and also + // SubmitSecondLevelSigBatch. var sigBlobBuf bytes.Buffer sigBlob := testSigBlob{ BlobInt: tlv.NewPrimitiveRecord[tlv.TlvType65634, uint16](5), diff --git a/lnwallet/mock.go b/lnwallet/mock.go index 68d5dcca7..e588c91c0 100644 --- a/lnwallet/mock.go +++ b/lnwallet/mock.go @@ -435,9 +435,26 @@ func (*MockAuxLeafStore) ApplyHtlcView( return fn.Ok(fn.None[tlv.Blob]()) } +// EmptyMockJobHandler is a mock job handler that just sends an empty response +// to all jobs. +func EmptyMockJobHandler(jobs []AuxSigJob) { + for _, sigJob := range jobs { + sigJob.Resp <- AuxSigJobResp{} + } +} + // MockAuxSigner is a mock implementation of the AuxSigner interface. type MockAuxSigner struct { mock.Mock + + jobHandlerFunc func([]AuxSigJob) +} + +// NewAuxSignerMock creates a new mock aux signer with the given job handler. +func NewAuxSignerMock(jobHandler func([]AuxSigJob)) *MockAuxSigner { + return &MockAuxSigner{ + jobHandlerFunc: jobHandler, + } } // SubmitSecondLevelSigBatch takes a batch of aux sign jobs and @@ -447,10 +464,8 @@ func (a *MockAuxSigner) SubmitSecondLevelSigBatch(chanState AuxChanState, args := a.Called(chanState, tx, jobs) - // While we return, we'll also send back an instant response for the - // set of jobs. - for _, sigJob := range jobs { - sigJob.Resp <- AuxSigJobResp{} + if a.jobHandlerFunc != nil { + a.jobHandlerFunc(jobs) } return args.Error(0) diff --git a/lnwallet/test_utils.go b/lnwallet/test_utils.go index d4f0d05ae..b450b3b30 100644 --- a/lnwallet/test_utils.go +++ b/lnwallet/test_utils.go @@ -597,7 +597,7 @@ func ForceStateTransition(chanA, chanB *LightningChannel) error { } func NewDefaultAuxSignerMock(t *testing.T) *MockAuxSigner { - auxSigner := &MockAuxSigner{} + auxSigner := NewAuxSignerMock(EmptyMockJobHandler) type testSigBlob struct { BlobInt tlv.RecordT[tlv.TlvType65634, uint16] diff --git a/peer/test_utils.go b/peer/test_utils.go index 948a22c4e..cce8055bd 100644 --- a/peer/test_utils.go +++ b/peer/test_utils.go @@ -305,7 +305,9 @@ func createTestPeerWithChannel(t *testing.T, updateChan func(a, channelAlice, err := lnwallet.NewLightningChannel( aliceSigner, aliceChannelState, alicePool, lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}), - lnwallet.WithAuxSigner(&lnwallet.MockAuxSigner{}), + lnwallet.WithAuxSigner(lnwallet.NewAuxSignerMock( + lnwallet.EmptyMockJobHandler, + )), ) if err != nil { return nil, err @@ -319,7 +321,9 @@ func createTestPeerWithChannel(t *testing.T, updateChan func(a, channelBob, err := lnwallet.NewLightningChannel( bobSigner, bobChannelState, bobPool, lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}), - lnwallet.WithAuxSigner(&lnwallet.MockAuxSigner{}), + lnwallet.WithAuxSigner(lnwallet.NewAuxSignerMock( + lnwallet.EmptyMockJobHandler, + )), ) if err != nil { return nil, err