Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions protocol/localstatequery/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package localstatequery_test

import (
"encoding/json"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -285,3 +286,66 @@ func TestGetUTxOByAddress(t *testing.T) {
},
)
}

func TestGenesisConfigJSON(t *testing.T) {
genesisConfig := localstatequery.GenesisConfigResult{
Start: localstatequery.SystemStartResult{
Year: 2024,
Day: 35,
Picoseconds: 1234567890123456,
},
NetworkMagic: 764824073,
NetworkId: 1,
ActiveSlotsCoeff: []interface{}{0.1, 0.2},
SecurityParam: 2160,
EpochLength: 432000,
SlotsPerKESPeriod: 129600,
MaxKESEvolutions: 62,
SlotLength: 1,
UpdateQuorum: 5,
MaxLovelaceSupply: 45000000000000000,
ProtocolParams: localstatequery.GenesisConfigResultProtocolParameters{
MinFeeA: 44,
MinFeeB: 155381,
MaxBlockBodySize: 65536,
MaxTxSize: 16384,
MaxBlockHeaderSize: 1100,
KeyDeposit: 2000000,
PoolDeposit: 500000000,
EMax: 18,
NOpt: 500,
A0: []int{0},
Rho: []int{1},
Tau: []int{2},
DecentralizationParam: []int{3},
ExtraEntropy: nil,
ProtocolVersionMajor: 2,
ProtocolVersionMinor: 0,
MinUTxOValue: 1000000,
MinPoolCost: 340000000,
},
GenDelegs: []byte("mocked_cbor_data"),
Unknown1: nil,
Unknown2: nil,
}

// Marshal to JSON
jsonData, err := json.Marshal(genesisConfig)
if err != nil {
t.Fatalf("Failed to marshal JSON: %v", err)
}

// Unmarshal back to struct
var result localstatequery.GenesisConfigResult
if err := json.Unmarshal(jsonData, &result); err != nil {
t.Fatalf("Failed to unmarshal JSON: %v", err)
}

//Compare everything after unmarshalling

if !reflect.DeepEqual(genesisConfig, result) {
t.Errorf("Mismatch after JSON marshalling/unmarshalling. Expected:\n%+v\nGot:\n%+v", genesisConfig, result)
} else {
t.Logf("Successfully validated the GenesisConfigResult after JSON marshalling and unmarshalling.")
}
}
45 changes: 23 additions & 22 deletions protocol/localstatequery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,34 +585,35 @@ type GenesisConfigResult struct {
SlotLength int
UpdateQuorum int
MaxLovelaceSupply int64
ProtocolParams struct {
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
_ struct{} `cbor:",toarray"`
MinFeeA int
MinFeeB int
MaxBlockBodySize int
MaxTxSize int
MaxBlockHeaderSize int
KeyDeposit int
PoolDeposit int
EMax int
NOpt int
A0 []int
Rho []int
Tau []int
DecentralizationParam []int
ExtraEntropy interface{}
ProtocolVersionMajor int
ProtocolVersionMinor int
MinUTxOValue int
MinPoolCost int
}
ProtocolParams GenesisConfigResultProtocolParameters
// This value contains maps with bytestring keys, which we can't parse yet
GenDelegs cbor.RawMessage
Unknown1 interface{}
Unknown2 interface{}
}

type GenesisConfigResultProtocolParameters struct {
_ struct{} `cbor:",toarray"`
MinFeeA int
MinFeeB int
MaxBlockBodySize int
MaxTxSize int
MaxBlockHeaderSize int
KeyDeposit int
PoolDeposit int
EMax int
NOpt int
A0 []int
Rho []int
Tau []int
DecentralizationParam []int
ExtraEntropy interface{}
ProtocolVersionMajor int
ProtocolVersionMinor int
MinUTxOValue int
MinPoolCost int
}

// TODO (#864)
type DebugNewEpochStateResult interface{}

Expand Down