Skip to content

Commit

Permalink
itest: update test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Sep 26, 2023
1 parent bfb005f commit d4ce176
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
38 changes: 31 additions & 7 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/fn"
Expand Down Expand Up @@ -366,7 +365,27 @@ func verifyProofBlob(t *testing.T, tapClient taprpc.TaprootAssetsClient,
return err
}

snapshot, err := f.Verify(ctxt, headerVerifier)
groupVerifier := func(groupKey *btcec.PublicKey) error {
assetGroupKey := hex.EncodeToString(
groupKey.SerializeCompressed(),
)

// The given group key should be listed as a known group.
assetGroups, err := tapClient.ListGroups(
ctxt, &taprpc.ListGroupsRequest{},
)
require.NoError(t, err)

_, ok := assetGroups.Groups[assetGroupKey]
if !ok {
return fmt.Errorf("group key %s not known",
assetGroupKey)
}

return nil
}

snapshot, err := f.Verify(ctxt, headerVerifier, groupVerifier)
require.NoError(t, err)

return f, snapshot
Expand Down Expand Up @@ -845,15 +864,20 @@ func AssertGroup(t *testing.T, a *taprpc.Asset, b *taprpc.AssetHumanReadable,
// AssertGroupAnchor asserts that a specific asset genesis was used to create
// a tweaked group key.
func AssertGroupAnchor(t *testing.T, anchorGen *asset.Genesis,
internalKey, tweakedKey []byte) {
anchorGroup *taprpc.AssetGroup) {

internalPubKey, err := btcec.ParsePubKey(internalKey)
internalPubKey, err := btcec.ParsePubKey(anchorGroup.RawGroupKey)
require.NoError(t, err)
computedGroupPubKey := txscript.ComputeTaprootOutputKey(
internalPubKey, anchorGen.GroupKeyTweak(),

// TODO(jhb): add tapscript root support
anchorTweak := anchorGen.ID()
computedGroupPubKey, err := asset.GroupPubKey(
internalPubKey, anchorTweak[:], nil,
)
require.NoError(t, err)

computedGroupKey := computedGroupPubKey.SerializeCompressed()
require.Equal(t, tweakedKey, computedGroupKey)
require.Equal(t, anchorGroup.TweakedGroupKey, computedGroupKey)
}

// MatchRpcAsset is a function that returns true if the given RPC asset is a
Expand Down
5 changes: 2 additions & 3 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,8 @@ func assertAssetBalances(t *harnessTest,
require.Equal(
t.t, balance.Balance, rpcAsset.Amount,
)
require.Equal(
t.t,
balance.AssetGenesis,
AssertAssetGenesis(
t.t, balance.AssetGenesis,
rpcAsset.AssetGenesis,
)
}
Expand Down
5 changes: 1 addition & 4 deletions itest/multi_asset_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ func VerifyGroupAnchor(t *testing.T, assets []*taprpc.Asset,

anchorGen := parseGenInfo(t, anchor.AssetGenesis)
anchorGen.Type = asset.Type(anchor.AssetType)
AssertGroupAnchor(
t, anchorGen, anchor.AssetGroup.RawGroupKey,
anchor.AssetGroup.TweakedGroupKey,
)
AssertGroupAnchor(t, anchorGen, anchor.AssetGroup)

return anchor
}
Expand Down

0 comments on commit d4ce176

Please sign in to comment.