|
15 | 15 | package localstatequery_test
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "encoding/json" |
18 | 19 | "fmt"
|
19 | 20 | "reflect"
|
20 | 21 | "testing"
|
@@ -285,3 +286,66 @@ func TestGetUTxOByAddress(t *testing.T) {
|
285 | 286 | },
|
286 | 287 | )
|
287 | 288 | }
|
| 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 | +} |
0 commit comments