Skip to content

Commit cf6f8de

Browse files
committed
asset: move unit test TestGroupKeyIsEqual to group_key_test.go
1 parent ff293be commit cf6f8de

File tree

2 files changed

+129
-129
lines changed

2 files changed

+129
-129
lines changed

asset/asset_test.go

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/lightninglabs/taproot-assets/internal/test"
1919
"github.com/lightninglabs/taproot-assets/mssmt"
2020
"github.com/lightningnetwork/lnd/input"
21-
"github.com/lightningnetwork/lnd/keychain"
2221
"github.com/lightningnetwork/lnd/tlv"
2322
"github.com/stretchr/testify/require"
2423
"pgregory.net/rapid"
@@ -111,134 +110,6 @@ var (
111110
}
112111
)
113112

114-
// TestGroupKeyIsEqual tests that GroupKey.IsEqual is correct.
115-
func TestGroupKeyIsEqual(t *testing.T) {
116-
t.Parallel()
117-
118-
testKey := &GroupKey{
119-
RawKey: keychain.KeyDescriptor{
120-
// Fill in some non-defaults.
121-
KeyLocator: keychain.KeyLocator{
122-
Family: keychain.KeyFamilyMultiSig,
123-
Index: 1,
124-
},
125-
PubKey: pubKey,
126-
},
127-
GroupPubKey: *pubKey,
128-
Witness: sigWitness,
129-
}
130-
131-
pubKeyCopy := *pubKey
132-
133-
tests := []struct {
134-
a, b *GroupKey
135-
equal bool
136-
}{
137-
{
138-
a: nil,
139-
b: nil,
140-
equal: true,
141-
},
142-
{
143-
a: &GroupKey{},
144-
b: &GroupKey{},
145-
equal: true,
146-
},
147-
{
148-
a: nil,
149-
b: &GroupKey{},
150-
equal: false,
151-
},
152-
{
153-
a: testKey,
154-
b: &GroupKey{
155-
GroupPubKey: *pubKey,
156-
},
157-
equal: false,
158-
},
159-
{
160-
a: testKey,
161-
b: &GroupKey{
162-
GroupPubKey: testKey.GroupPubKey,
163-
Witness: testKey.Witness,
164-
},
165-
equal: false,
166-
},
167-
{
168-
a: testKey,
169-
b: &GroupKey{
170-
RawKey: keychain.KeyDescriptor{
171-
KeyLocator: testKey.RawKey.KeyLocator,
172-
PubKey: nil,
173-
},
174-
175-
GroupPubKey: testKey.GroupPubKey,
176-
Witness: testKey.Witness,
177-
},
178-
equal: false,
179-
},
180-
{
181-
a: testKey,
182-
b: &GroupKey{
183-
RawKey: keychain.KeyDescriptor{
184-
PubKey: &pubKeyCopy,
185-
},
186-
187-
GroupPubKey: testKey.GroupPubKey,
188-
Witness: testKey.Witness,
189-
},
190-
equal: false,
191-
},
192-
{
193-
a: testKey,
194-
b: &GroupKey{
195-
RawKey: keychain.KeyDescriptor{
196-
KeyLocator: testKey.RawKey.KeyLocator,
197-
PubKey: &pubKeyCopy,
198-
},
199-
200-
GroupPubKey: testKey.GroupPubKey,
201-
Witness: testKey.Witness,
202-
},
203-
equal: true,
204-
},
205-
{
206-
a: &GroupKey{
207-
GroupPubKey: testKey.GroupPubKey,
208-
Witness: testKey.Witness,
209-
},
210-
b: &GroupKey{
211-
GroupPubKey: testKey.GroupPubKey,
212-
Witness: testKey.Witness,
213-
},
214-
equal: true,
215-
},
216-
{
217-
a: &GroupKey{
218-
RawKey: keychain.KeyDescriptor{
219-
KeyLocator: testKey.RawKey.KeyLocator,
220-
},
221-
GroupPubKey: testKey.GroupPubKey,
222-
Witness: testKey.Witness,
223-
},
224-
b: &GroupKey{
225-
RawKey: keychain.KeyDescriptor{
226-
KeyLocator: testKey.RawKey.KeyLocator,
227-
},
228-
GroupPubKey: testKey.GroupPubKey,
229-
Witness: testKey.Witness,
230-
},
231-
equal: true,
232-
},
233-
}
234-
235-
for _, testCase := range tests {
236-
testCase := testCase
237-
require.Equal(t, testCase.equal, testCase.a.IsEqual(testCase.b))
238-
require.Equal(t, testCase.equal, testCase.b.IsEqual(testCase.a))
239-
}
240-
}
241-
242113
// TestGenesisAssetClassification tests that the multiple forms of genesis asset
243114
// are recognized correctly.
244115
func TestGenesisAssetClassification(t *testing.T) {

asset/group_key_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/btcsuite/btcd/wire"
1212
"github.com/lightninglabs/taproot-assets/fn"
1313
"github.com/lightninglabs/taproot-assets/internal/test"
14+
"github.com/lightningnetwork/lnd/keychain"
1415
"github.com/stretchr/testify/require"
1516
"pgregory.net/rapid"
1617
)
@@ -391,3 +392,131 @@ func TestNonSpendableLeafScript(t *testing.T) {
391392
})
392393
}
393394
}
395+
396+
// TestGroupKeyIsEqual tests that GroupKey.IsEqual is correct.
397+
func TestGroupKeyIsEqual(t *testing.T) {
398+
t.Parallel()
399+
400+
testKey := &GroupKey{
401+
RawKey: keychain.KeyDescriptor{
402+
// Fill in some non-defaults.
403+
KeyLocator: keychain.KeyLocator{
404+
Family: keychain.KeyFamilyMultiSig,
405+
Index: 1,
406+
},
407+
PubKey: pubKey,
408+
},
409+
GroupPubKey: *pubKey,
410+
Witness: sigWitness,
411+
}
412+
413+
pubKeyCopy := *pubKey
414+
415+
tests := []struct {
416+
a, b *GroupKey
417+
equal bool
418+
}{
419+
{
420+
a: nil,
421+
b: nil,
422+
equal: true,
423+
},
424+
{
425+
a: &GroupKey{},
426+
b: &GroupKey{},
427+
equal: true,
428+
},
429+
{
430+
a: nil,
431+
b: &GroupKey{},
432+
equal: false,
433+
},
434+
{
435+
a: testKey,
436+
b: &GroupKey{
437+
GroupPubKey: *pubKey,
438+
},
439+
equal: false,
440+
},
441+
{
442+
a: testKey,
443+
b: &GroupKey{
444+
GroupPubKey: testKey.GroupPubKey,
445+
Witness: testKey.Witness,
446+
},
447+
equal: false,
448+
},
449+
{
450+
a: testKey,
451+
b: &GroupKey{
452+
RawKey: keychain.KeyDescriptor{
453+
KeyLocator: testKey.RawKey.KeyLocator,
454+
PubKey: nil,
455+
},
456+
457+
GroupPubKey: testKey.GroupPubKey,
458+
Witness: testKey.Witness,
459+
},
460+
equal: false,
461+
},
462+
{
463+
a: testKey,
464+
b: &GroupKey{
465+
RawKey: keychain.KeyDescriptor{
466+
PubKey: &pubKeyCopy,
467+
},
468+
469+
GroupPubKey: testKey.GroupPubKey,
470+
Witness: testKey.Witness,
471+
},
472+
equal: false,
473+
},
474+
{
475+
a: testKey,
476+
b: &GroupKey{
477+
RawKey: keychain.KeyDescriptor{
478+
KeyLocator: testKey.RawKey.KeyLocator,
479+
PubKey: &pubKeyCopy,
480+
},
481+
482+
GroupPubKey: testKey.GroupPubKey,
483+
Witness: testKey.Witness,
484+
},
485+
equal: true,
486+
},
487+
{
488+
a: &GroupKey{
489+
GroupPubKey: testKey.GroupPubKey,
490+
Witness: testKey.Witness,
491+
},
492+
b: &GroupKey{
493+
GroupPubKey: testKey.GroupPubKey,
494+
Witness: testKey.Witness,
495+
},
496+
equal: true,
497+
},
498+
{
499+
a: &GroupKey{
500+
RawKey: keychain.KeyDescriptor{
501+
KeyLocator: testKey.RawKey.KeyLocator,
502+
},
503+
GroupPubKey: testKey.GroupPubKey,
504+
Witness: testKey.Witness,
505+
},
506+
b: &GroupKey{
507+
RawKey: keychain.KeyDescriptor{
508+
KeyLocator: testKey.RawKey.KeyLocator,
509+
},
510+
GroupPubKey: testKey.GroupPubKey,
511+
Witness: testKey.Witness,
512+
},
513+
equal: true,
514+
},
515+
}
516+
517+
for _, testCase := range tests {
518+
testCase := testCase
519+
require.Equal(t, testCase.equal, testCase.a.IsEqual(testCase.b))
520+
require.Equal(t, testCase.equal, testCase.b.IsEqual(testCase.a))
521+
}
522+
}

0 commit comments

Comments
 (0)