|
| 1 | +package utils |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/btcsuite/btcd/btcec/v2" |
| 7 | + "github.com/lightninglabs/loop/test" |
| 8 | + "github.com/lightningnetwork/lnd/input" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +// TestMuSig2SignRejectsSingleSigner ensures the helper fails fast with a clear |
| 13 | +// error instead of entering an invalid one-party MuSig2 flow. |
| 14 | +func TestMuSig2SignRejectsSingleSigner(t *testing.T) { |
| 15 | + privKey, pubKey := test.CreateKey(1) |
| 16 | + |
| 17 | + _, err := MuSig2Sign( |
| 18 | + input.MuSig2Version100RC2, |
| 19 | + []*btcec.PrivateKey{privKey}, |
| 20 | + []*btcec.PublicKey{pubKey}, |
| 21 | + &input.MuSig2Tweaks{}, |
| 22 | + [32]byte{}, |
| 23 | + ) |
| 24 | + require.ErrorContains(t, err, "need at least two signing keys") |
| 25 | +} |
| 26 | + |
| 27 | +// TestMuSig2SignRejectsMismatchedKeyCounts ensures we fail before creating any |
| 28 | +// MuSig2 sessions when the signer sets are inconsistent. |
| 29 | +func TestMuSig2SignRejectsMismatchedKeyCounts(t *testing.T) { |
| 30 | + privKey, pubKey1 := test.CreateKey(1) |
| 31 | + _, pubKey2 := test.CreateKey(2) |
| 32 | + |
| 33 | + _, err := MuSig2Sign( |
| 34 | + input.MuSig2Version100RC2, |
| 35 | + []*btcec.PrivateKey{privKey}, |
| 36 | + []*btcec.PublicKey{pubKey1, pubKey2}, |
| 37 | + &input.MuSig2Tweaks{}, |
| 38 | + [32]byte{}, |
| 39 | + ) |
| 40 | + require.ErrorContains(t, err, "must match number of public keys") |
| 41 | +} |
0 commit comments