@@ -21,6 +21,11 @@ import (
2121 "github.com/blinklabs-io/gouroboros/ledger"
2222)
2323
24+ const (
25+ byronTxCborHex = "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0"
26+ conwayTxCborHex = "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6"
27+ )
28+
2429func TestDetermineTransactionType (t * testing.T ) {
2530 testDefs := []struct {
2631 name string
@@ -29,12 +34,12 @@ func TestDetermineTransactionType(t *testing.T) {
2934 }{
3035 {
3136 name : "ConwayTx" ,
32- txCborHex : "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6" ,
37+ txCborHex : conwayTxCborHex ,
3338 expectedTxType : 6 ,
3439 },
3540 {
3641 name : "ByronTx" ,
37- txCborHex : "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0" ,
42+ txCborHex : byronTxCborHex ,
3843 expectedTxType : 0 ,
3944 },
4045 }
@@ -47,15 +52,87 @@ func TestDetermineTransactionType(t *testing.T) {
4752 if err != nil {
4853 t .Fatalf (
4954 "DetermineTransactionType failed with an unexpected error: %s" ,
50- err ,
51- )
55+ err )
5256 }
5357 if tmpTxType != testDef .expectedTxType {
5458 t .Fatalf (
5559 "did not get expected TX type: got %d, wanted %d" ,
5660 tmpTxType ,
57- testDef .expectedTxType ,
58- )
61+ testDef .expectedTxType )
62+ }
63+ }
64+
65+ }
66+
67+ func BenchmarkDetermineTransactionType_Conway (b * testing.B ) {
68+ txCbor , _ := hex .DecodeString (conwayTxCborHex )
69+ b .ResetTimer ()
70+ for i := 0 ; i < b .N ; i ++ {
71+ _ , err := ledger .DetermineTransactionType (txCbor )
72+ if err != nil {
73+ b .Fatal (err )
74+ }
75+ }
76+ }
77+
78+ // Benchmarks for type determination, deserialization, and serialization across Cardano ledger eras.
79+ // Note: Conway type determination benchmark covers attempts on Shelley, Allegra, Mary, Alonzo, Babbage eras.
80+ // Specific deserialization/serialization benchmarks are provided for Byron era.
81+ // Additional era-specific benchmarks can be added when valid transaction hex strings are available.
82+
83+ func BenchmarkDetermineTransactionType_Byron (b * testing.B ) {
84+ txCbor , _ := hex .DecodeString (byronTxCborHex )
85+ b .ResetTimer ()
86+ for i := 0 ; i < b .N ; i ++ {
87+ _ , err := ledger .DetermineTransactionType (txCbor )
88+ if err != nil {
89+ b .Fatal (err )
90+ }
91+ }
92+ }
93+
94+ func BenchmarkTransactionDeserialization_Byron (b * testing.B ) {
95+ txCbor , _ := hex .DecodeString (byronTxCborHex )
96+ b .ResetTimer ()
97+ for i := 0 ; i < b .N ; i ++ {
98+ _ , err := ledger .NewByronTransactionFromCbor (txCbor )
99+ if err != nil {
100+ b .Fatal (err )
101+ }
102+ }
103+ }
104+
105+ func BenchmarkTransactionSerialization_Byron (b * testing.B ) {
106+ txCbor , _ := hex .DecodeString (byronTxCborHex )
107+ tx , err := ledger .NewByronTransactionFromCbor (txCbor )
108+ if err != nil {
109+ b .Fatal (err )
110+ }
111+ b .ResetTimer ()
112+ for i := 0 ; i < b .N ; i ++ {
113+ _ = tx .Cbor ()
114+ }
115+ }
116+
117+ func BenchmarkTransactionDeserialization_Conway (b * testing.B ) {
118+ txCbor , _ := hex .DecodeString (conwayTxCborHex )
119+ b .ResetTimer ()
120+ for i := 0 ; i < b .N ; i ++ {
121+ _ , err := ledger .NewConwayTransactionFromCbor (txCbor )
122+ if err != nil {
123+ b .Fatal (err )
59124 }
60125 }
61126}
127+
128+ func BenchmarkTransactionSerialization_Conway (b * testing.B ) {
129+ txCbor , _ := hex .DecodeString (conwayTxCborHex )
130+ tx , err := ledger .NewConwayTransactionFromCbor (txCbor )
131+ if err != nil {
132+ b .Fatal (err )
133+ }
134+ b .ResetTimer ()
135+ for i := 0 ; i < b .N ; i ++ {
136+ _ = tx .Cbor ()
137+ }
138+ }
0 commit comments