|
| 1 | +// Copyright 2024 Blink Labs Software |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package shelley_test |
| 16 | + |
| 17 | +import ( |
| 18 | + "encoding/json" |
| 19 | + "reflect" |
| 20 | + "testing" |
| 21 | + "time" |
| 22 | + |
| 23 | + "github.com/blinklabs-io/gouroboros/ledger/shelley" |
| 24 | +) |
| 25 | + |
| 26 | +const shelleyGenesisConfig = ` |
| 27 | +{ |
| 28 | + "activeSlotsCoeff": 0.05, |
| 29 | + "protocolParams": { |
| 30 | + "protocolVersion": { |
| 31 | + "minor": 0, |
| 32 | + "major": 2 |
| 33 | + }, |
| 34 | + "decentralisationParam": 1, |
| 35 | + "eMax": 18, |
| 36 | + "extraEntropy": { |
| 37 | + "tag": "NeutralNonce" |
| 38 | + }, |
| 39 | + "maxTxSize": 16384, |
| 40 | + "maxBlockBodySize": 65536, |
| 41 | + "maxBlockHeaderSize": 1100, |
| 42 | + "minFeeA": 44, |
| 43 | + "minFeeB": 155381, |
| 44 | + "minUTxOValue": 1000000, |
| 45 | + "poolDeposit": 500000000, |
| 46 | + "minPoolCost": 340000000, |
| 47 | + "keyDeposit": 2000000, |
| 48 | + "nOpt": 150, |
| 49 | + "rho": 0.003, |
| 50 | + "tau": 0.20, |
| 51 | + "a0": 0.3 |
| 52 | + }, |
| 53 | + "genDelegs": { |
| 54 | + "ad5463153dc3d24b9ff133e46136028bdc1edbb897f5a7cf1b37950c": { |
| 55 | + "delegate": "d9e5c76ad5ee778960804094a389f0b546b5c2b140a62f8ec43ea54d", |
| 56 | + "vrf": "64fa87e8b29a5b7bfbd6795677e3e878c505bc4a3649485d366b50abadec92d7" |
| 57 | + }, |
| 58 | + "b9547b8a57656539a8d9bc42c008e38d9c8bd9c8adbb1e73ad529497": { |
| 59 | + "delegate": "855d6fc1e54274e331e34478eeac8d060b0b90c1f9e8a2b01167c048", |
| 60 | + "vrf": "66d5167a1f426bd1adcc8bbf4b88c280d38c148d135cb41e3f5a39f948ad7fcc" |
| 61 | + }, |
| 62 | + "60baee25cbc90047e83fd01e1e57dc0b06d3d0cb150d0ab40bbfead1": { |
| 63 | + "delegate": "7f72a1826ae3b279782ab2bc582d0d2958de65bd86b2c4f82d8ba956", |
| 64 | + "vrf": "c0546d9aa5740afd569d3c2d9c412595cd60822bb6d9a4e8ce6c43d12bd0f674" |
| 65 | + }, |
| 66 | + "f7b341c14cd58fca4195a9b278cce1ef402dc0e06deb77e543cd1757": { |
| 67 | + "delegate": "69ae12f9e45c0c9122356c8e624b1fbbed6c22a2e3b4358cf0cb5011", |
| 68 | + "vrf": "6394a632af51a32768a6f12dac3485d9c0712d0b54e3f389f355385762a478f2" |
| 69 | + }, |
| 70 | + "162f94554ac8c225383a2248c245659eda870eaa82d0ef25fc7dcd82": { |
| 71 | + "delegate": "4485708022839a7b9b8b639a939c85ec0ed6999b5b6dc651b03c43f6", |
| 72 | + "vrf": "aba81e764b71006c515986bf7b37a72fbb5554f78e6775f08e384dbd572a4b32" |
| 73 | + }, |
| 74 | + "2075a095b3c844a29c24317a94a643ab8e22d54a3a3a72a420260af6": { |
| 75 | + "delegate": "6535db26347283990a252313a7903a45e3526ec25ddba381c071b25b", |
| 76 | + "vrf": "fcaca997b8105bd860876348fc2c6e68b13607f9bbd23515cd2193b555d267af" |
| 77 | + }, |
| 78 | + "268cfc0b89e910ead22e0ade91493d8212f53f3e2164b2e4bef0819b": { |
| 79 | + "delegate": "1d4f2e1fda43070d71bb22a5522f86943c7c18aeb4fa47a362c27e23", |
| 80 | + "vrf": "63ef48bc5355f3e7973100c371d6a095251c80ceb40559f4750aa7014a6fb6db" |
| 81 | + } |
| 82 | + }, |
| 83 | + "updateQuorum": 5, |
| 84 | + "networkId": "Mainnet", |
| 85 | + "initialFunds": {}, |
| 86 | + "maxLovelaceSupply": 45000000000000000, |
| 87 | + "networkMagic": 764824073, |
| 88 | + "epochLength": 432000, |
| 89 | + "systemStart": "2017-09-23T21:44:51Z", |
| 90 | + "slotsPerKESPeriod": 129600, |
| 91 | + "slotLength": 1, |
| 92 | + "maxKESEvolutions": 62, |
| 93 | + "securityParam": 2160 |
| 94 | +} |
| 95 | +` |
| 96 | + |
| 97 | +var expectedGenesisObj = shelley.ShelleyGenesis{ |
| 98 | + SystemStart: time.Date(2017, time.September, 23, 21, 44, 51, 0, time.UTC), |
| 99 | + NetworkMagic: 764824073, |
| 100 | + NetworkId: "Mainnet", |
| 101 | + ActiveSlotsCoeff: 0.05, |
| 102 | + SecurityParam: 2160, |
| 103 | + EpochLength: 432000, |
| 104 | + SlotsPerKESPeriod: 129600, |
| 105 | + MaxKESEvolutions: 62, |
| 106 | + SlotLength: 1, |
| 107 | + UpdateQuorum: 5, |
| 108 | + MaxLovelaceSupply: 45000000000000000, |
| 109 | + ProtocolParameters: shelley.ShelleyGenesisProtocolParams{ |
| 110 | + MinFeeA: 44, |
| 111 | + MinFeeB: 155381, |
| 112 | + MaxBlockBodySize: 65536, |
| 113 | + MaxTxSize: 16384, |
| 114 | + MaxBlockHeaderSize: 1100, |
| 115 | + KeyDeposit: 2000000, |
| 116 | + PoolDeposit: 500000000, |
| 117 | + MaxEpoch: 18, |
| 118 | + NOpt: 150, |
| 119 | + A0: 0.3, |
| 120 | + Rho: 0.003, |
| 121 | + Tau: 0.2, |
| 122 | + Decentralization: 1, |
| 123 | + ExtraEntropy: map[string]string{ |
| 124 | + "tag": "NeutralNonce", |
| 125 | + }, |
| 126 | + ProtocolVersion: struct { |
| 127 | + Major uint |
| 128 | + Minor uint |
| 129 | + }{ |
| 130 | + Major: 2, |
| 131 | + Minor: 0, |
| 132 | + }, |
| 133 | + MinUtxoValue: 1000000, |
| 134 | + MinPoolCost: 340000000, |
| 135 | + }, |
| 136 | + GenDelegs: map[string]map[string]any{ |
| 137 | + "162f94554ac8c225383a2248c245659eda870eaa82d0ef25fc7dcd82": map[string]any{ |
| 138 | + "delegate": "4485708022839a7b9b8b639a939c85ec0ed6999b5b6dc651b03c43f6", |
| 139 | + "vrf": "aba81e764b71006c515986bf7b37a72fbb5554f78e6775f08e384dbd572a4b32", |
| 140 | + }, |
| 141 | + "2075a095b3c844a29c24317a94a643ab8e22d54a3a3a72a420260af6": map[string]any{ |
| 142 | + "delegate": "6535db26347283990a252313a7903a45e3526ec25ddba381c071b25b", |
| 143 | + "vrf": "fcaca997b8105bd860876348fc2c6e68b13607f9bbd23515cd2193b555d267af", |
| 144 | + }, |
| 145 | + "268cfc0b89e910ead22e0ade91493d8212f53f3e2164b2e4bef0819b": map[string]any{ |
| 146 | + "delegate": "1d4f2e1fda43070d71bb22a5522f86943c7c18aeb4fa47a362c27e23", |
| 147 | + "vrf": "63ef48bc5355f3e7973100c371d6a095251c80ceb40559f4750aa7014a6fb6db", |
| 148 | + }, |
| 149 | + "60baee25cbc90047e83fd01e1e57dc0b06d3d0cb150d0ab40bbfead1": map[string]any{ |
| 150 | + "delegate": "7f72a1826ae3b279782ab2bc582d0d2958de65bd86b2c4f82d8ba956", |
| 151 | + "vrf": "c0546d9aa5740afd569d3c2d9c412595cd60822bb6d9a4e8ce6c43d12bd0f674", |
| 152 | + }, |
| 153 | + "ad5463153dc3d24b9ff133e46136028bdc1edbb897f5a7cf1b37950c": map[string]any{ |
| 154 | + "delegate": "d9e5c76ad5ee778960804094a389f0b546b5c2b140a62f8ec43ea54d", |
| 155 | + "vrf": "64fa87e8b29a5b7bfbd6795677e3e878c505bc4a3649485d366b50abadec92d7", |
| 156 | + }, |
| 157 | + "b9547b8a57656539a8d9bc42c008e38d9c8bd9c8adbb1e73ad529497": map[string]any{ |
| 158 | + "delegate": "855d6fc1e54274e331e34478eeac8d060b0b90c1f9e8a2b01167c048", |
| 159 | + "vrf": "66d5167a1f426bd1adcc8bbf4b88c280d38c148d135cb41e3f5a39f948ad7fcc", |
| 160 | + }, |
| 161 | + "f7b341c14cd58fca4195a9b278cce1ef402dc0e06deb77e543cd1757": map[string]any{ |
| 162 | + "delegate": "69ae12f9e45c0c9122356c8e624b1fbbed6c22a2e3b4358cf0cb5011", |
| 163 | + "vrf": "6394a632af51a32768a6f12dac3485d9c0712d0b54e3f389f355385762a478f2", |
| 164 | + }, |
| 165 | + }, |
| 166 | + InitialFunds: map[string]any{}, |
| 167 | +} |
| 168 | + |
| 169 | +func TestGenesisFromJson(t *testing.T) { |
| 170 | + var tmpGenesis shelley.ShelleyGenesis |
| 171 | + if err := json.Unmarshal([]byte(shelleyGenesisConfig), &tmpGenesis); err != nil { |
| 172 | + t.Fatalf("unexpected error: %s", err) |
| 173 | + } |
| 174 | + if !reflect.DeepEqual(tmpGenesis, expectedGenesisObj) { |
| 175 | + t.Fatalf("did not get expected object:\n got: %#v\n wanted: %#v", tmpGenesis, expectedGenesisObj) |
| 176 | + } |
| 177 | +} |
0 commit comments