Skip to content

Commit

Permalink
tapdb: new opt to specify group anchor in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb authored and guggero committed Mar 8, 2024
1 parent 4a0b14d commit 3f02042
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tapdb/assets_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type assetGenOptions struct {

groupAnchorGen *asset.Genesis

groupAnchorGenPoint *wire.OutPoint

noGroupKey bool

groupKeyPriv *btcec.PrivateKey
Expand Down Expand Up @@ -87,6 +89,12 @@ func withGroupAnchorGen(g *asset.Genesis) assetGenOpt {
}
}

func withGroupAnchorGenPoint(op wire.OutPoint) assetGenOpt {
return func(opt *assetGenOptions) {
opt.groupAnchorGenPoint = &op
}
}

func withAssetGenPoint(op wire.OutPoint) assetGenOpt {
return func(opt *assetGenOptions) {
opt.genesisPoint = op
Expand Down Expand Up @@ -151,6 +159,9 @@ func randAsset(t *testing.T, genOpts ...assetGenOpt) *asset.Asset {
if opts.groupAnchorGen != nil {
initialGen = *opts.groupAnchorGen
}
if opts.groupAnchorGenPoint != nil {
initialGen.FirstPrevOut = *opts.groupAnchorGenPoint
}

groupReq := asset.NewGroupKeyRequestNoErr(
t, groupKeyDesc, initialGen, protoAsset, nil,
Expand Down Expand Up @@ -433,6 +444,8 @@ type assetDesc struct {

groupAnchorGen *asset.Genesis

groupAnchorGenPoint *wire.OutPoint

anchorPoint wire.OutPoint

keyGroup *btcec.PrivateKey
Expand Down Expand Up @@ -548,6 +561,11 @@ func (a *assetGenerator) genAssets(t *testing.T, assetStore *AssetStore,
desc.groupAnchorGen,
))
}
if desc.groupAnchorGenPoint != nil {
opts = append(opts, withGroupAnchorGenPoint(
*desc.groupAnchorGenPoint,
))
}
if desc.assetVersion != nil {
opts = append(opts, withAssetVersionGen(
desc.assetVersion,
Expand Down Expand Up @@ -1046,12 +1064,14 @@ func TestSelectCommitment(t *testing.T) {
keyGroup: assetGen.groupKeys[0],
},
{
assetGen: assetGen.assetGens[0],
assetGen: assetGen.assetGens[1],
amt: 20,

anchorPoint: assetGen.anchorPoints[0],

keyGroup: assetGen.groupKeys[0],
keyGroup: assetGen.groupKeys[0],
groupAnchorGen: &assetGen.assetGens[0],
groupAnchorGenPoint: &assetGen.anchorPoints[0],
},
{
assetGen: assetGen.assetGens[1],
Expand Down

0 comments on commit 3f02042

Please sign in to comment.