-
Notifications
You must be signed in to change notification settings - Fork 155
/
GovSpec.hs
1163 lines (1130 loc) · 41.2 KB
/
GovSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Test.Cardano.Ledger.Conway.Imp.GovSpec (spec) where
import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.Allegra.Scripts (
pattern RequireAllOf,
pattern RequireAnyOf,
pattern RequireMOf,
pattern RequireSignature,
)
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Coin (Coin (Coin))
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.Rules (ConwayGovPredFailure (..))
import Cardano.Ledger.Credential (Credential (KeyHashObj))
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Val (zero, (<->))
import Data.Default.Class (Default (..))
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import Data.Tree
import Lens.Micro
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Core.Rational (IsRatio (..))
import Test.Cardano.Ledger.Imp.Common hiding (Success)
spec ::
forall era.
( ConwayEraImp era
, GovState era ~ ConwayGovState era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
spec =
describe "GOV" $ do
hardForkSpec
pparamUpdateSpec
proposalsSpec
votingSpec
constitutionSpec
policySpec
networkIdSpec
predicateFailuresSpec
predicateFailuresSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
predicateFailuresSpec =
describe "Predicate failures" $ do
it "ExpirationEpochTooSmall" $ do
pp <- getsNES $ nesEsL . curPParamsEpochStateL
committeeC <- KeyHashObj <$> freshKeyHash
rewardAccount <- registerRewardAccount
let expiration = EpochNo 1
action =
UpdateCommittee
SNothing
mempty
(Map.singleton committeeC expiration)
(0 %! 1)
passEpoch
submitFailingProposal
( ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = action
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
)
[injectFailure $ ExpirationEpochTooSmall $ Map.singleton committeeC expiration]
it "ProposalDepositIncorrect" $ do
committeeC <- KeyHashObj <$> freshKeyHash
rewardAccount <- registerRewardAccount
let expiration = EpochNo 1
actionDeposit = Coin 2
action =
UpdateCommittee
SNothing
mempty
(Map.singleton committeeC expiration)
(0 %! 1)
modifyPParams $ ppGovActionDepositL .~ actionDeposit
submitFailingProposal
( ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = action
, pProcDeposit = actionDeposit <-> Coin 1
, pProcAnchor = def
}
)
[injectFailure $ ProposalDepositIncorrect (actionDeposit <-> Coin 1) actionDeposit]
it "ConflictingCommitteeUpdate" $ do
pp <- getsNES $ nesEsL . curPParamsEpochStateL
committeeC <- KeyHashObj <$> freshKeyHash
rewardAccount <- registerRewardAccount
let expiration = EpochNo 1
action =
UpdateCommittee
SNothing
(Set.singleton committeeC)
(Map.singleton committeeC expiration)
(0 %! 1)
submitFailingProposal
( ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = action
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
)
[injectFailure $ ConflictingCommitteeUpdate $ Set.singleton committeeC]
hardForkSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
hardForkSpec =
describe "HardFork" $ do
describe "Hardfork is the first one (doesn't have a GovPurposeId) " $ do
it "Hardfork minorFollow" (firstHardForkFollows minorFollow)
it "Hardfork majorFollow" (firstHardForkFollows majorFollow)
it "Hardfork cantFollow" firstHardForkCantFollow
describe "Hardfork is the second one (has a GovPurposeId)" $ do
it "Hardfork minorFollow" (secondHardForkFollows minorFollow)
it "Hardfork majorFollow" (secondHardForkFollows majorFollow)
it "Hardfork cantFollow" secondHardForkCantFollow
pparamUpdateSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
pparamUpdateSpec =
describe "PParamUpdate" $ do
describe "PPU needs to be wellformed" $ do
let testMalformedProposal lbl lenz val = it lbl $ do
pp <- getsNES $ nesEsL . curPParamsEpochStateL
rew <- registerRewardAccount
let ppUpdate =
emptyPParamsUpdate
& lenz .~ SJust val
ga = ParameterChange SNothing ppUpdate SNothing
submitFailingProposal
( ProposalProcedure
{ pProcReturnAddr = rew
, pProcGovAction = ga
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
)
[injectFailure $ MalformedProposal ga]
testMalformedProposal
"ppuMaxBBSizeL cannot be 0"
ppuMaxBBSizeL
0
testMalformedProposal
"ppuMaxTxSizeL cannot be 0"
ppuMaxTxSizeL
0
testMalformedProposal
"ppuMaxBHSizeL cannot be 0"
ppuMaxBHSizeL
0
testMalformedProposal
"ppuMaxValSizeL cannot be 0"
ppuMaxValSizeL
0
testMalformedProposal
"ppuCollateralPercentageL cannot be 0"
ppuCollateralPercentageL
0
testMalformedProposal
"ppuCommitteeMaxTermLengthL cannot be 0"
ppuCommitteeMaxTermLengthL
$ EpochInterval 0
testMalformedProposal
"ppuGovActionLifetimeL cannot be 0"
ppuGovActionLifetimeL
$ EpochInterval 0
testMalformedProposal
"ppuPoolDepositL cannot be 0"
ppuPoolDepositL
zero
testMalformedProposal
"ppuGovActionDepositL cannot be 0"
ppuGovActionDepositL
zero
testMalformedProposal
"ppuDRepDepositL cannot be 0"
ppuDRepDepositL
zero
it "PPU cannot be empty" $ do
pp <- getsNES $ nesEsL . curPParamsEpochStateL
rew <- registerRewardAccount
let ga = ParameterChange SNothing emptyPParamsUpdate SNothing
submitFailingProposal
( ProposalProcedure
{ pProcReturnAddr = rew
, pProcGovAction = ga
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
)
[injectFailure $ MalformedProposal ga]
proposalsSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
proposalsSpec =
describe "Proposals" $ do
describe "Consistency" $ do
it "Proposals submitted without proper parent fail" $ do
let mkCorruptGovActionId :: GovActionId c -> GovActionId c
mkCorruptGovActionId (GovActionId txi (GovActionIx gaix)) =
GovActionId txi $ GovActionIx $ gaix + 999
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
Node p1 [Node _p11 []] <-
submitConstitutionGovActionTree
SNothing
$ Node
()
[ Node () []
]
constitutionHash <- freshSafeHash
pp <- getsNES $ nesEsL . curPParamsEpochStateL
khPropRwd <- freshKeyHash
let constitutionAction =
NewConstitution
(SJust $ GovPurposeId $ mkCorruptGovActionId p1)
( Constitution
( Anchor
(fromJust $ textToUrl 64 "constitution.after.0")
constitutionHash
)
SNothing
)
constitutionProposal =
ProposalProcedure
{ pProcDeposit = pp ^. ppGovActionDepositL
, pProcReturnAddr = RewardAccount Testnet (KeyHashObj khPropRwd)
, pProcGovAction = constitutionAction
, pProcAnchor = def
}
submitFailingProposal
constitutionProposal
[ injectFailure $ InvalidPrevGovActionId constitutionProposal
]
it "Subtrees are pruned when proposals expire" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
p1 <- submitInitConstitutionGovAction
passNEpochs 3
a <-
submitConstitutionGovActionTree
(SJust p1)
$ Node
()
[ Node () []
, Node () []
]
b <-
submitConstitutionGovActionTree
SNothing
$ Node
()
[ Node () []
]
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p1) [SJust <$> a]
, SJust <$> b
]
]
passNEpochs 3
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node SNothing [SJust <$> b]
]
it "Subtrees are pruned when competing proposals are enacted" $ do
(dRep, committeeMember, GovPurposeId committeeGovActionId) <- electBasicCommittee
a@[ _
, b@(Node p2 _)
] <-
submitConstitutionGovActionForest
SNothing
[ Node
()
[ Node
()
[ Node () []
, Node () []
]
]
, Node
()
[ Node () []
]
]
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node (SJust committeeGovActionId) []
, Node SNothing (fmap SJust <$> a)
]
passEpoch
submitYesVote_ (DRepVoter dRep) p2
submitYesVote_ (CommitteeVoter committeeMember) p2
passNEpochs 2
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node (SJust committeeGovActionId) []
, SJust <$> b
]
it "Subtrees are pruned when proposals expire over multiple rounds" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
p1 <- submitInitConstitutionGovAction
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p1) []
]
]
passEpoch
p2 <- submitInitConstitutionGovAction
p11 <- submitChildConstitutionGovAction p1
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p1) [Node (SJust p11) []]
, Node (SJust p2) []
]
]
passEpoch
p3 <- submitInitConstitutionGovAction
p21 <- submitChildConstitutionGovAction p2
a <-
submitConstitutionGovActionForest
(SJust p11)
[ Node () []
, Node () []
]
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node
(SJust p1)
[ Node
(SJust p11)
(fmap SJust <$> a)
]
, Node (SJust p2) [Node (SJust p21) []]
, Node (SJust p3) []
]
]
passEpoch
p4 <- submitInitConstitutionGovAction
p31 <- submitChildConstitutionGovAction p3
p211 <- submitChildConstitutionGovAction p21
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node
(SJust p1)
[ Node
(SJust p11)
(fmap SJust <$> a)
]
, Node (SJust p2) [Node (SJust p21) [Node (SJust p211) []]]
, Node (SJust p3) [Node (SJust p31) []]
, Node (SJust p4) []
]
]
passNEpochs 3
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p2) [Node (SJust p21) [Node (SJust p211) []]]
, Node (SJust p3) [Node (SJust p31) []]
, Node (SJust p4) []
]
]
p5 <- submitInitConstitutionGovAction
p41 <- submitChildConstitutionGovAction p4
p311 <- submitChildConstitutionGovAction p31
p212 <- submitChildConstitutionGovAction p21
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node
(SJust p2)
[ Node
(SJust p21)
[ Node (SJust p211) []
, Node (SJust p212) []
]
]
, Node (SJust p3) [Node (SJust p31) [Node (SJust p311) []]]
, Node (SJust p4) [Node (SJust p41) []]
, Node (SJust p5) []
]
]
passEpoch
p6 <- submitInitConstitutionGovAction
p51 <- submitChildConstitutionGovAction p5
p411 <- submitChildConstitutionGovAction p41
p312 <- submitChildConstitutionGovAction p31
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node
(SJust p3)
[ Node
(SJust p31)
[ Node (SJust p311) []
, Node (SJust p312) []
]
]
, Node (SJust p4) [Node (SJust p41) [Node (SJust p411) []]]
, Node (SJust p5) [Node (SJust p51) []]
, Node (SJust p6) []
]
]
passEpoch
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p4) [Node (SJust p41) [Node (SJust p411) []]]
, Node (SJust p5) [Node (SJust p51) []]
, Node (SJust p6) []
]
]
passEpoch
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p5) [Node (SJust p51) []]
, Node (SJust p6) []
]
]
passNEpochs 3
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node
SNothing
[ Node (SJust p6) []
]
]
passEpoch
getProposalsForest
`shouldReturn` [ Node SNothing []
, Node SNothing []
, Node SNothing []
, Node SNothing []
]
it "Subtrees are pruned when competing proposals are enacted over multiple rounds" $ do
(dRep, committeeMember, _) <- electBasicCommittee
a@[ c
, Node
p2
[ Node p21 []
, Node p22 []
]
, Node p3 []
] <-
submitConstitutionGovActionForest
SNothing
[ Node
()
[ Node
()
[ Node () []
, Node () []
]
]
, Node
()
[ Node () []
, Node () []
]
, Node () []
]
submitYesVote_ (DRepVoter dRep) p2
submitYesVote_ (CommitteeVoter committeeMember) p2
submitYesVote_ (DRepVoter dRep) p21
submitYesVote_ (CommitteeVoter committeeMember) p21
submitYesVote_ (DRepVoter dRep) p3
submitYesVote_ (CommitteeVoter committeeMember) p3 -- Two competing proposals break the tie based on proposal order
fmap (!! 3) getProposalsForest
`shouldReturn` Node SNothing (fmap SJust <$> a)
passEpoch
p4 <- submitInitConstitutionGovAction
p31 <- submitChildConstitutionGovAction p3
p211 <- submitChildConstitutionGovAction p21
fmap (!! 3) getProposalsForest
`shouldReturn` Node
SNothing
[ SJust <$> c
, Node
(SJust p2)
[ Node (SJust p21) [Node (SJust p211) []]
, Node (SJust p22) []
]
, Node (SJust p3) [Node (SJust p31) []]
, Node (SJust p4) []
]
passEpoch
fmap (!! 3) getProposalsForest
`shouldReturn` Node
(SJust p2)
[ Node (SJust p21) [Node (SJust p211) []]
, Node (SJust p22) []
]
[ Node p212 []
, Node p213 []
, Node p214 []
] <-
submitConstitutionGovActionForest
(SJust p21)
[ Node () []
, Node () []
, Node () []
]
p2131 <- submitChildConstitutionGovAction p213
p2141 <- submitChildConstitutionGovAction p214
submitYesVote_ (DRepVoter dRep) p212
submitYesVote_ (CommitteeVoter committeeMember) p212
fmap (!! 3) getProposalsForest
`shouldReturn` Node
(SJust p2)
[ Node
(SJust p21)
[ Node (SJust p211) []
, Node (SJust p212) []
, Node (SJust p213) [Node (SJust p2131) []]
, Node (SJust p214) [Node (SJust p2141) []]
]
, Node (SJust p22) []
]
passNEpochs 2
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p212) []
props <- getProposals
proposalsSize props `shouldBe` 0
it "Votes from subsequent epochs are considered for ratification" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
(dRep, committeeMember, _) <- electBasicCommittee
[Node p1 []] <-
submitConstitutionGovActionForest
SNothing
[Node () []]
fmap (!! 3) getProposalsForest
`shouldReturn` Node SNothing [Node (SJust p1) []]
passNEpochs 2
submitYesVote_ (DRepVoter dRep) p1
submitYesVote_ (CommitteeVoter committeeMember) p1
passNEpochs 2
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p1) []
it "Subtrees are pruned for both enactment and expiry over multiple rounds" $ do
(dRep, committeeMember, _) <- electBasicCommittee
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
[ a@( Node
p1
[ b@( Node
p11
[ Node _p111 []
, Node _p112 []
]
)
]
)
, Node
_p2
[ Node _p21 []
, Node _p22 []
]
, Node p3 []
] <-
submitConstitutionGovActionForest
SNothing
[ Node
()
[ Node
()
[ Node () []
, Node () []
]
]
, Node
()
[ Node () []
, Node () []
]
, Node () []
]
passNEpochs 2
submitYesVote_ (DRepVoter dRep) p1
submitYesVote_ (CommitteeVoter committeeMember) p1
submitYesVote_ (DRepVoter dRep) p11
submitYesVote_ (CommitteeVoter committeeMember) p11
submitYesVote_ (DRepVoter dRep) p3
submitYesVote_ (CommitteeVoter committeeMember) p3 -- Two competing proposals break the tie based on proposal order
passNEpochs 2
fmap (!! 3) getProposalsForest
`shouldReturn` SJust
<$> a
passEpoch -- ConstitutionPurpose is a delayed action
fmap (!! 3) getProposalsForest
`shouldReturn` SJust
<$> b
passNEpochs 2
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p11) []
c@[ Node _p113 []
, Node _p114 []
] <-
submitConstitutionGovActionForest
(SJust p11)
[ Node () []
, Node () []
]
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p11) (fmap SJust <$> c)
passNEpochs 4
d@[ Node _p115 []
, Node p116 []
] <-
submitConstitutionGovActionForest
(SJust p11)
[ Node () []
, Node () []
]
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p11) (fmap SJust <$> (c <> d))
passNEpochs 2
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p11) (fmap SJust <$> d)
submitYesVote_ (DRepVoter dRep) p116
submitYesVote_ (CommitteeVoter committeeMember) p116
passNEpochs 3
fmap (!! 3) getProposalsForest
`shouldReturn` Node (SJust p116) []
votingSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
votingSpec =
describe "Voting" $ do
describe "fails for" $ do
it "expired gov-actions" $ do
-- Voting after the 3rd epoch should fail
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
(khDRep, _, _) <- setupSingleDRep 1_000_000
(govActionId, _) <- submitConstitution SNothing
passEpoch
passEpoch
passEpoch
let voter = DRepVoter $ KeyHashObj khDRep
submitFailingVote
voter
govActionId
[ injectFailure $ VotingOnExpiredGovAction [(voter, govActionId)]
]
it "non-existent gov-actions" $ do
(khDRep, _, _) <- setupSingleDRep 1_000_000
(govActionId, _) <- submitConstitution SNothing
let voter = DRepVoter $ KeyHashObj khDRep
dummyGaid = govActionId {gaidGovActionIx = GovActionIx 99} -- non-existent `GovActionId`
submitFailingVote
voter
dummyGaid
[injectFailure $ GovActionsDoNotExist $ pure dummyGaid]
it
"committee member voting on committee change"
committeeMemberVotingOnCommitteeChange
it "non-committee-member voting on committee change as a committee member" $ do
(_, _, prevGovActionId) <- electBasicCommittee
credCandidate <- KeyHashObj <$> freshKeyHash
credVoter <- KeyHashObj <$> freshKeyHash
committeeUpdateId <-
submitGovAction $
UpdateCommittee
(SJust prevGovActionId)
mempty
(Map.singleton credCandidate $ EpochNo 28)
(3 %! 5)
let voter = CommitteeVoter credVoter
trySubmitVote VoteNo voter committeeUpdateId
`shouldReturn` Left
[ injectFailure $ DisallowedVoters [(voter, committeeUpdateId)]
]
it
"committee member can't vote on committee update when sandwiched between other votes"
ccVoteOnConstitutionFailsWithMultipleVotes
constitutionSpec ::
forall era.
( ConwayEraImp era
, GovState era ~ ConwayGovState era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
constitutionSpec =
describe "Constitution proposals" $ do
describe "accepted for" $ do
it "empty PrevGovId before the first constitution is enacted" $ do
-- Initial proposal does not need a GovPurposeId but after it is enacted, the
-- following ones are not
_ <- submitConstitution SNothing
-- Until the first proposal is enacted all proposals with empty GovPurposeIds are valid
void $ submitConstitution SNothing
it "valid GovPurposeId" $ do
(dRep, committeeMember, _) <- electBasicCommittee
constitution <- arbitrary
gaidConstitutionProp <- enactConstitution SNothing constitution dRep committeeMember
constitution1 <- arbitrary
void $ enactConstitution (SJust $ GovPurposeId gaidConstitutionProp) constitution1 dRep committeeMember
describe "rejected for" $ do
it "empty PrevGovId after the first constitution was enacted" $ do
(dRep, committeeMember, _) <- electBasicCommittee
(govActionId, _constitution) <- submitConstitution SNothing
submitYesVote_ (DRepVoter dRep) govActionId
submitYesVote_ (CommitteeVoter committeeMember) govActionId
passNEpochs 2
constitution <- arbitrary
let invalidNewConstitutionGovAction =
NewConstitution
SNothing
constitution
invalidNewConstitutionProposal <- proposalWithRewardAccount invalidNewConstitutionGovAction
submitFailingProposal
invalidNewConstitutionProposal
[ injectFailure $ InvalidPrevGovActionId invalidNewConstitutionProposal
]
it "invalid index in GovPurposeId" $ do
(_dRep, _committeeMember, _) <- electBasicCommittee
(govActionId, _constitution) <- submitConstitution SNothing
passNEpochs 2
constitution <- arbitrary
let invalidPrevGovActionId =
-- Expected Ix = 0
GovPurposeId (govActionId {gaidGovActionIx = GovActionIx 1})
invalidNewConstitutionGovAction =
NewConstitution
(SJust invalidPrevGovActionId)
constitution
invalidNewConstitutionProposal <- proposalWithRewardAccount invalidNewConstitutionGovAction
submitFailingProposal
invalidNewConstitutionProposal
[ injectFailure $ InvalidPrevGovActionId invalidNewConstitutionProposal
]
it "valid GovPurposeId but invalid purpose" $ do
(_dRep, _committeeMember, _) <- electBasicCommittee
(govActionId, _constitution) <- submitConstitution SNothing
passNEpochs 2
let invalidNoConfidenceAction =
NoConfidence $ SJust $ GovPurposeId govActionId
invalidNoConfidenceProposal <- proposalWithRewardAccount invalidNoConfidenceAction
submitFailingProposal
invalidNoConfidenceProposal
[ injectFailure $ InvalidPrevGovActionId invalidNoConfidenceProposal
]
it "submitted successfully with valid GovPurposeId" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 1
curConstitution <- getsNES $ newEpochStateGovStateL . constitutionGovStateL
initialPulser <- getsNES $ newEpochStateGovStateL . drepPulsingStateGovStateL
initialEnactState <- getEnactState
(govActionId, _) <- submitConstitution SNothing
curConstitution' <- getsNES $ newEpochStateGovStateL . constitutionGovStateL
impAnn "Constitution has not been enacted yet" $
curConstitution' `shouldBe` curConstitution
ConwayGovState expectedProposals _ _ _ _ expectedPulser <-
getsNES newEpochStateGovStateL
expectedEnactState <- getEnactState
impAnn "EnactState reflects the submitted governance action" $ do
expectedEnactState `shouldBe` initialEnactState
impAnn "Proposals contain the submitted proposal" $
expectedProposals `shouldSatisfy` \props -> govActionId `elem` proposalsIds props
impAnn "Pulser has not changed" $
expectedPulser `shouldBe` initialPulser
passEpoch >> passEpoch
impAnn "Proposal gets removed after expiry" $ do
ConwayGovState _ _ _ _ _ pulser <- getsNES newEpochStateGovStateL
let ratifyState = extractDRepPulsingState pulser
rsExpired ratifyState `shouldBe` Set.singleton govActionId
policySpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
policySpec =
describe "Policy" $ do
it "policy is respected by proposals" $ do
(dRep, committeeMember, _) <- electBasicCommittee
keyHash <- freshKeyHash
scriptHash <- impAddNativeScript $ RequireAllOf (SSeq.singleton (RequireSignature keyHash))
anchor <- arbitrary
_ <- enactConstitution SNothing (Constitution anchor (SJust scriptHash)) dRep committeeMember
wrongScriptHash <-
impAddNativeScript $
RequireMOf 1 $
SSeq.fromList [RequireAnyOf mempty, RequireAllOf mempty]
pp <- getsNES $ nesEsL . curPParamsEpochStateL
impAnn "ParameterChange with correct policy succeeds" $ do
let
pparamsUpdate =
def
& ppuCommitteeMinSizeL .~ SJust 1
rewardAccount <- registerRewardAccount
submitProposal_
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = ParameterChange SNothing pparamsUpdate (SJust scriptHash)
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
impAnn "TreasuryWithdrawals with correct policy succeeds" $ do
rewardAccount <- registerRewardAccount
let
withdrawals =
Map.fromList
[ (rewardAccount, Coin 1000)
]
submitProposal_
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = TreasuryWithdrawals withdrawals (SJust scriptHash)
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
impAnn "ParameterChange with invalid policy fails" $ do
rewardAccount <- registerRewardAccount
let
pparamsUpdate =
def
& ppuCommitteeMinSizeL .~ SJust 2
res <-
trySubmitProposal
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = ParameterChange SNothing pparamsUpdate (SJust wrongScriptHash)
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
res
`shouldBeLeft` [ injectFailure $
InvalidPolicyHash (SJust wrongScriptHash) (SJust scriptHash)
]
impAnn "TreasuryWithdrawals with invalid policy fails" $ do
rewardAccount <- registerRewardAccount
let
withdrawals =
Map.fromList
[ (rewardAccount, Coin 1000)
]
res <-
trySubmitProposal
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction = TreasuryWithdrawals withdrawals (SJust wrongScriptHash)
, pProcDeposit = pp ^. ppGovActionDepositL
, pProcAnchor = def
}
res
`shouldBeLeft` [ injectFailure $
InvalidPolicyHash (SJust wrongScriptHash) (SJust scriptHash)
]
networkIdSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
networkIdSpec =
describe "Network ID" $ do
it "Fails with invalid network ID in proposal return address" $ do
rewardCredential <- KeyHashObj <$> freshKeyHash
let badRewardAccount =
RewardAccount
{ raNetwork = Mainnet -- Our network is Testnet
, raCredential = rewardCredential
}
propDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
submitFailingProposal
ProposalProcedure
{ pProcReturnAddr = badRewardAccount
, pProcGovAction = InfoAction
, pProcDeposit = propDeposit
, pProcAnchor = def
}
[ injectFailure $
ProposalProcedureNetworkIdMismatch
badRewardAccount
Testnet
]
it "Fails with invalid network ID in withdrawal addresses" $ do
rewardAccount <- registerRewardAccount
rewardCredential <- KeyHashObj <$> freshKeyHash
let badRewardAccount =
RewardAccount
{ raNetwork = Mainnet -- Our network is Testnet
, raCredential = rewardCredential
}
propDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
submitFailingProposal
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction =
TreasuryWithdrawals
(Map.singleton badRewardAccount $ Coin 100_000_000)
SNothing
, pProcDeposit = propDeposit
, pProcAnchor = def
}
[ injectFailure $
TreasuryWithdrawalsNetworkIdMismatch
(Set.singleton badRewardAccount)
Testnet
]
proposalWithRewardAccount ::
forall era.
ConwayEraImp era =>