@@ -19,37 +19,33 @@ import (
1919 "encoding/json"
2020 "math/big"
2121 "reflect"
22-
2322 "testing"
2423
2524 "github.com/blinklabs-io/gouroboros/cbor"
2625 "github.com/blinklabs-io/gouroboros/ledger/alonzo"
2726 "github.com/blinklabs-io/gouroboros/ledger/common"
28- "github.com/blinklabs-io/gouroboros/ledger/mary"
29- "github.com/blinklabs-io/gouroboros/ledger/shelley"
3027)
3128
3229// Helper to create properly initialized base protocol parameters
33- func newBaseProtocolParams () mary.MaryProtocolParameters {
34- return mary.MaryProtocolParameters {
35- AllegraProtocolParameters : allegra.AllegraProtocolParameters {
36- ShelleyProtocolParameters : shelley.ShelleyProtocolParameters {
37- MinFeeA : 44 ,
38- MinFeeB : 155381 ,
39- MaxBlockBodySize : 65536 ,
40- MaxTxSize : 16384 ,
41- MaxBlockHeaderSize : 1100 ,
42- KeyDeposit : 2000000 ,
43- PoolDeposit : 500000000 ,
44- MaxEpoch : 18 ,
45- NOpt : 500 ,
46- A0 : & cbor.Rat {Rat : big .NewRat (1 , 2 )},
47- Rho : & cbor.Rat {Rat : big .NewRat (3 , 4 )},
48- Tau : & cbor.Rat {Rat : big .NewRat (5 , 6 )},
49- ProtocolMajor : 8 ,
50- ProtocolMinor : 0 ,
51- },
52- },
30+ func newBaseProtocolParams () alonzo.AlonzoProtocolParameters {
31+ return alonzo.AlonzoProtocolParameters {
32+ MinFeeA : 44 ,
33+ MinFeeB : 155381 ,
34+ MaxBlockBodySize : 65536 ,
35+ MaxTxSize : 16384 ,
36+ MaxBlockHeaderSize : 1100 ,
37+ KeyDeposit : 2000000 ,
38+ PoolDeposit : 500000000 ,
39+ MaxEpoch : 18 ,
40+ NOpt : 500 ,
41+ A0 : & cbor.Rat {Rat : big .NewRat (1 , 2 )},
42+ Rho : & cbor.Rat {Rat : big .NewRat (3 , 4 )},
43+ Tau : & cbor.Rat {Rat : big .NewRat (5 , 6 )},
44+ ProtocolMajor : 8 ,
45+ ProtocolMinor : 0 ,
46+ // Initialize other required fields with zero values
47+ MinPoolCost : 0 ,
48+ AdaPerUtxoByte : 0 ,
5349 }
5450}
5551
@@ -63,10 +59,11 @@ func TestAlonzoProtocolParametersUpdate(t *testing.T) {
6359 {
6460 name : "Update MinPoolCost" ,
6561 updateCbor : "a1101903e8" , // {16: 1000}
66- expected : alonzo.AlonzoProtocolParameters {
67- MaryProtocolParameters : newBaseProtocolParams (),
68- MinPoolCost : 1000 ,
69- },
62+ expected : func () alonzo.AlonzoProtocolParameters {
63+ params := newBaseProtocolParams ()
64+ params .MinPoolCost = 1000
65+ return params
66+ }(),
7067 },
7168 }
7269
@@ -85,9 +82,7 @@ func TestAlonzoProtocolParametersUpdate(t *testing.T) {
8582 return
8683 }
8784
88- params := alonzo.AlonzoProtocolParameters {
89- MaryProtocolParameters : newBaseProtocolParams (),
90- }
85+ params := newBaseProtocolParams ()
9186 params .Update (& update )
9287
9388 if ! reflect .DeepEqual (params , tt .expected ) {
@@ -96,6 +91,7 @@ func TestAlonzoProtocolParametersUpdate(t *testing.T) {
9691 })
9792 }
9893}
94+
9995func TestAlonzoProtocolParametersUpdateFromGenesis (t * testing.T ) {
10096 tests := []struct {
10197 name string
@@ -197,9 +193,7 @@ func TestAlonzoProtocolParametersUpdateFromGenesis(t *testing.T) {
197193 CostModels : convertCostModels (tempGenesis .CostModels ),
198194 }
199195
200- params := alonzo.AlonzoProtocolParameters {
201- MaryProtocolParameters : newBaseProtocolParams (),
202- }
196+ params := newBaseProtocolParams ()
203197 err = params .UpdateFromGenesis (& genesis )
204198 if err != nil {
205199 t .Fatalf ("UpdateFromGenesis failed: %v" , err )
@@ -212,7 +206,6 @@ func TestAlonzoProtocolParametersUpdateFromGenesis(t *testing.T) {
212206 }
213207}
214208
215-
216209func convertToExecutionPricesRat (r * struct {
217210 Numerator int64 `json:"numerator"`
218211 Denominator int64 `json:"denominator"`
@@ -239,15 +232,28 @@ func convertCostModels(tempModels map[string]map[string]int) map[string]map[stri
239232 return models
240233}
241234
242-
243- func TestAlonzoUtxorpc ( t * testing. T ) {
235+ func TestAlonzoProtocolParametersUtxorpc ( t * testing. T ) {
236+ baseParams := newBaseProtocolParams ()
244237 params := alonzo.AlonzoProtocolParameters {
245- MaryProtocolParameters : newBaseProtocolParams (),
246- MinPoolCost : 340000000 ,
247- AdaPerUtxoByte : 4310 ,
248- MaxValueSize : 5000 ,
249- CollateralPercentage : 150 ,
250- MaxCollateralInputs : 3 ,
238+ MinFeeA : baseParams .MinFeeA ,
239+ MinFeeB : baseParams .MinFeeB ,
240+ MaxBlockBodySize : baseParams .MaxBlockBodySize ,
241+ MaxTxSize : baseParams .MaxTxSize ,
242+ MaxBlockHeaderSize : baseParams .MaxBlockHeaderSize ,
243+ KeyDeposit : baseParams .KeyDeposit ,
244+ PoolDeposit : baseParams .PoolDeposit ,
245+ MaxEpoch : baseParams .MaxEpoch ,
246+ NOpt : baseParams .NOpt ,
247+ A0 : baseParams .A0 ,
248+ Rho : baseParams .Rho ,
249+ Tau : baseParams .Tau ,
250+ ProtocolMajor : baseParams .ProtocolMajor ,
251+ ProtocolMinor : baseParams .ProtocolMinor ,
252+ MinPoolCost : 340000000 ,
253+ AdaPerUtxoByte : 4310 ,
254+ MaxValueSize : 5000 ,
255+ CollateralPercentage : 150 ,
256+ MaxCollateralInputs : 3 ,
251257 ExecutionCosts : common.ExUnitPrice {
252258 MemPrice : & cbor.Rat {Rat : big .NewRat (577 , 10000 )},
253259 StepPrice : & cbor.Rat {Rat : big .NewRat (721 , 10000000 )},
@@ -318,10 +324,8 @@ func TestCostModelConversions(t *testing.T) {
318324
319325 for _ , tt := range tests {
320326 t .Run (tt .name , func (t * testing.T ) {
321- params := alonzo.AlonzoProtocolParameters {
322- MaryProtocolParameters : newBaseProtocolParams (),
323- CostModels : tt .input ,
324- }
327+ params := newBaseProtocolParams ()
328+ params .CostModels = tt .input
325329 result := params .ToLegacyCostModels ()
326330 if ! reflect .DeepEqual (result , tt .expected ) {
327331 t .Errorf ("unexpected result:\n got: %v\n want: %v" , result , tt .expected )
0 commit comments