Skip to content

Commit 7943a3f

Browse files
committed
multi: remove unneeded param from RandPrivKey
1 parent 4e3e4c8 commit 7943a3f

File tree

14 files changed

+51
-43
lines changed

14 files changed

+51
-43
lines changed

address/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func RandAddr(t testing.TB, params *ChainParams,
3333
proofCourierAddr url.URL) (*AddrWithKeyInfo,
3434
*asset.Genesis, *asset.GroupKey) {
3535

36-
scriptKeyPriv := test.RandPrivKey(t)
36+
scriptKeyPriv := test.RandPrivKey()
3737
scriptKey := asset.NewScriptKeyBip86(keychain.KeyDescriptor{
3838
PubKey: scriptKeyPriv.PubKey(),
3939
KeyLocator: keychain.KeyLocator{
@@ -42,7 +42,7 @@ func RandAddr(t testing.TB, params *ChainParams,
4242
},
4343
})
4444

45-
internalKey := test.RandPrivKey(t)
45+
internalKey := test.RandPrivKey()
4646

4747
genesis := asset.RandGenesis(t, asset.Type(test.RandInt31n(2)))
4848
amount := test.RandInt[uint64]()

asset/asset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ func TestAssetGroupKey(t *testing.T) {
857857
func TestDeriveGroupKey(t *testing.T) {
858858
t.Parallel()
859859

860-
groupPriv := test.RandPrivKey(t)
860+
groupPriv := test.RandPrivKey()
861861
groupPub := groupPriv.PubKey()
862862
groupKeyDesc := test.PubToKeyDesc(groupPub)
863863
genSigner := NewMockGenesisSigner(groupPriv)

asset/mock.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lightningnetwork/lnd/keychain"
2020
"github.com/lightningnetwork/lnd/tlv"
2121
"github.com/stretchr/testify/require"
22+
"pgregory.net/rapid"
2223
)
2324

2425
// RandGenesis creates a random genesis for testing.
@@ -38,17 +39,24 @@ func RandGenesis(t testing.TB, assetType Type) Genesis {
3839
}
3940

4041
// RandGroupKey creates a random group key for testing.
41-
func RandGroupKey(t testing.TB, genesis Genesis, newAsset *Asset) *GroupKey {
42-
groupKey, _ := RandGroupKeyWithSigner(t, genesis, newAsset)
42+
func RandGroupKey(t rapid.TB, genesis Genesis, newAsset *Asset) *GroupKey {
43+
groupKey, _ := RandGroupKeyWithSigner(t, nil, genesis, newAsset)
4344
return groupKey
4445
}
4546

4647
// RandGroupKeyWithSigner creates a random group key for testing, and provides
4748
// the signer for reissuing assets into the same group.
48-
func RandGroupKeyWithSigner(t testing.TB, genesis Genesis,
49-
newAsset *Asset) (*GroupKey, []byte) {
49+
func RandGroupKeyWithSigner(t rapid.TB, privKey *btcec.PrivateKey,
50+
genesis Genesis, newAsset *Asset) (*GroupKey, []byte) {
5051

51-
privateKey := test.RandPrivKey(t)
52+
var privateKey *btcec.PrivateKey
53+
switch {
54+
case privKey != nil:
55+
privateKey = privKey
56+
57+
default:
58+
privateKey = test.RandPrivKey()
59+
}
5260

5361
genSigner := NewMockGenesisSigner(privateKey)
5462
genBuilder := MockGroupTxBuilder{}
@@ -352,7 +360,7 @@ func AssetCustomGroupKey(t *testing.T, useHashLock, BIP86, keySpend,
352360
scriptKey := RandScriptKey(t)
353361
protoAsset := RandAssetWithValues(t, gen, nil, scriptKey)
354362

355-
groupPrivKey := test.RandPrivKey(t)
363+
groupPrivKey := test.RandPrivKey()
356364
groupInternalKey := groupPrivKey.PubKey()
357365
genSigner := NewMockGenesisSigner(groupPrivKey)
358366
genBuilder := MockGroupTxBuilder{}
@@ -430,12 +438,12 @@ func AssetCustomGroupKey(t *testing.T, useHashLock, BIP86, keySpend,
430438

431439
// RandScriptKey creates a random script key for testing.
432440
func RandScriptKey(t testing.TB) ScriptKey {
433-
return NewScriptKey(test.RandPrivKey(t).PubKey())
441+
return NewScriptKey(test.RandPrivKey().PubKey())
434442
}
435443

436444
// RandSerializedKey creates a random serialized key for testing.
437445
func RandSerializedKey(t testing.TB) SerializedKey {
438-
return ToSerialized(test.RandPrivKey(t).PubKey())
446+
return ToSerialized(test.RandPrivKey().PubKey())
439447
}
440448

441449
// RandID creates a random asset ID.

commitment/commitment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func randAssetDetails(t *testing.T, assetType asset.Type) *AssetDetails {
5353
Version: assetVersion,
5454
Type: assetType,
5555
ScriptKey: keychain.KeyDescriptor{
56-
PubKey: test.RandPrivKey(t).PubKey(),
56+
PubKey: test.RandPrivKey().PubKey(),
5757
},
5858
Amount: &amount,
5959
LockTime: rand.Uint64(),
@@ -127,7 +127,7 @@ func TestNewAssetCommitment(t *testing.T) {
127127
)
128128
group1Anchor := randAsset(t, genesis1, nil)
129129
groupKey1, group1PrivBytes := asset.RandGroupKeyWithSigner(
130-
t, genesis1, group1Anchor,
130+
t, nil, genesis1, group1Anchor,
131131
)
132132
group1Anchor = asset.NewAssetNoErr(
133133
t, genesis1, group1Anchor.Amount, group1Anchor.LockTime,
@@ -289,7 +289,7 @@ func TestMintTapCommitment(t *testing.T) {
289289
genesisNormal := asset.RandGenesis(t, asset.Normal)
290290
genesisCollectible := asset.RandGenesis(t, asset.Collectible)
291291
pubKey := keychain.KeyDescriptor{
292-
PubKey: test.RandPrivKey(t).PubKey(),
292+
PubKey: test.RandPrivKey().PubKey(),
293293
}
294294

295295
testCases := []struct {
@@ -1008,7 +1008,7 @@ func TestUpdateAssetCommitment(t *testing.T) {
10081008
genesis1collect.Type = asset.Collectible
10091009
group1Anchor := randAsset(t, genesis1, nil)
10101010
groupKey1, group1PrivBytes := asset.RandGroupKeyWithSigner(
1011-
t, genesis1, group1Anchor,
1011+
t, nil, genesis1, group1Anchor,
10121012
)
10131013
group1Anchor = asset.NewAssetNoErr(
10141014
t, genesis1, group1Anchor.Amount, group1Anchor.LockTime,

commitment/taproot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestTapscriptPreimage(t *testing.T) {
2727

2828
// Create a script tree that we'll use for our tapscript sibling test
2929
// cases.
30-
scriptInternalKey := test.RandPrivKey(t).PubKey()
30+
scriptInternalKey := test.RandPrivKey().PubKey()
3131
leaf1 := test.ScriptHashLock(t, []byte("foobar"))
3232
leaf1Hash := leaf1.TapHash()
3333
leaf2 := test.ScriptSchnorrSig(t, scriptInternalKey)

internal/test/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func RandOp(t testing.TB) wire.OutPoint {
9898
return op
9999
}
100100

101-
func RandPrivKey(_ testing.TB) *btcec.PrivateKey {
101+
func RandPrivKey() *btcec.PrivateKey {
102102
priv, _ := btcec.PrivKeyFromBytes(RandBytes(32))
103103
return priv
104104
}
@@ -139,7 +139,7 @@ func SchnorrKeysEqual(t testing.TB, a, b *btcec.PublicKey) bool {
139139
}
140140

141141
func RandPubKey(t testing.TB) *btcec.PublicKey {
142-
return SchnorrPubKey(t, RandPrivKey(t))
142+
return SchnorrPubKey(t, RandPrivKey())
143143
}
144144

145145
func RandCommitmentKeyRing(t *testing.T) lnwallet.CommitmentKeyRing {

itest/assets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func testMintAssetsWithTapscriptSibling(t *harnessTest) {
417417
defer cancel()
418418

419419
// Build the tapscript tree.
420-
sigLockPrivKey := test.RandPrivKey(t.t)
420+
sigLockPrivKey := test.RandPrivKey()
421421
hashLockPreimage := []byte("foobar")
422422
hashLockLeaf := test.ScriptHashLock(t.t, hashLockPreimage)
423423
sigLeaf := test.ScriptSchnorrSig(t.t, sigLockPrivKey.PubKey())

proof/append_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
118118
require.NoError(t, err)
119119

120120
// Transfer the asset to a new owner.
121-
recipientPrivKey := test.RandPrivKey(t)
121+
recipientPrivKey := test.RandPrivKey()
122122
newAsset := *genesisProof.Asset.Copy()
123123
newAsset.ScriptKey = asset.NewScriptKeyBip86(
124124
test.PubToKeyDesc(recipientPrivKey.PubKey()),
@@ -156,7 +156,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
156156
// Add a P2TR change output to test the exclusion proof.
157157
var changeInternalKey *btcec.PublicKey
158158
if withBip86Change {
159-
changeInternalKey = test.RandPrivKey(t).PubKey()
159+
changeInternalKey = test.RandPrivKey().PubKey()
160160
changeTaprootKey := txscript.ComputeTaprootKeyNoScript(
161161
changeInternalKey,
162162
)
@@ -221,9 +221,9 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
221221
}
222222

223223
// If we want to test splitting, we do that now, as a second transfer.
224-
split1PrivKey := test.RandPrivKey(t)
225-
split2PrivKey := test.RandPrivKey(t)
226-
split3PrivKey := test.RandPrivKey(t)
224+
split1PrivKey := test.RandPrivKey()
225+
split2PrivKey := test.RandPrivKey()
226+
split3PrivKey := test.RandPrivKey()
227227
transitionOutpoint := wire.OutPoint{
228228
Hash: transitionProof.AnchorTx.TxHash(),
229229
Index: transitionProof.InclusionProof.OutputIndex,

proof/mint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestNewMintingBlobs(t *testing.T) {
2222

2323
// First, we'll create a fake, but legit looking set of minting params
2424
// to generate a proof with.
25-
genesisPrivKey := test.RandPrivKey(t)
25+
genesisPrivKey := test.RandPrivKey()
2626
genesisScriptKey := test.PubToKeyDesc(genesisPrivKey.PubKey())
2727

2828
// We'll modify the returned genesis to instead commit to some actual
@@ -71,7 +71,7 @@ func TestNewMintingBlobs(t *testing.T) {
7171
)
7272
taprootScript := test.ComputeTaprootScript(t, taprootKey)
7373

74-
changeInternalKey := test.RandPrivKey(t).PubKey()
74+
changeInternalKey := test.RandPrivKey().PubKey()
7575
changeTaprootKey := txscript.ComputeTaprootKeyNoScript(
7676
changeInternalKey,
7777
)

proof/proof_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func genRandomGenesisWithProof(t testing.TB, assetType asset.Type,
234234

235235
t.Helper()
236236

237-
genesisPrivKey := test.RandPrivKey(t)
237+
genesisPrivKey := test.RandPrivKey()
238238
genesisPubKey := test.PubToKeyDesc(genesisPrivKey.PubKey())
239239

240240
// If we have a specified meta reveal, then we'll replace the meta hash
@@ -371,7 +371,7 @@ func TestGenesisProofVerification(t *testing.T) {
371371

372372
// Create a script tree that we'll use for our tapscript sibling test
373373
// cases.
374-
scriptInternalKey := test.RandPrivKey(t).PubKey()
374+
scriptInternalKey := test.RandPrivKey().PubKey()
375375
leaf1 := test.ScriptHashLock(t, []byte("foobar"))
376376
leaf2 := test.ScriptSchnorrSig(t, scriptInternalKey)
377377
testLeafPreimage, err := commitment.NewPreimageFromLeaf(leaf1)

0 commit comments

Comments
 (0)