mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
multi: allow mock aux signer to customize sig jobs
This commit is contained in:
parent
6f0d7f9a87
commit
afdd53194b
@ -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),
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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)
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user