github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/testutil/hex.go (about) 1 package testutil 2 3 import ( 4 "bytes" 5 "encoding/hex" 6 "io" 7 "testing" 8 9 "github.com/bytom/bytom/protocol/bc" 10 ) 11 12 func MustDecodeHash(s string) (h bc.Hash) { 13 if err := h.UnmarshalText([]byte(s)); err != nil { 14 panic(err) 15 } 16 return h 17 } 18 19 func MustDecodeHexString(s string) []byte { 20 bytes, err := hex.DecodeString(s) 21 if err != nil { 22 panic(err) 23 } 24 return bytes 25 } 26 27 func MustDecodeAsset(s string) (h bc.AssetID) { 28 if err := h.UnmarshalText([]byte(s)); err != nil { 29 panic(err) 30 } 31 return h 32 } 33 34 func Serialize(t *testing.T, wt io.WriterTo) []byte { 35 var b bytes.Buffer 36 if _, err := wt.WriteTo(&b); err != nil { 37 t.Fatal(err) 38 } 39 return b.Bytes() 40 }