Skip to content

Commit fdfc902

Browse files
committed
proof: add new TLV fields to test vectors
1 parent 6c68c9f commit fdfc902

File tree

4 files changed

+514
-9
lines changed

4 files changed

+514
-9
lines changed

proof/mock.go

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,17 +927,45 @@ func (ttp *TestTapscriptProof) ToTapscriptProof(t testing.TB) *TapscriptProof {
927927
func NewTestFromMetaReveal(t testing.TB, m *MetaReveal) *TestMetaReveal {
928928
t.Helper()
929929

930+
var universeCommitments *bool
931+
if m.UniverseCommitments {
932+
trueValue := true
933+
universeCommitments = &trueValue
934+
}
935+
936+
var canonicalUniverses []string
937+
m.CanonicalUniverses.WhenSome(func(urls []url.URL) {
938+
canonicalUniverses = fn.Map(urls, func(u url.URL) string {
939+
return u.String()
940+
})
941+
})
942+
943+
var delegationKey *string
944+
m.DelegationKey.WhenSome(func(key btcec.PublicKey) {
945+
keyBytes := key.SerializeCompressed()
946+
keyHex := hex.EncodeToString(keyBytes)
947+
delegationKey = &keyHex
948+
})
949+
930950
return &TestMetaReveal{
931-
Type: uint8(m.Type),
932-
Data: hex.EncodeToString(m.Data),
933-
UnknownOddTypes: m.UnknownOddTypes,
951+
Type: uint8(m.Type),
952+
Data: hex.EncodeToString(m.Data),
953+
UniverseCommitments: universeCommitments,
954+
DecimalDisplay: m.DecimalDisplay.UnwrapToPtr(),
955+
CanonicalUniverses: canonicalUniverses,
956+
DelegationKey: delegationKey,
957+
UnknownOddTypes: m.UnknownOddTypes,
934958
}
935959
}
936960

937961
type TestMetaReveal struct {
938-
Type uint8 `json:"type"`
939-
Data string `json:"data"`
940-
UnknownOddTypes tlv.TypeMap `json:"unknown_odd_types"`
962+
Type uint8 `json:"type"`
963+
Data string `json:"data"`
964+
DecimalDisplay *uint32 `json:"decimal_display"`
965+
UniverseCommitments *bool `json:"universe_commitments"`
966+
CanonicalUniverses []string `json:"canonical_universes"`
967+
DelegationKey *string `json:"delegation_key"`
968+
UnknownOddTypes tlv.TypeMap `json:"unknown_odd_types"`
941969
}
942970

943971
func (tmr *TestMetaReveal) ToMetaReveal(t testing.TB) *MetaReveal {
@@ -946,9 +974,47 @@ func (tmr *TestMetaReveal) ToMetaReveal(t testing.TB) *MetaReveal {
946974
data, err := hex.DecodeString(tmr.Data)
947975
require.NoError(t, err)
948976

977+
var decimalDisplay fn.Option[uint32]
978+
if tmr.DecimalDisplay != nil {
979+
decimalDisplay = fn.Some(*tmr.DecimalDisplay)
980+
}
981+
982+
var universeCommitments bool
983+
if tmr.UniverseCommitments != nil && *tmr.UniverseCommitments {
984+
universeCommitments = true
985+
}
986+
987+
var canonicalUniverses fn.Option[[]url.URL]
988+
if len(tmr.CanonicalUniverses) > 0 {
989+
urls := make([]url.URL, len(tmr.CanonicalUniverses))
990+
for idx, u := range tmr.CanonicalUniverses {
991+
uniURL, err := url.Parse(u)
992+
require.NoError(t, err)
993+
994+
urls[idx] = *uniURL
995+
}
996+
997+
canonicalUniverses = fn.Some(urls)
998+
}
999+
1000+
var delegationKey fn.Option[btcec.PublicKey]
1001+
if tmr.DelegationKey != nil {
1002+
keyBytes, err := hex.DecodeString(*tmr.DelegationKey)
1003+
require.NoError(t, err)
1004+
1005+
key, err := btcec.ParsePubKey(keyBytes)
1006+
require.NoError(t, err)
1007+
1008+
delegationKey = fn.Some(*key)
1009+
}
1010+
9491011
return &MetaReveal{
950-
Type: MetaType(tmr.Type),
951-
Data: data,
952-
UnknownOddTypes: tmr.UnknownOddTypes,
1012+
Type: MetaType(tmr.Type),
1013+
Data: data,
1014+
DecimalDisplay: decimalDisplay,
1015+
UniverseCommitments: universeCommitments,
1016+
CanonicalUniverses: canonicalUniverses,
1017+
DelegationKey: delegationKey,
1018+
UnknownOddTypes: tmr.UnknownOddTypes,
9531019
}
9541020
}

proof/proof_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9+
"net/url"
910
"os"
1011
"path/filepath"
1112
"strings"
@@ -559,6 +560,15 @@ func TestGenesisProofVerification(t *testing.T) {
559560
testBranchPreimage := commitment.NewPreimageFromBranch(branch)
560561
amount := uint64(5000)
561562

563+
dummyURL, err := url.Parse("universerpc://some-host:1234")
564+
require.NoError(t, err)
565+
566+
dummyURL2, err := url.Parse("universerpc://another-host:765")
567+
require.NoError(t, err)
568+
569+
oneURL := fn.Some[[]url.URL]([]url.URL{*dummyURL})
570+
twoURL := fn.Some[[]url.URL]([]url.URL{*dummyURL, *dummyURL2})
571+
562572
testCases := []struct {
563573
name string
564574
assetType asset.Type
@@ -751,6 +761,43 @@ func TestGenesisProofVerification(t *testing.T) {
751761
},
752762
expectedErr: ErrGroupKeyRevealMismatch,
753763
},
764+
{
765+
name: "normal asset with a meta reveal and " +
766+
"decimal display and canonical universe URL",
767+
assetType: asset.Normal,
768+
amount: &amount,
769+
metaReveal: &MetaReveal{
770+
Data: []byte("meant in crooking " +
771+
"nevermore"),
772+
DecimalDisplay: fn.Some[uint32](8),
773+
CanonicalUniverses: oneURL,
774+
},
775+
},
776+
{
777+
name: "collectible with a meta reveal and " +
778+
"decimal display and canonical universe URL",
779+
assetType: asset.Collectible,
780+
metaReveal: &MetaReveal{
781+
Data: []byte("shall be lifted " +
782+
"nevermore"),
783+
DecimalDisplay: fn.Some[uint32](3),
784+
CanonicalUniverses: oneURL,
785+
},
786+
},
787+
{
788+
name: "normal asset with all meta reveal fields",
789+
assetType: asset.Normal,
790+
amount: &amount,
791+
metaReveal: &MetaReveal{
792+
Data: []byte("fully loaded"),
793+
DecimalDisplay: fn.Some[uint32](11),
794+
UniverseCommitments: true,
795+
CanonicalUniverses: twoURL,
796+
DelegationKey: fn.MaybeSome(
797+
asset.NUMSPubKey,
798+
),
799+
},
800+
},
754801
}
755802

756803
testVectors := &TestVectors{}

0 commit comments

Comments
 (0)