-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3698 from input-output-hk/jj/reorder-procedures
Reordering of governance actions
- Loading branch information
Showing
8 changed files
with
139 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
eras/conway/impl/test/Test/Cardano/Ledger/Conway/GovActionReorderSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Cardano.Ledger.Conway.GovActionReorderSpec (spec) where | ||
|
||
import Cardano.Ledger.Conway (Conway) | ||
import Cardano.Ledger.Conway.Governance (GovActionState (..)) | ||
import Cardano.Ledger.Conway.Rules (actionPriority, reorderActions) | ||
import Data.Foldable (Foldable (..)) | ||
import Data.List (sort, sortOn) | ||
import qualified Data.Sequence.Strict as Seq | ||
import Test.Cardano.Ledger.Binary.Arbitrary () | ||
import Test.Cardano.Ledger.Common (Spec, describe, prop, shuffle) | ||
import Test.Cardano.Ledger.Conway.Arbitrary ( | ||
genGovActionStateFromAction, | ||
govActionGenerators, | ||
) | ||
|
||
spec :: Spec | ||
spec = | ||
describe "Conway governance actions reordering" $ do | ||
prop "preserves length when reordered" $ | ||
\actions -> Seq.length actions == Seq.length (reorderActions @Conway actions) | ||
prop "sorts by priority" $ | ||
\actions -> | ||
sort (toList (actionPriority . gasAction @Conway <$> actions)) | ||
== toList (actionPriority . gasAction <$> reorderActions actions) | ||
prop "same priority actions are not rearranged" $ | ||
\a as -> | ||
let filterPrio b = actionPriority (gasAction a) == actionPriority (gasAction b) | ||
in filter filterPrio (toList $ reorderActions @Conway (a Seq.:<| as)) | ||
== filter filterPrio (toList $ reorderActions (a Seq.:<| as)) | ||
prop "orders actions correctly" $ do | ||
actionsList <- | ||
traverse | ||
(>>= genGovActionStateFromAction) | ||
(govActionGenerators @Conway) | ||
let sortedActions = sortOn (actionPriority . gasAction) actionsList | ||
shuffledActions <- shuffle actionsList | ||
pure $ | ||
Seq.fromList sortedActions | ||
== reorderActions (Seq.fromList shuffledActions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main where | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters