2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-17 21:25:56 +00:00
loop/test/signer_mock.go
carla 435238ac03
mutli: bump lndclient version
We need the newer version of lndclient to get our synced to chain
state. This requires changes to our test mock, so it is separated
into a different commit. Since lndclient is expanding to be used in
projects other than loop, the client interface is embedded in our
mock rather than implementing functions we do not need. Functions that
we already use in tests are updated accordingly.

Note that while this commit bumps us to a version of lndclient that
defaults to requiring lnd 0.11, we do not bump our required version
yet because we are not using any new endpoints.
2020-08-14 09:25:39 +02:00

60 lines
1.4 KiB
Go

package test
import (
"bytes"
"context"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
)
type mockSigner struct {
lnd *LndMockServices
}
func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
signDescriptors []*lndclient.SignDescriptor) ([][]byte, error) {
s.lnd.SignOutputRawChannel <- SignOutputRawRequest{
Tx: tx,
SignDescriptors: signDescriptors,
}
rawSigs := [][]byte{{1, 2, 3}}
return rawSigs, nil
}
func (s *mockSigner) ComputeInputScript(ctx context.Context, tx *wire.MsgTx,
signDescriptors []*lndclient.SignDescriptor) ([]*input.Script, error) {
return nil, fmt.Errorf("unimplemented")
}
func (s *mockSigner) SignMessage(ctx context.Context, msg []byte,
locator keychain.KeyLocator) ([]byte, error) {
return s.lnd.Signature, nil
}
func (s *mockSigner) VerifyMessage(ctx context.Context, msg, sig []byte,
pubkey [33]byte) (bool, error) {
// Make the mock somewhat functional by asserting that the message and
// signature is what we expect from the mock parameters.
mockAssertion := bytes.Equal(msg, []byte(s.lnd.SignatureMsg)) &&
bytes.Equal(sig, s.lnd.Signature)
return mockAssertion, nil
}
func (s *mockSigner) DeriveSharedKey(context.Context, *btcec.PublicKey,
*keychain.KeyLocator) ([32]byte, error) {
return [32]byte{4, 5, 6}, nil
}