|
15 | 15 | package conway_test
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "encoding/json" |
18 | 19 | "math/big"
|
19 | 20 | "reflect"
|
20 | 21 | "strings"
|
@@ -401,3 +402,64 @@ func TestGenesisFromJson(t *testing.T) {
|
401 | 402 | )
|
402 | 403 | }
|
403 | 404 | }
|
| 405 | + |
| 406 | +func TestNewConwayGenesisFromReader(t *testing.T) { |
| 407 | + jsonData := `{ |
| 408 | + "poolVotingThresholds": { |
| 409 | + "committeeNormal": null, |
| 410 | + "committeeNoConfidence": null, |
| 411 | + "hardForkInitiation": null, |
| 412 | + "motionNoConfidence": null, |
| 413 | + "ppSecurityGroup": null |
| 414 | + }, |
| 415 | + "dRepVotingThresholds": { |
| 416 | + "motionNoConfidence": null, |
| 417 | + "committeeNormal": null, |
| 418 | + "committeeNoConfidence": null, |
| 419 | + "updateToConstitution": null, |
| 420 | + "hardForkInitiation": null, |
| 421 | + "ppNetworkGroup": null, |
| 422 | + "ppEconomicGroup": null, |
| 423 | + "ppTechnicalGroup": null, |
| 424 | + "ppGovGroup": null, |
| 425 | + "treasuryWithdrawal": null |
| 426 | + }, |
| 427 | + "committeeMinSize": 5, |
| 428 | + "committeeMaxTermLength": 365, |
| 429 | + "govActionLifetime": 90, |
| 430 | + "govActionDeposit": 1000, |
| 431 | + "dRepDeposit": 200, |
| 432 | + "dRepActivity": 60, |
| 433 | + "minFeeRefScriptCostPerByte": null, |
| 434 | + "plutusV3CostModel": [1, 2, 3], |
| 435 | + "constitution": { |
| 436 | + "anchor": { |
| 437 | + "dataHash": "abc123", |
| 438 | + "url": "https://example.com" |
| 439 | + }, |
| 440 | + "script": "example-script" |
| 441 | + }, |
| 442 | + "committee": { |
| 443 | + "members": { "key1": 1 }, |
| 444 | + "threshold": { "key1": 2 } |
| 445 | + } |
| 446 | + }` |
| 447 | + |
| 448 | + expected := conway.ConwayGenesis{} |
| 449 | + err := json.Unmarshal([]byte(jsonData), &expected) |
| 450 | + if err != nil { |
| 451 | + t.Errorf("Failed to unmarshal expected JSON: %v", err) |
| 452 | + } |
| 453 | + |
| 454 | + reader := strings.NewReader(jsonData) |
| 455 | + actual, err := conway.NewConwayGenesisFromReader(reader) |
| 456 | + if err != nil { |
| 457 | + t.Errorf("Failed to decode JSON via NewConwayGenesisFromReader: %v", err) |
| 458 | + } |
| 459 | + |
| 460 | + if !reflect.DeepEqual(expected, actual) { |
| 461 | + t.Errorf("Mismatch between expected and actual structs\nExpected: %#v\nActual: %#v", expected, actual) |
| 462 | + } else { |
| 463 | + t.Logf("ConwayGenesis decoded correctly and matches expected structure") |
| 464 | + } |
| 465 | +} |
0 commit comments