Skip to content

Commit

Permalink
itest: retrieve anchor txid from outpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Nov 8, 2023
1 parent ec46259 commit 8f7b0c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 11 additions & 2 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@ func AssetAnchorCheck(txid, blockHash chainhash.Hash) AssetCheck {
return fmt.Errorf("asset is missing chain anchor field")
}

if a.ChainAnchor.AnchorTxid != txid.String() {
out, err :=
wire.NewOutPointFromString(a.ChainAnchor.AnchorOutpoint)

if err != nil {
return fmt.Errorf("unable to parse outpoint: %v", err)
}

anchorTxid := out.Hash.String()

if anchorTxid != txid.String() {
return fmt.Errorf("unexpected asset anchor TXID, got "+
"%v wanted %x", a.ChainAnchor.AnchorTxid,
"%v wanted %x", anchorTxid,
txid[:])
}

Expand Down
11 changes: 8 additions & 3 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/taprpc"
Expand Down Expand Up @@ -173,11 +174,15 @@ func transferAssetProofs(t *harnessTest, src, dst *tapdHarness,
importedAssets := GroupAssetsByName(listResp.Assets)
for _, existingAsset := range assets {
gen := existingAsset.AssetGenesis
anchorTxHash, err := chainhash.NewHashFromStr(
existingAsset.ChainAnchor.AnchorTxid,
out, err := wire.NewOutPointFromString(
existingAsset.ChainAnchor.AnchorOutpoint,
)
require.NoError(t.t, err)

anchorTxHash := out.Hash

require.NoError(t.t, err)

anchorBlockHash, err := chainhash.NewHashFromStr(
existingAsset.ChainAnchor.AnchorBlockHash,
)
Expand All @@ -187,7 +192,7 @@ func transferAssetProofs(t *harnessTest, src, dst *tapdHarness,
t.t, importedAssets, gen.Name, gen.MetaHash,
AssetAmountCheck(existingAsset.Amount),
AssetTypeCheck(existingAsset.AssetGenesis.AssetType),
AssetAnchorCheck(*anchorTxHash, *anchorBlockHash),
AssetAnchorCheck(anchorTxHash, *anchorBlockHash),
AssetScriptKeyIsLocalCheck(shouldShowUpAsLocal),
)
}
Expand Down

0 comments on commit 8f7b0c1

Please sign in to comment.