Skip to content

Commit fb666cf

Browse files
authored
fix(protocol/localstatequery): Added unit test function to validate GenesisConfigResult (#947)
* fix(protocol/localstatequery): Added a unit test case function to validate GenesisConfigResult Signed-off-by: Akhil Repala <[email protected]>
1 parent 98b40a0 commit fb666cf

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed

protocol/localstatequery/client_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package localstatequery_test
1616

1717
import (
18+
"encoding/json"
1819
"fmt"
1920
"reflect"
2021
"testing"
@@ -285,3 +286,66 @@ func TestGetUTxOByAddress(t *testing.T) {
285286
},
286287
)
287288
}
289+
290+
func TestGenesisConfigJSON(t *testing.T) {
291+
genesisConfig := localstatequery.GenesisConfigResult{
292+
Start: localstatequery.SystemStartResult{
293+
Year: 2024,
294+
Day: 35,
295+
Picoseconds: 1234567890123456,
296+
},
297+
NetworkMagic: 764824073,
298+
NetworkId: 1,
299+
ActiveSlotsCoeff: []interface{}{0.1, 0.2},
300+
SecurityParam: 2160,
301+
EpochLength: 432000,
302+
SlotsPerKESPeriod: 129600,
303+
MaxKESEvolutions: 62,
304+
SlotLength: 1,
305+
UpdateQuorum: 5,
306+
MaxLovelaceSupply: 45000000000000000,
307+
ProtocolParams: localstatequery.GenesisConfigResultProtocolParameters{
308+
MinFeeA: 44,
309+
MinFeeB: 155381,
310+
MaxBlockBodySize: 65536,
311+
MaxTxSize: 16384,
312+
MaxBlockHeaderSize: 1100,
313+
KeyDeposit: 2000000,
314+
PoolDeposit: 500000000,
315+
EMax: 18,
316+
NOpt: 500,
317+
A0: []int{0},
318+
Rho: []int{1},
319+
Tau: []int{2},
320+
DecentralizationParam: []int{3},
321+
ExtraEntropy: nil,
322+
ProtocolVersionMajor: 2,
323+
ProtocolVersionMinor: 0,
324+
MinUTxOValue: 1000000,
325+
MinPoolCost: 340000000,
326+
},
327+
GenDelegs: []byte("mocked_cbor_data"),
328+
Unknown1: nil,
329+
Unknown2: nil,
330+
}
331+
332+
// Marshal to JSON
333+
jsonData, err := json.Marshal(genesisConfig)
334+
if err != nil {
335+
t.Fatalf("Failed to marshal JSON: %v", err)
336+
}
337+
338+
// Unmarshal back to struct
339+
var result localstatequery.GenesisConfigResult
340+
if err := json.Unmarshal(jsonData, &result); err != nil {
341+
t.Fatalf("Failed to unmarshal JSON: %v", err)
342+
}
343+
344+
//Compare everything after unmarshalling
345+
346+
if !reflect.DeepEqual(genesisConfig, result) {
347+
t.Errorf("Mismatch after JSON marshalling/unmarshalling. Expected:\n%+v\nGot:\n%+v", genesisConfig, result)
348+
} else {
349+
t.Logf("Successfully validated the GenesisConfigResult after JSON marshalling and unmarshalling.")
350+
}
351+
}

protocol/localstatequery/queries.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -585,34 +585,35 @@ type GenesisConfigResult struct {
585585
SlotLength int
586586
UpdateQuorum int
587587
MaxLovelaceSupply int64
588-
ProtocolParams struct {
589-
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
590-
_ struct{} `cbor:",toarray"`
591-
MinFeeA int
592-
MinFeeB int
593-
MaxBlockBodySize int
594-
MaxTxSize int
595-
MaxBlockHeaderSize int
596-
KeyDeposit int
597-
PoolDeposit int
598-
EMax int
599-
NOpt int
600-
A0 []int
601-
Rho []int
602-
Tau []int
603-
DecentralizationParam []int
604-
ExtraEntropy interface{}
605-
ProtocolVersionMajor int
606-
ProtocolVersionMinor int
607-
MinUTxOValue int
608-
MinPoolCost int
609-
}
588+
ProtocolParams GenesisConfigResultProtocolParameters
610589
// This value contains maps with bytestring keys, which we can't parse yet
611590
GenDelegs cbor.RawMessage
612591
Unknown1 interface{}
613592
Unknown2 interface{}
614593
}
615594

595+
type GenesisConfigResultProtocolParameters struct {
596+
_ struct{} `cbor:",toarray"`
597+
MinFeeA int
598+
MinFeeB int
599+
MaxBlockBodySize int
600+
MaxTxSize int
601+
MaxBlockHeaderSize int
602+
KeyDeposit int
603+
PoolDeposit int
604+
EMax int
605+
NOpt int
606+
A0 []int
607+
Rho []int
608+
Tau []int
609+
DecentralizationParam []int
610+
ExtraEntropy interface{}
611+
ProtocolVersionMajor int
612+
ProtocolVersionMinor int
613+
MinUTxOValue int
614+
MinPoolCost int
615+
}
616+
616617
// TODO (#864)
617618
type DebugNewEpochStateResult interface{}
618619

0 commit comments

Comments
 (0)