This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CDEC-499] Add golden+roundtrip JSON for
TxpConfiguration
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
Showing
8 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
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,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 |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"memPoolLimitTx":99,"assetLockedSrcAddrs":["2RhQhCGqYPDpFgTsnBTbnvPvCwpqAkjwLqQkWpkqXbLRmNxd4xNd262nGsr8JiynyKRUeMLSJ9Ntho9i76uvBTrVXdJJG5yiNLb8frmUe5qX7E"]} |
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 @@ | ||
{"memPoolLimitTx":9,"assetLockedSrcAddrs":["a2x5MVsL5Pr1SESUZbGb7d64coe2VpRJhEFsYCUHfaimAE3wvmNHd44H7ue1wFx1RqrS9vnAmTVri19FttwaRLWG5L2rLMe1tCSzZ4zJjeUwej8kEX4VmYbL7t7o1rmucebNvz8qGod2s6LKCkAxN6dWVv9jZ3gCkWrNsXq3JeSjaBLPT7RNwSExRmPAwJ6geZmadnKSArbiPjYXkaJa5GQyDUYbni8jCyXmMHB7Qsj1Pgc7qCKA7AebV13kADRv3wSbMgWEAbBrxEmBRnHgXw5Nh6EJ5n7ejVYJAJY3kJ8Q2xisLJxW54Y48BK8a4AW7M3fU","Ae2tdPwUPEZDoUnyXuAgqzhkjNXNJeiZ5nqwprg9sArZmRNjySfJ5uz4FjB","dRNpRgY7sgwXaGbEZQ7KtFprY5PE3sxejht9kFEKLmSowgUegSinCjx3yuKGHQbRHL2EUP89BuAurEScfrgWxahCjD1M9QKYoTj5KrbR5TDnqBE3oSNx7UcXhrGKM9aau48SASu8i88Sq8hPb3z5K662spTXX"]} |
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 @@ | ||
{"memPoolLimitTx":700,"assetLockedSrcAddrs":["2RhQhCGqYPDpFgTsnBTbnvPvCwpqAkjwLqQkWpkqXbLRmNxd4xNd262nGsr8JiynyKRUeMLSJ9Ntho9i76uvBTrVXdJJG5yiNLb8frmUe5qX7E","5FCjkr138i9wjRVwawmYMd4Vc9KxU7TuQhMyjMGpnykg9yb2qMpUCerDFzXvfAJMFgJTHyD7Sn4ybLXm2M6zeWAaWe7ctjq5QjVL427vGRx"]} |
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