Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 6, 2023
1 parent e88c0d2 commit e224f9d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,10 @@ func AssertUniverseRoot(t *testing.T, client unirpc.UniverseClient,
}

func AssertUniverseRootEqual(a, b *unirpc.UniverseRoot) bool {
if (a.Id != nil && b.Id == nil) || (a.Id == nil && b.Id != nil) {
return false
}

// The ids should batch exactly.
if !reflect.DeepEqual(a.Id.Id, b.Id.Id) {
return false
Expand Down
33 changes: 24 additions & 9 deletions itest/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
tap "github.com/lightninglabs/taproot-assets"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/mssmt"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightninglabs/taproot-assets/universe"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -282,21 +284,29 @@ func testUniverseREST(t *harnessTest) {

// Simple assets are keyed by their asset ID.
for _, simpleAsset := range rpcSimpleAssets {
assetID := hex.EncodeToString(simpleAsset.AssetGenesis.AssetId)
require.Contains(t.t, roots.UniverseRoots, assetID)
// Ensure that the universe root set contains issuance roots for
// all of our assets.
var assetID asset.ID
copy(assetID[:], simpleAsset.AssetGenesis.AssetId)
uniID := universe.Identifier{
AssetID: assetID,
ProofType: universe.ProofTypeIssuance,
}
uniIDStr := uniID.String()
require.Contains(t.t, roots.UniverseRoots, uniIDStr)

require.Equal(
t.t, simpleAsset.AssetGenesis.Name,
roots.UniverseRoots[assetID].AssetName,
roots.UniverseRoots[uniIDStr].AssetName,
)

// Query the specific root to make sure we get the same result.
assetRoot, err := getJSON[*unirpc.QueryRootResponse](
assetRoots, err := getJSON[*unirpc.QueryRootResponse](
fmt.Sprintf("%s/roots/asset-id/%s", urlPrefix, assetID),
)
require.NoError(t.t, err)
require.True(t.t, AssertUniverseRootEqual(
roots.UniverseRoots[assetID], assetRoot.AssetRoot,
roots.UniverseRoots[uniIDStr], assetRoots.IssuanceRoot,
))
}

Expand All @@ -309,21 +319,26 @@ func testUniverseREST(t *harnessTest) {
groupKey := issuableAsset.AssetGroup.TweakedGroupKey
groupKeyHash := sha256.Sum256(groupKey[1:])
groupKeyID := hex.EncodeToString(groupKeyHash[:])
require.Contains(t.t, roots.UniverseRoots, groupKeyID)

namespace := fmt.Sprintf(
"%s-%s", universe.ProofTypeTransfer, groupKeyID,
)
require.Contains(t.t, roots.UniverseRoots, namespace)

// Query the specific root to make sure we get the same result.
// Rather than use the hash above, the API exposes the
// serialized schorr key instead as the URI param.
queryGroupKey := hex.EncodeToString(groupKey[1:])
queryGroupKey := hex.EncodeToString(groupKeyHash[:])
queryURI := fmt.Sprintf(
"%s/roots/group-key/%s", urlPrefix, queryGroupKey,
)
assetRoot, err := getJSON[*unirpc.QueryRootResponse](queryURI)
require.NoError(t.t, err)

uniRoot, foundRoot := roots.UniverseRoots[namespace]
require.True(t.t, foundRoot)
require.True(t.t, AssertUniverseRootEqual(
roots.UniverseRoots[groupKeyID],
assetRoot.AssetRoot,
uniRoot, assetRoot.TransferRoot,
))
}
}
Expand Down
6 changes: 5 additions & 1 deletion universe_rpc_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func (r *RpcUniverseDiff) RootNode(ctx context.Context,
return universe.BaseRoot{}, err
}

return unmarshalUniverseRoot(universeRoot.AssetRoot)
if id.ProofType == universe.ProofTypeIssuance {
return unmarshalUniverseRoot(universeRoot.IssuanceRoot)
}

return unmarshalUniverseRoot(universeRoot.TransferRoot)
}

// UniverseLeafKeys returns all the keys inserted in the universe.
Expand Down

0 comments on commit e224f9d

Please sign in to comment.