multi: allow mock aux signer to customize sig jobs

This commit is contained in:
Jonathan Harvey-Buschel 2024-10-17 13:38:27 +02:00 committed by Oliver Gugger
parent 6f0d7f9a87
commit afdd53194b
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
5 changed files with 32 additions and 12 deletions

View File

@ -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),
),
}

View File

@ -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),

View File

@ -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)

View File

@ -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]

View File

@ -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