Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[CDEC-499] Add golden+roundtrip JSON for TxpConfiguration
Browse files Browse the repository at this point in the history
This datatypes will be modified for CO-354, and it currently uses
derived JSON instances, which means it is fragile when the datatype
is modified. We will use these golden tests to ensure compatibility
with the current configuration format (when we add a field to the
datatype we will give it a default value in the event a key is
missing from the configuration).
  • Loading branch information
mhuesch committed Aug 16, 2018
1 parent de0bbab commit c8a1b7e
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chain/cardano-sl-chain.cabal
Expand Up @@ -208,6 +208,8 @@ test-suite test
Test.Pos.Chain.Ssc.Json
Test.Pos.Chain.Ssc.Arbitrary
Test.Pos.Chain.Txp.CoreSpec
Test.Pos.Chain.Txp.Gen
Test.Pos.Chain.Txp.Json
Test.Pos.Chain.Txp.Toil.UtxoSpec
Test.Pos.Chain.Update.Arbitrary
Test.Pos.Chain.Update.Arbitrary.Core
Expand Down
21 changes: 21 additions & 0 deletions chain/test/Test/Pos/Chain/Txp/Gen.hs
@@ -0,0 +1,21 @@
module Test.Pos.Chain.Txp.Gen
( genTxpConfiguration
) where

import Universum

import qualified Data.Set as S
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range

import Pos.Chain.Txp (TxpConfiguration (..))

import Test.Pos.Core.Gen (genAddress)


genTxpConfiguration :: Gen TxpConfiguration
genTxpConfiguration = do
limit <- Gen.int (Range.constant 0 200)
addrs <- Gen.list (Range.linear 0 50) genAddress
return (TxpConfiguration limit (S.fromList addrs))
70 changes: 70 additions & 0 deletions chain/test/Test/Pos/Chain/Txp/Json.hs
@@ -0,0 +1,70 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Test.Pos.Chain.Txp.Json
( tests
) where
import Universum

import qualified Data.Set as S
import Hedgehog (Property)
import qualified Hedgehog as H

import Pos.Chain.Txp (TxpConfiguration (..))

import Test.Pos.Chain.Txp.Gen (genTxpConfiguration)
import Test.Pos.Core.ExampleHelpers (exampleAddress, exampleAddress1,
exampleAddress2, exampleAddress3, exampleAddress4)
import Test.Pos.Util.Golden (discoverGolden, eachOf, goldenTestJSON)
import Test.Pos.Util.Tripping (discoverRoundTrip, roundTripsAesonShow)

-------------------------------------------------------------------------------
-- TxpConfiguration
-------------------------------------------------------------------------------

golden_TxpConfiguration0 :: Property
golden_TxpConfiguration0 =
goldenTestJSON exampleTxpConfiguration0
"test/golden/json/TxpConfiguration0"

golden_TxpConfiguration1 :: Property
golden_TxpConfiguration1 =
goldenTestJSON exampleTxpConfiguration1
"test/golden/json/TxpConfiguration1"

golden_TxpConfiguration2 :: Property
golden_TxpConfiguration2 =
goldenTestJSON exampleTxpConfiguration2
"test/golden/json/TxpConfiguration2"

roundTripTxpConfiguration :: Property
roundTripTxpConfiguration =
eachOf 200 genTxpConfiguration roundTripsAesonShow

-------------------------------------------------------------------------------
-- Main test export
-------------------------------------------------------------------------------

exampleTxpConfiguration0 :: TxpConfiguration
exampleTxpConfiguration0 = TxpConfiguration 99 talsa
where
talsa = S.fromList [exampleAddress]

exampleTxpConfiguration1 :: TxpConfiguration
exampleTxpConfiguration1 = TxpConfiguration 9 talsa
where
talsa = S.fromList [exampleAddress1, exampleAddress2, exampleAddress3]

exampleTxpConfiguration2 :: TxpConfiguration
exampleTxpConfiguration2 = TxpConfiguration 700 talsa
where
talsa = S.fromList [exampleAddress4, exampleAddress]

-------------------------------------------------------------------------------
-- Main test export
-------------------------------------------------------------------------------

tests :: IO Bool
tests = (&&) <$> H.checkSequential $$discoverGolden
<*> H.checkParallel $$discoverRoundTrip
3 changes: 3 additions & 0 deletions chain/test/cardano-sl-chain-test.cabal
Expand Up @@ -21,6 +21,8 @@ library
Test.Pos.Chain.Ssc.Arbitrary
Test.Pos.Chain.Ssc.Gen
Test.Pos.Chain.Ssc.Json
Test.Pos.Chain.Txp.Gen
Test.Pos.Chain.Txp.Json
Test.Pos.Chain.Update.Arbitrary

other-modules: Test.Pos.Chain.Update.Arbitrary.Core
Expand All @@ -36,6 +38,7 @@ library
, cardano-sl-crypto
, cardano-sl-crypto-test
, cardano-sl-util-test
, containers
, formatting
, generic-arbitrary
, hedgehog
Expand Down
1 change: 1 addition & 0 deletions chain/test/golden/json/TxpConfiguration0
@@ -0,0 +1 @@
{"memPoolLimitTx":99,"assetLockedSrcAddrs":["2RhQhCGqYPDpFgTsnBTbnvPvCwpqAkjwLqQkWpkqXbLRmNxd4xNd262nGsr8JiynyKRUeMLSJ9Ntho9i76uvBTrVXdJJG5yiNLb8frmUe5qX7E"]}
1 change: 1 addition & 0 deletions chain/test/golden/json/TxpConfiguration1
@@ -0,0 +1 @@
{"memPoolLimitTx":9,"assetLockedSrcAddrs":["a2x5MVsL5Pr1SESUZbGb7d64coe2VpRJhEFsYCUHfaimAE3wvmNHd44H7ue1wFx1RqrS9vnAmTVri19FttwaRLWG5L2rLMe1tCSzZ4zJjeUwej8kEX4VmYbL7t7o1rmucebNvz8qGod2s6LKCkAxN6dWVv9jZ3gCkWrNsXq3JeSjaBLPT7RNwSExRmPAwJ6geZmadnKSArbiPjYXkaJa5GQyDUYbni8jCyXmMHB7Qsj1Pgc7qCKA7AebV13kADRv3wSbMgWEAbBrxEmBRnHgXw5Nh6EJ5n7ejVYJAJY3kJ8Q2xisLJxW54Y48BK8a4AW7M3fU","Ae2tdPwUPEZDoUnyXuAgqzhkjNXNJeiZ5nqwprg9sArZmRNjySfJ5uz4FjB","dRNpRgY7sgwXaGbEZQ7KtFprY5PE3sxejht9kFEKLmSowgUegSinCjx3yuKGHQbRHL2EUP89BuAurEScfrgWxahCjD1M9QKYoTj5KrbR5TDnqBE3oSNx7UcXhrGKM9aau48SASu8i88Sq8hPb3z5K662spTXX"]}
1 change: 1 addition & 0 deletions chain/test/golden/json/TxpConfiguration2
@@ -0,0 +1 @@
{"memPoolLimitTx":700,"assetLockedSrcAddrs":["2RhQhCGqYPDpFgTsnBTbnvPvCwpqAkjwLqQkWpkqXbLRmNxd4xNd262nGsr8JiynyKRUeMLSJ9Ntho9i76uvBTrVXdJJG5yiNLb8frmUe5qX7E","5FCjkr138i9wjRVwawmYMd4Vc9KxU7TuQhMyjMGpnykg9yb2qMpUCerDFzXvfAJMFgJTHyD7Sn4ybLXm2M6zeWAaWe7ctjq5QjVL427vGRx"]}
2 changes: 2 additions & 0 deletions pkgs/default.nix
Expand Up @@ -15516,6 +15516,7 @@ license = stdenv.lib.licenses.mit;
, cardano-sl-crypto
, cardano-sl-crypto-test
, cardano-sl-util-test
, containers
, formatting
, generic-arbitrary
, hedgehog
Expand Down Expand Up @@ -15548,6 +15549,7 @@ cardano-sl-core-test
cardano-sl-crypto
cardano-sl-crypto-test
cardano-sl-util-test
containers
formatting
generic-arbitrary
hedgehog
Expand Down

0 comments on commit c8a1b7e

Please sign in to comment.