@@ -250,3 +250,168 @@ func TestGenesisUtxos(t *testing.T) {
250
250
)
251
251
}
252
252
}
253
+
254
+ const shelleyGenesisWithStaking = `
255
+ {
256
+ "activeSlotsCoeff": 0.05,
257
+ "protocolParams": {
258
+ "protocolVersion": {
259
+ "minor": 0,
260
+ "major": 2
261
+ },
262
+ "decentralisationParam": 1,
263
+ "eMax": 18,
264
+ "extraEntropy": {
265
+ "tag": "NeutralNonce"
266
+ },
267
+ "maxTxSize": 16384,
268
+ "maxBlockBodySize": 65536,
269
+ "maxBlockHeaderSize": 1100,
270
+ "minFeeA": 44,
271
+ "minFeeB": 155381,
272
+ "minUTxOValue": 1000000,
273
+ "poolDeposit": 500000000,
274
+ "minPoolCost": 340000000,
275
+ "keyDeposit": 2000000,
276
+ "nOpt": 150,
277
+ "rho": 0.003,
278
+ "tau": 0.20,
279
+ "a0": 0.3
280
+ },
281
+ "genDelegs": {},
282
+ "updateQuorum": 5,
283
+ "networkId": "Testnet",
284
+ "initialFunds": {},
285
+ "maxLovelaceSupply": 45000000000000000,
286
+ "networkMagic": 764824073,
287
+ "epochLength": 432000,
288
+ "systemStart": "2017-09-23T21:44:51Z",
289
+ "slotsPerKESPeriod": 129600,
290
+ "slotLength": 1,
291
+ "maxKESEvolutions": 62,
292
+ "securityParam": 2160,
293
+ "staking": {
294
+ "pools": {
295
+ "0aedc455785463235311c990f68742c9043cd79af09ab31c2ba5e195": {
296
+ "cost": 340000000,
297
+ "margin": 0.0,
298
+ "metadata": null,
299
+ "owners": [],
300
+ "pledge": 0,
301
+ "publicKey": "0aedc455785463235311c990f68742c9043cd79af09ab31c2ba5e195",
302
+ "relays": [
303
+ {
304
+ "single host name": {
305
+ "dnsName": "p4.example",
306
+ "port": 3001
307
+ }
308
+ }
309
+ ],
310
+ "rewardAccount": {
311
+ "credential": {
312
+ "key hash": "6079cde665c2035b8d9ac8929307bdd7f20a51e678e9d4a5e39ace3a"
313
+ },
314
+ "network": "Testnet"
315
+ },
316
+ "vrf": "eb53a17fbad9b7ea0bcf1e1ea89355305600d593b426dfc3084a924d8877d47e"
317
+ }
318
+ },
319
+ "stake": {
320
+ "24632b71152f31516054075897d0d4ababc33204f8a8661136d49e36": "0aedc455785463235311c990f68742c9043cd79af09ab31c2ba5e195"
321
+ }
322
+ }
323
+ }
324
+ `
325
+
326
+ func TestGenesisStaking (t * testing.T ) {
327
+ tmpGenesis , err := shelley .NewShelleyGenesisFromReader (
328
+ strings .NewReader (shelleyGenesisWithStaking ),
329
+ )
330
+ if err != nil {
331
+ t .Fatalf ("unexpected error: %s" , err )
332
+ }
333
+
334
+ // Test GetInitialPools
335
+ pools , delegators , err := tmpGenesis .GetInitialPools ()
336
+ if err != nil {
337
+ t .Fatalf ("unexpected error: %s" , err )
338
+ }
339
+
340
+ expectedPoolId := "0aedc455785463235311c990f68742c9043cd79af09ab31c2ba5e195"
341
+ if len (pools ) != 1 {
342
+ t .Fatalf ("expected 1 pool, got %d" , len (pools ))
343
+ }
344
+
345
+ pool , exists := pools [expectedPoolId ]
346
+ if ! exists {
347
+ t .Fatalf ("expected pool with ID %s not found" , expectedPoolId )
348
+ }
349
+
350
+ // Verify pool details
351
+ if pool .Cost != 340000000 {
352
+ t .Errorf ("expected pool cost 340000000, got %d" , pool .Cost )
353
+ }
354
+ if pool .Margin != 0.0 {
355
+ t .Errorf ("expected pool margin 0.0, got %f" , pool .Margin )
356
+ }
357
+ if pool .Pledge != 0 {
358
+ t .Errorf ("expected pool pledge 0, got %d" , pool .Pledge )
359
+ }
360
+ if pool .PublicKey != expectedPoolId {
361
+ t .Errorf ("expected pool public key %s, got %s" , expectedPoolId , pool .PublicKey )
362
+ }
363
+ if pool .Vrf != "eb53a17fbad9b7ea0bcf1e1ea89355305600d593b426dfc3084a924d8877d47e" {
364
+ t .Errorf ("unexpected pool VRF key" )
365
+ }
366
+
367
+ // Verify delegators
368
+ expectedStakeAddr := "24632b71152f31516054075897d0d4ababc33204f8a8661136d49e36"
369
+ if len (delegators [expectedPoolId ]) != 1 {
370
+ t .Fatalf ("expected 1 delegator for pool, got %d" , len (delegators [expectedPoolId ]))
371
+ }
372
+ if delegators [expectedPoolId ][0 ] != expectedStakeAddr {
373
+ t .Errorf ("expected stake address %s, got %s" , expectedStakeAddr , delegators [expectedPoolId ][0 ])
374
+ }
375
+
376
+ // Test GetPoolById
377
+ poolById , delegatorsById , err := tmpGenesis .GetPoolById (expectedPoolId )
378
+ if err != nil {
379
+ t .Fatalf ("unexpected error: %s" , err )
380
+ }
381
+
382
+ if poolById .PublicKey != expectedPoolId {
383
+ t .Errorf ("GetPoolById: expected pool public key %s, got %s" , expectedPoolId , poolById .PublicKey )
384
+ }
385
+
386
+ if len (delegatorsById ) != 1 || delegatorsById [0 ] != expectedStakeAddr {
387
+ t .Errorf ("GetPoolById: unexpected delegators" )
388
+ }
389
+
390
+ // Test non-existent pool
391
+ _ , _ , err = tmpGenesis .GetPoolById ("nonexistentpoolid" )
392
+ if err == nil {
393
+ t .Error ("expected error for non-existent pool, got nil" )
394
+ } else if err .Error () != "pool not found" {
395
+ t .Errorf ("expected 'pool not found' error, got: %v" , err )
396
+ }
397
+ }
398
+
399
+ func TestGenesisStakingCBOR (t * testing.T ) {
400
+ tmpGenesis , err := shelley .NewShelleyGenesisFromReader (
401
+ strings .NewReader (shelleyGenesisWithStaking ),
402
+ )
403
+ if err != nil {
404
+ t .Fatalf ("unexpected error: %s" , err )
405
+ }
406
+
407
+ // Test CBOR marshaling
408
+ cborData , err := tmpGenesis .MarshalCBOR ()
409
+ if err != nil {
410
+ t .Fatalf ("unexpected error during CBOR marshaling: %s" , err )
411
+ }
412
+
413
+ if len (cborData ) == 0 {
414
+ t .Error ("expected non-empty CBOR data, got empty" )
415
+ }
416
+
417
+ }
0 commit comments