mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 23:21:12 +02:00
watchtower/multi: move MockSigner+MockPeer to wtmock
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||
"github.com/lightningnetwork/lnd/watchtower/lookout"
|
||||
"github.com/lightningnetwork/lnd/watchtower/wtdb"
|
||||
"github.com/lightningnetwork/lnd/watchtower/wtmock"
|
||||
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
|
||||
)
|
||||
|
||||
@@ -47,55 +48,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
type mockSigner struct {
|
||||
index uint32
|
||||
keys map[keychain.KeyLocator]*btcec.PrivateKey
|
||||
}
|
||||
|
||||
func newMockSigner() *mockSigner {
|
||||
return &mockSigner{
|
||||
keys: make(map[keychain.KeyLocator]*btcec.PrivateKey),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *mockSigner) SignOutputRaw(tx *wire.MsgTx,
|
||||
signDesc *input.SignDescriptor) ([]byte, error) {
|
||||
|
||||
witnessScript := signDesc.WitnessScript
|
||||
amt := signDesc.Output.Value
|
||||
|
||||
privKey, ok := s.keys[signDesc.KeyDesc.KeyLocator]
|
||||
if !ok {
|
||||
panic("cannot sign w/ unknown key")
|
||||
}
|
||||
|
||||
sig, err := txscript.RawTxInWitnessSignature(
|
||||
tx, signDesc.SigHashes, signDesc.InputIndex, amt,
|
||||
witnessScript, signDesc.HashType, privKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sig[:len(sig)-1], nil
|
||||
}
|
||||
|
||||
func (s *mockSigner) ComputeInputScript(tx *wire.MsgTx,
|
||||
signDesc *input.SignDescriptor) (*input.Script, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *mockSigner) addPrivKey(privKey *btcec.PrivateKey) keychain.KeyLocator {
|
||||
keyLoc := keychain.KeyLocator{
|
||||
Index: s.index,
|
||||
}
|
||||
s.index++
|
||||
|
||||
s.keys[keyLoc] = privKey
|
||||
|
||||
return keyLoc
|
||||
}
|
||||
|
||||
func TestJusticeDescriptor(t *testing.T) {
|
||||
const (
|
||||
localAmount = btcutil.Amount(100000)
|
||||
@@ -115,10 +67,10 @@ func TestJusticeDescriptor(t *testing.T) {
|
||||
)
|
||||
|
||||
// Create the signer, and add the revocation and to-remote privkeys.
|
||||
signer := newMockSigner()
|
||||
signer := wtmock.NewMockSigner()
|
||||
var (
|
||||
revKeyLoc = signer.addPrivKey(revSK)
|
||||
toRemoteKeyLoc = signer.addPrivKey(toRemoteSK)
|
||||
revKeyLoc = signer.AddPrivKey(revSK)
|
||||
toRemoteKeyLoc = signer.AddPrivKey(toRemoteSK)
|
||||
)
|
||||
|
||||
// Construct the to-local witness script.
|
||||
|
Reference in New Issue
Block a user