@@ -3,39 +3,66 @@ package utils
33import (
44 "testing"
55
6- "github.com/btcsuite/btcd/btcec/v2"
76 "github.com/lightninglabs/loop/test"
87 "github.com/lightningnetwork/lnd/input"
98 "github.com/stretchr/testify/require"
109)
1110
11+ // rawKeys returns serialized private keys for the given test seeds.
12+ func rawKeys (seeds ... int32 ) [][32 ]byte {
13+ keys := make ([][32 ]byte , len (seeds ))
14+ for i , seed := range seeds {
15+ privKey , _ := test .CreateKey (seed )
16+ copy (keys [i ][:], privKey .Serialize ())
17+ }
18+
19+ return keys
20+ }
21+
1222// TestMuSig2SignRejectsSingleSigner ensures the helper fails fast with a clear
1323// error instead of entering an invalid one-party MuSig2 flow.
1424func TestMuSig2SignRejectsSingleSigner (t * testing.T ) {
15- privKey , pubKey := test .CreateKey (1 )
16-
1725 _ , err := MuSig2Sign (
1826 input .MuSig2Version100RC2 ,
19- []* btcec.PrivateKey {privKey },
20- []* btcec.PublicKey {pubKey },
27+ rawKeys (1 ),
2128 & input.MuSig2Tweaks {},
2229 [32 ]byte {},
2330 )
2431 require .ErrorContains (t , err , "need at least two signing keys" )
2532}
2633
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 )
34+ // TestMuSig2SignSupportsVersions verifies the helper works with the supported
35+ // MuSig2 versions used in Loop.
36+ func TestMuSig2SignSupportsVersions (t * testing.T ) {
37+ t .Parallel ()
3238
33- _ , err := MuSig2Sign (
39+ for _ , version := range []input.MuSig2Version {
40+ input .MuSig2Version040 ,
3441 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" )
42+ } {
43+ t .Run (testVersionName (version ), func (t * testing.T ) {
44+ t .Parallel ()
45+
46+ sig , err := MuSig2Sign (
47+ version , rawKeys (1 , 2 ), & input.MuSig2Tweaks {},
48+ [32 ]byte {},
49+ )
50+ require .NoError (t , err )
51+ require .Len (t , sig , 64 )
52+ })
53+ }
54+ }
55+
56+ // testVersionName returns a stable subtest name for a MuSig2 version.
57+ func testVersionName (version input.MuSig2Version ) string {
58+ switch version {
59+ case input .MuSig2Version040 :
60+ return "MuSig2 0.4"
61+
62+ case input .MuSig2Version100RC2 :
63+ return "MuSig2 1.0RC2"
64+
65+ default :
66+ return "unknown"
67+ }
4168}
0 commit comments