Skip to content

Commit 334a73b

Browse files
committed
unittests+mock: add missing args to NewGroupKeyRequestNoErr
Add externalKey and customTapscriptRoot arguments to the mock function NewGroupKeyRequestNoErr, enabling them to be specified during testing.
1 parent 032061e commit 334a73b

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

asset/asset_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/blockchain"
1111
"github.com/btcsuite/btcd/btcec/v2"
1212
"github.com/btcsuite/btcd/btcec/v2/schnorr"
13+
"github.com/btcsuite/btcd/chaincfg/chainhash"
1314
"github.com/btcsuite/btcd/txscript"
1415
"github.com/btcsuite/btcd/wire"
1516
"github.com/lightninglabs/taproot-assets/fn"
@@ -887,7 +888,10 @@ func TestAssetGroupKey(t *testing.T) {
887888
// TweakTaprootPrivKey modifies the private key that is passed in! We
888889
// need to provide a copy to arrive at the same result.
889890
protoAsset := NewAssetNoErr(t, g, 1, 0, 0, fakeScriptKey, nil)
890-
groupReq := NewGroupKeyRequestNoErr(t, fakeKeyDesc, g, protoAsset, nil)
891+
groupReq := NewGroupKeyRequestNoErr(
892+
t, fakeKeyDesc, fn.None[ExternalKey](), g, protoAsset, nil,
893+
fn.None[chainhash.Hash](),
894+
)
891895
genTx, err := groupReq.BuildGroupVirtualTx(&genBuilder)
892896
require.NoError(t, err)
893897

@@ -905,7 +909,8 @@ func TestAssetGroupKey(t *testing.T) {
905909
tweakedKey = txscript.TweakTaprootPrivKey(*internalKey, tapTweak)
906910

907911
groupReq = NewGroupKeyRequestNoErr(
908-
t, test.PubToKeyDesc(privKey.PubKey()), g, protoAsset, tapTweak,
912+
t, test.PubToKeyDesc(privKey.PubKey()), fn.None[ExternalKey](),
913+
g, protoAsset, tapTweak, fn.None[chainhash.Hash](),
909914
)
910915
genTx, err = groupReq.BuildGroupVirtualTx(&genBuilder)
911916
require.NoError(t, err)

asset/mock.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,13 @@ func NewAssetNoErr(t testing.TB, gen Genesis, amt, locktime, relocktime uint64,
617617
}
618618

619619
func NewGroupKeyRequestNoErr(t testing.TB, internalKey keychain.KeyDescriptor,
620-
gen Genesis, newAsset *Asset, scriptRoot []byte) *GroupKeyRequest {
620+
externalKey fn.Option[ExternalKey], gen Genesis, newAsset *Asset,
621+
scriptRoot []byte,
622+
customTapscriptRoot fn.Option[chainhash.Hash]) *GroupKeyRequest {
621623

622624
req, err := NewGroupKeyRequest(
623-
internalKey, fn.None[ExternalKey](), gen, newAsset, scriptRoot,
624-
fn.None[chainhash.Hash](),
625+
internalKey, externalKey, gen, newAsset, scriptRoot,
626+
customTapscriptRoot,
625627
)
626628
require.NoError(t, err)
627629

commitment/commitment_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ func TestNewAssetCommitment(t *testing.T) {
149149
genTxBuilder := asset.MockGroupTxBuilder{}
150150
group1Priv, group1Pub := btcec.PrivKeyFromBytes(group1PrivBytes)
151151
group1ReissuedGroupReq := asset.NewGroupKeyRequestNoErr(
152-
t, test.PubToKeyDesc(group1Pub), genesis1, genesis2ProtoAsset,
153-
nil,
152+
t, test.PubToKeyDesc(group1Pub), fn.None[asset.ExternalKey](),
153+
genesis1, genesis2ProtoAsset, nil, fn.None[chainhash.Hash](),
154154
)
155155
group1ReissuedGenTx, err := group1ReissuedGroupReq.BuildGroupVirtualTx(
156156
&genTxBuilder,
@@ -1021,7 +1021,8 @@ func TestUpdateAssetCommitment(t *testing.T) {
10211021
genTxBuilder := asset.MockGroupTxBuilder{}
10221022
group1Priv, group1Pub := btcec.PrivKeyFromBytes(group1PrivBytes)
10231023
group1ReissuedGroupReq := asset.NewGroupKeyRequestNoErr(
1024-
t, test.PubToKeyDesc(group1Pub), genesis1, group1Reissued, nil,
1024+
t, test.PubToKeyDesc(group1Pub), fn.None[asset.ExternalKey](),
1025+
genesis1, group1Reissued, nil, fn.None[chainhash.Hash](),
10251026
)
10261027
group1ReissuedGenTx, err := group1ReissuedGroupReq.BuildGroupVirtualTx(
10271028
&genTxBuilder,

tapdb/asset_minting_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func storeGroupGenesis(t *testing.T, ctx context.Context, initGen asset.Genesis,
132132
t, assetGen, nil, asset.RandScriptKey(t),
133133
)
134134
groupReq := asset.NewGroupKeyRequestNoErr(
135-
t, privDesc, initGen, genProtoAsset, nil,
135+
t, privDesc, fn.None[asset.ExternalKey](), initGen,
136+
genProtoAsset, nil, fn.None[chainhash.Hash](),
136137
)
137138
genTx, err := groupReq.BuildGroupVirtualTx(&genTxBuilder)
138139
require.NoError(t, err)
@@ -671,8 +672,10 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
671672
if groupInfo != nil {
672673
groupReq := asset.NewGroupKeyRequestNoErr(
673674
t, groupInfo.GroupKey.RawKey,
675+
fn.None[asset.ExternalKey](),
674676
*groupInfo.Genesis, protoAsset,
675677
groupInfo.GroupKey.TapscriptRoot,
678+
fn.None[chainhash.Hash](),
676679
)
677680
genTx, err := groupReq.BuildGroupVirtualTx(
678681
&genTxBuilder,
@@ -690,8 +693,10 @@ func seedlingsToAssetRoot(t *testing.T, genesisPoint wire.OutPoint,
690693
groupKeyRaw, newGroupPriv := test.RandKeyDesc(t)
691694
genSigner := asset.NewMockGenesisSigner(newGroupPriv)
692695
groupReq := asset.NewGroupKeyRequestNoErr(
693-
t, groupKeyRaw, assetGen, protoAsset,
696+
t, groupKeyRaw, fn.None[asset.ExternalKey](),
697+
assetGen, protoAsset,
694698
seedling.GroupTapscriptRoot,
699+
fn.None[chainhash.Hash](),
695700
)
696701
genTx, err := groupReq.BuildGroupVirtualTx(
697702
&genTxBuilder,

tapdb/assets_store_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ func randAsset(t *testing.T, genOpts ...assetGenOpt) *asset.Asset {
167167
}
168168

169169
groupReq := asset.NewGroupKeyRequestNoErr(
170-
t, groupKeyDesc, initialGen, protoAsset, nil,
170+
t, groupKeyDesc, fn.None[asset.ExternalKey](), initialGen,
171+
protoAsset, nil, fn.None[chainhash.Hash](),
171172
)
172173
genTx, err := groupReq.BuildGroupVirtualTx(&genTxBuilder)
173174
require.NoError(t, err)

0 commit comments

Comments
 (0)