Skip to content

Commit 184f02e

Browse files
committed
asset+tapsend: add more debugging statements and helpers
To debug commitment issues, it's useful to log the exact asset leaf that is committed. To be able to easily decode (and compare) that commitment, we also add a unit test that outputs the leaf as JSON.
1 parent 6613672 commit 184f02e

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

asset/asset_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"bytes"
55
"crypto/sha256"
66
"encoding/hex"
7+
"encoding/json"
8+
"os"
9+
"path/filepath"
710
"reflect"
811
"testing"
912

@@ -106,6 +109,8 @@ var (
106109
GroupPubKey: *pubKey,
107110
},
108111
}
112+
113+
assetHexFileName = filepath.Join("testdata", "asset.hex")
109114
)
110115

111116
// TestGenesisAssetClassification tests that the multiple forms of genesis asset
@@ -1222,3 +1227,23 @@ func TestExternalKeyPubKey(t *testing.T) {
12221227
})
12231228
}
12241229
}
1230+
1231+
// TestDecodeAsset tests that we can decode an asset from a hex file. This is
1232+
// mostly useful for debugging purposes.
1233+
func TestDecodeAsset(t *testing.T) {
1234+
fileContent, err := os.ReadFile(assetHexFileName)
1235+
require.NoError(t, err)
1236+
1237+
assetBytes, err := hex.DecodeString(string(fileContent))
1238+
require.NoError(t, err)
1239+
1240+
var a Asset
1241+
err = a.Decode(bytes.NewReader(assetBytes))
1242+
require.NoError(t, err)
1243+
1244+
ta := NewTestFromAsset(t, &a)
1245+
assetJSON, err := json.MarshalIndent(ta, "", "\t")
1246+
require.NoError(t, err)
1247+
1248+
t.Logf("Decoded asset: %v", string(assetJSON))
1249+
}

asset/testdata/asset.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0001010265fca6685a399ad7e9088ba3911c5b2f02b07cffc319f8086e3f129fbf647c4537000000011b69746573742d61737365742d63656e74732d7472616e6368652d32811ad3c42f355c915d1fc4ba4ed71337092191431308f975d7acbc88a09ab98100000000000401000603fd138a0901040bad01ab01651145af966796fc5f4e7ec057acd24b38c5d0060bfe8e0c74e4c9464c08993a330000000017e137755dac067b0e1d91e33d077ab3482fbe1c382d424412c4620a8e3455eb02e9fa4e023746d43a7440b4148fb00f83f8b22ecb67625313fcb54442df2bdfb403420140791e35d3b49d0c1a1ec6415ba419f027fb4fcf254773e9c54ba77715a793e33c67175901e020b9ed87ab2161aa17a572def28d638ca3656fd5f27d6fd974ae280e020000102102e9fa4e023746d43a7440b4148fb00f83f8b22ecb67625313fcb54442df2bdfb4112102f37e9d09521076209768a6028aa2b42000b042a0635cb90f257c8b00c34a3688

tapsend/send.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,9 @@ func LogCommitment(prefix string, idx int,
15841584
prefix, idx, tapCommitment.Version, merkleRoot[:],
15851585
internalKey.SerializeCompressed(), pkScript, trimmedMerkleRoot)
15861586
for _, a := range tapCommitment.CommittedAssets() {
1587+
var buf bytes.Buffer
1588+
_ = a.Encode(&buf)
1589+
15871590
groupKey := "<nil>"
15881591
if a.GroupKey != nil {
15891592
groupKey = hex.EncodeToString(
@@ -1592,9 +1595,11 @@ func LogCommitment(prefix string, idx int,
15921595
}
15931596
log.Tracef("%v commitment asset_id=%v, script_key=%x, "+
15941597
"group_key=%v, amount=%d, version=%d, "+
1595-
"split_commitment=%v", prefix, a.ID(),
1598+
"split_commitment=%v, encoded=%x", prefix, a.ID(),
15961599
a.ScriptKey.PubKey.SerializeCompressed(), groupKey,
1597-
a.Amount, a.Version, a.SplitCommitmentRoot != nil)
1600+
a.Amount, a.Version, a.SplitCommitmentRoot != nil,
1601+
buf.Bytes())
1602+
15981603
}
15991604
}
16001605

0 commit comments

Comments
 (0)