Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions account/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,30 @@ type testHarness struct {
store *mockStore
notifier *mockChainNotifier
wallet *mockWallet
signer *mockSigner
auctioneer *mockAuctioneer
manager Manager
}

func newTestHarness(t *testing.T) *testHarness {
store := newMockStore()
wallet := newMockWallet()
signer := newMockSigner()
notifier := newMockChainNotifier()
auctioneer := newMockAuctioneer()

return &testHarness{
t: t,
store: store,
wallet: wallet,
signer: signer,
notifier: notifier,
auctioneer: auctioneer,
manager: NewManager(&ManagerConfig{
Store: store,
Auctioneer: auctioneer,
Wallet: wallet,
Signer: wallet,
Signer: signer,
ChainNotifier: notifier,
TxSource: wallet,
TxFeeEstimator: wallet,
Expand Down Expand Up @@ -419,14 +422,14 @@ func (h *testHarness) assertAuctioneerMuSig2NoncesReceived() {
h.auctioneer.mu.Lock()
defer h.auctioneer.mu.Unlock()

h.wallet.Lock()
defer h.wallet.Unlock()
h.signer.Lock()
defer h.signer.Unlock()

require.Len(h.t, h.wallet.muSig2Sessions, 0)
require.Len(h.t, h.wallet.muSig2RemovedSessions, 1)
require.Len(h.t, h.signer.muSig2Sessions, 0)
require.Len(h.t, h.signer.muSig2RemovedSessions, 1)

var sessionInfo *input.MuSig2SessionInfo
for _, info := range h.wallet.muSig2RemovedSessions {
for _, info := range h.signer.muSig2RemovedSessions {
sessionInfo = info
break
}
Expand Down
120 changes: 73 additions & 47 deletions account/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet"
Expand Down Expand Up @@ -239,16 +240,12 @@ var _ Auctioneer = (*mockAuctioneer)(nil)
type mockWallet struct {
TxSource
lndclient.WalletKitClient
lndclient.SignerClient
sync.Mutex

txs []lndclient.Transaction
publishChan chan *wire.MsgTx
muSig2Sessions map[input.MuSig2SessionID]*input.MuSig2SessionInfo
muSig2RemovedSessions map[input.MuSig2SessionID]*input.MuSig2SessionInfo
utxos []*lnwallet.Utxo
fundPsbt *psbt.Packet
fundPsbtChangeIdx int32
txs []lndclient.Transaction
publishChan chan *wire.MsgTx
utxos []*lnwallet.Utxo
fundPsbt *psbt.Packet
fundPsbtChangeIdx int32

sendOutputs func(context.Context, []*wire.TxOut,
chainfee.SatPerKWeight) (*wire.MsgTx, error)
Expand All @@ -259,26 +256,20 @@ var _ lndclient.WalletKitClient = (*mockWallet)(nil)
func newMockWallet() *mockWallet {
return &mockWallet{
publishChan: make(chan *wire.MsgTx, 1),
muSig2Sessions: make(
map[input.MuSig2SessionID]*input.MuSig2SessionInfo,
),
muSig2RemovedSessions: make(
map[input.MuSig2SessionID]*input.MuSig2SessionInfo,
),
}
}

func (w *mockWallet) DeriveNextKey(ctx context.Context,
family int32) (*keychain.KeyDescriptor, error) {
func (w *mockWallet) RawClientWithMacAuth(
ctx context.Context) (context.Context, time.Duration,
walletrpc.WalletKitClient) {

return testTraderKeyDesc, nil
return ctx, 0, nil
}

func (w *mockWallet) DeriveSharedKey(ctx context.Context,
ephemeralKey *btcec.PublicKey,
keyLocator *keychain.KeyLocator) ([32]byte, error) {
func (w *mockWallet) DeriveNextKey(ctx context.Context,
family int32) (*keychain.KeyDescriptor, error) {

return sharedSecret, nil
return testTraderKeyDesc, nil
}

func (w *mockWallet) PublishTransaction(ctx context.Context, tx *wire.MsgTx,
Expand Down Expand Up @@ -348,24 +339,6 @@ func (w *mockWallet) ReleaseOutput(_ context.Context, lockID wtxmgr.LockID,
return nil
}

func (w *mockWallet) SignOutputRaw(context.Context, *wire.MsgTx,
[]*lndclient.SignDescriptor, []*wire.TxOut) ([][]byte, error) {

return [][]byte{[]byte("trader sig")}, nil
}

func (w *mockWallet) ComputeInputScript(context.Context, *wire.MsgTx,
[]*lndclient.SignDescriptor, []*wire.TxOut) ([]*input.Script, error) {

return []*input.Script{{
SigScript: []byte("input sig script"),
Witness: wire.TxWitness{
[]byte("input"),
[]byte("witness"),
},
}}, nil
}

func (w *mockWallet) EstimateFeeRate(_ context.Context,
_ int32) (chainfee.SatPerKWeight, error) {

Expand Down Expand Up @@ -402,7 +375,7 @@ func (w *mockWallet) SignPsbt(_ context.Context,
}

func (w *mockWallet) FinalizePsbt(_ context.Context, packet *psbt.Packet,
account string) (*psbt.Packet, *wire.MsgTx, error) {
_ string) (*psbt.Packet, *wire.MsgTx, error) {

// Just copy over any sigs we might have. This is copy/paste code from
// the psbt Finalizer, minus the IsComplete() check.
Expand Down Expand Up @@ -446,9 +419,55 @@ func (w *mockWallet) FinalizePsbt(_ context.Context, packet *psbt.Packet,
return packet, packet.UnsignedTx, nil
}

type mockSigner struct {
lndclient.SignerClient
sync.Mutex

muSig2Sessions map[input.MuSig2SessionID]*input.MuSig2SessionInfo
muSig2RemovedSessions map[input.MuSig2SessionID]*input.MuSig2SessionInfo
}

var _ lndclient.SignerClient = (*mockSigner)(nil)

func newMockSigner() *mockSigner {
return &mockSigner{
muSig2Sessions: make(
map[input.MuSig2SessionID]*input.MuSig2SessionInfo,
),
muSig2RemovedSessions: make(
map[input.MuSig2SessionID]*input.MuSig2SessionInfo,
),
}
}

func (w *mockSigner) DeriveSharedKey(ctx context.Context,
ephemeralKey *btcec.PublicKey,
keyLocator *keychain.KeyLocator) ([32]byte, error) {

return sharedSecret, nil
}

func (w *mockSigner) SignOutputRaw(context.Context, *wire.MsgTx,
[]*lndclient.SignDescriptor, []*wire.TxOut) ([][]byte, error) {

return [][]byte{[]byte("trader sig")}, nil
}

func (w *mockSigner) ComputeInputScript(context.Context, *wire.MsgTx,
[]*lndclient.SignDescriptor, []*wire.TxOut) ([]*input.Script, error) {

return []*input.Script{{
SigScript: []byte("input sig script"),
Witness: wire.TxWitness{
[]byte("input"),
[]byte("witness"),
},
}}, nil
}

// MuSig2CreateSession creates a new musig session with the key and signers
// provided.
func (w *mockWallet) MuSig2CreateSession(_ context.Context,
func (w *mockSigner) MuSig2CreateSession(_ context.Context,
version input.MuSig2Version, _ *keychain.KeyLocator, _ [][]byte,
opts ...lndclient.MuSig2SessionOpts) (*input.MuSig2SessionInfo, error) {

Expand Down Expand Up @@ -485,8 +504,8 @@ func (w *mockWallet) MuSig2CreateSession(_ context.Context,

// MuSig2RegisterNonces registers additional public nonces for a musig2 session.
// It returns a boolean indicating whether we have all of our nonces present.
func (w *mockWallet) MuSig2RegisterNonces(_ context.Context, sessionID [32]byte,
nonces [][66]byte) (bool, error) {
func (w *mockSigner) MuSig2RegisterNonces(_ context.Context, _ [32]byte,
_ [][66]byte) (bool, error) {

return true, nil
}
Expand All @@ -495,7 +514,7 @@ func (w *mockWallet) MuSig2RegisterNonces(_ context.Context, sessionID [32]byte,
// message. This can only be called once all public nonces have been created. If
// the caller will not be responsible for combining the signatures, the cleanup
// bool should be set.
func (w *mockWallet) MuSig2Sign(_ context.Context, sessionID [32]byte,
func (w *mockSigner) MuSig2Sign(_ context.Context, sessionID [32]byte,
_ [32]byte, cleanup bool) ([]byte, error) {

var (
Expand All @@ -521,7 +540,7 @@ func (w *mockWallet) MuSig2Sign(_ context.Context, sessionID [32]byte,
// MuSig2CombineSig combines the given partial signature(s) with the local one,
// if it already exists. Once a partial signature of all participants are
// registered, the final signature will be combined and returned.
func (w *mockWallet) MuSig2CombineSig(_ context.Context, sessionID [32]byte,
func (w *mockSigner) MuSig2CombineSig(_ context.Context, sessionID [32]byte,
_ [][]byte) (bool, []byte, error) {

var (
Expand All @@ -544,7 +563,7 @@ func (w *mockWallet) MuSig2CombineSig(_ context.Context, sessionID [32]byte,
}

// MuSig2Cleanup removes a session from memory to free up resources.
func (w *mockWallet) MuSig2Cleanup(_ context.Context,
func (w *mockSigner) MuSig2Cleanup(_ context.Context,
sessionID [32]byte) error {

w.Lock()
Expand Down Expand Up @@ -580,6 +599,13 @@ func newMockChainNotifier() *mockChainNotifier {
}
}

func (n *mockChainNotifier) RawClientWithMacAuth(
ctx context.Context) (context.Context, time.Duration,
chainrpc.ChainNotifierClient) {

return ctx, 0, nil
}

func (n *mockChainNotifier) RegisterConfirmationsNtfn(ctx context.Context,
txid *chainhash.Hash, pkScript []byte, numConfs, heightHint int32,
opts ...lndclient.NotifierOption) (chan *chainntnfs.TxConfirmation,
Expand Down
2 changes: 1 addition & 1 deletion gen/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.3-bookworm
FROM golang:1.22.6-bookworm

RUN go install go.uber.org/mock/mockgen@v0.4.0

Expand Down
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
module github.com/lightninglabs/pool

require (
github.com/btcsuite/btcd v0.24.2-beta.rc1.0.20240403021926-ae5533602c46
github.com/btcsuite/btcd/btcec/v2 v2.3.3
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/btcsuite/btcd/btcutil/psbt v1.1.8
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet v0.16.10-0.20240410030101-6fe19a472a62
github.com/btcsuite/btcwallet v0.16.10-0.20240809133323-7d3434c65ae2
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1
github.com/btcsuite/btcwallet/wtxmgr v1.5.3
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.3.2-beta
github.com/lightninglabs/lndclient v0.18.0-1
github.com/lightninglabs/lndclient v0.18.4-0
github.com/lightninglabs/pool/auctioneerrpc v1.1.2
github.com/lightninglabs/pool/poolrpc v1.0.0
github.com/lightningnetwork/lnd v0.18.0-beta.1
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241011124628-ca3bde901eb8
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/kvdb v1.4.8
github.com/lightningnetwork/lnd/fn v1.2.1
github.com/lightningnetwork/lnd/kvdb v1.4.10
github.com/lightningnetwork/lnd/tlv v1.2.6
github.com/lightningnetwork/lnd/tor v1.1.2
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -93,23 +94,23 @@ require (
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.2 // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jackpal/gateway v1.0.5 // indirect
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jrick/logrotate v1.0.0 // indirect
github.com/jrick/logrotate v1.1.2 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
github.com/lightningnetwork/lnd/fn v1.0.5 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.4 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.2 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.4 // indirect
github.com/lightningnetwork/lnd/ticker v1.1.1 // indirect
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down Expand Up @@ -185,7 +186,7 @@ require (
modernc.org/libc v1.49.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.29.8 // indirect
modernc.org/sqlite v1.29.10 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
Expand All @@ -199,4 +200,4 @@ replace github.com/lightninglabs/pool/auctioneerrpc => ./auctioneerrpc

replace github.com/lightninglabs/pool/poolrpc => ./poolrpc

go 1.22.3
go 1.22.6
Loading