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 da6dcea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ 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,
txid[:])
"%v wanted %x", anchorTxid, txid[:])
}

if a.ChainAnchor.AnchorBlockHash != blockHash.String() {
Expand Down
9 changes: 6 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,13 @@ 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

anchorBlockHash, err := chainhash.NewHashFromStr(
existingAsset.ChainAnchor.AnchorBlockHash,
)
Expand All @@ -187,7 +190,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 da6dcea

Please sign in to comment.