Skip to content

Commit

Permalink
itest: use 33 byte script key in universe test
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Jun 9, 2023
1 parent 4a9dab3 commit 5fb7f89
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
22 changes: 19 additions & 3 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,22 @@ func assertAddr(t *testing.T, expected *taprpc.Asset, actual *taprpc.Addr) {
require.NotEqual(t, expected.ScriptKey, actual.ScriptKey)
}

// assertEqualAsset asserts that two taprpc.Asset objects are equal, ignoring
// node-specific fields like if script keys are local, if the asset is spent,
// or if the anchor information is populated.
func assertAsset(t *testing.T, expected, actual *taprpc.Asset) {
require.Equal(t, expected.Version, actual.Version)
require.Equal(t, expected.AssetGenesis, actual.AssetGenesis)
require.Equal(t, expected.AssetType, actual.AssetType)
require.Equal(t, expected.Amount, actual.Amount)
require.Equal(t, expected.LockTime, actual.LockTime)
require.Equal(t, expected.RelativeLockTime, actual.RelativeLockTime)
require.Equal(t, expected.ScriptVersion, actual.ScriptVersion)
require.Equal(t, expected.ScriptKey, actual.ScriptKey)
require.Equal(t, expected.AssetGroup, actual.AssetGroup)
require.Equal(t, expected.PrevWitnesses, actual.PrevWitnesses)
}

// assertBalanceByID asserts that the balance of a single asset,
// specified by ID, on the given daemon is correct.
func assertBalanceByID(t *testing.T, tapd *tapdHarness, id []byte,
Expand Down Expand Up @@ -778,15 +794,15 @@ func assertUniverseStats(t *testing.T, node *tapdHarness,
}

if numProofs != int(uniStats.NumTotalProofs) {
return fmt.Errorf("expected %v, got %v",
return fmt.Errorf("expected %v proofs, got %v",
numProofs, uniStats.NumTotalProofs)
}
if numSyncs != int(uniStats.NumTotalSyncs) {
return fmt.Errorf("expected %v, got %v",
return fmt.Errorf("expected %v syncs, got %v",
numSyncs, uniStats.NumTotalSyncs)
}
if numAssets != int(uniStats.NumTotalAssets) {
return fmt.Errorf("expected %v, got %v",
return fmt.Errorf("expected %v assets, got %v",
numAssets, uniStats.NumTotalAssets)
}

Expand Down
42 changes: 41 additions & 1 deletion itest/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"io"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
tap "github.com/lightninglabs/taproot-assets"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/taprpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
Expand Down Expand Up @@ -232,6 +234,7 @@ func testUniverseFederation(t *harnessTest) {

// Now that Bob is active, we'll make a set of assets with the main node.
firstAsset := mintAssetsConfirmBatch(t, t.tapd, simpleAssets[:1])
require.Len(t.t, firstAsset, 1)

// We'll now add the main node, as a member of Bob's Universe
// federation. We expect that their state is synchronized shortly after
Expand Down Expand Up @@ -263,6 +266,43 @@ func testUniverseFederation(t *harnessTest) {
// should also be able to query for stats specifically for the asset.
assertUniverseStats(t.t, bob, 1, 0, 1)

// We should also be able to fetch the new asset from Bob's Universe,
// and query for that asset with the compressed script key.
firstAssetID := firstAsset[0].AssetGenesis.AssetId
firstScriptKey := hex.EncodeToString(firstAsset[0].ScriptKey)
firstOutpoint, err := tap.UnmarshalOutpoint(
firstAsset[0].ChainAnchor.AnchorOutpoint,
)
require.NoError(t.t, err)
require.Len(t.t, firstScriptKey, btcec.PubKeyBytesLenCompressed*2)

firstAssetProofQuery := unirpc.UniverseKey{
Id: &unirpc.ID{
Id: &unirpc.ID_AssetId{
AssetId: firstAssetID,
}},
LeafKey: &unirpc.AssetKey{
Outpoint: &unirpc.AssetKey_Op{
Op: &unirpc.Outpoint{
HashStr: firstOutpoint.Hash.String(),
Index: int32(firstOutpoint.Index),
},
},
ScriptKey: &unirpc.AssetKey_ScriptKeyStr{
ScriptKeyStr: firstScriptKey,
},
},
}

// The asset fetched from the universe should match the asset minted
// on the main node, ignoring the zero prev witness from minting.
firstAssetUniProof, err := bob.QueryProof(ctx, &firstAssetProofQuery)
require.NoError(t.t, err)

firstAssetFromUni := firstAssetUniProof.AssetLeaf.Asset
firstAssetFromUni.PrevWitnesses = nil
assertAsset(t.t, firstAsset[0], firstAssetFromUni)

// We'll now make a new asset with Bob, and ensure that the state is
// properly pushed to the main node which is a part of the federation.
newAsset := mintAssetsConfirmBatch(t, bob, simpleAssets[1:])
Expand All @@ -288,7 +328,7 @@ func testUniverseFederation(t *harnessTest) {

// Bob's stats should also now show that there're two total asset as
// well as two proofs.
assertUniverseStats(t.t, bob, 2, 0, 2)
assertUniverseStats(t.t, bob, 2, 1, 2)

// We should be able to find both the new assets in the set of universe
// stats for an asset.
Expand Down

0 comments on commit 5fb7f89

Please sign in to comment.