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

Commit

Permalink
[CDEC-500] Add golden tests for Address
Browse files Browse the repository at this point in the history
Since we are modifying this for CO-354, and it's quite important to
preserve backwards compatibility of Addresses, I've added 5 golden
tests to ensure the various configurations of Addresses will have
proper test coverage.
  • Loading branch information
mhuesch committed Aug 15, 2018
1 parent 8d9e2b8 commit a85c456
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 1 deletion.
49 changes: 49 additions & 0 deletions core/test/Test/Pos/Core/ExampleHelpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module Test.Pos.Core.ExampleHelpers

exampleAddrSpendingData_PubKey
, exampleAddress
, exampleAddress1
, exampleAddress2
, exampleAddress3
, exampleAddress4
, exampleBlockVersion
, exampleBlockVersionData
, exampleBlockVersionModifier
Expand Down Expand Up @@ -83,6 +87,7 @@ import Data.Fixed (Fixed (..))
import qualified Data.HashMap.Strict as HM
import Data.List (zipWith4, (!!))
import Data.List.NonEmpty (fromList)
import qualified Data.Map as M
import Data.Maybe (fromJust)
import qualified Data.Text as T
import Data.Time.Units (Millisecond)
Expand Down Expand Up @@ -564,6 +569,50 @@ exampleAddress = makeAddress exampleAddrSpendingData_PubKey attrs
attrs = AddrAttributes hap BootstrapEraDistr
hap = Just (HDAddressPayload (getBytes 32 32))

exampleAddress1 :: Address
exampleAddress1 = makeAddress easd attrs
where
easd = PubKeyASD pk
[pk] = examplePublicKeys 24 1
attrs = AddrAttributes hap BootstrapEraDistr
hap = Nothing

exampleAddress2 :: Address
exampleAddress2 = makeAddress easd attrs
where
easd = RedeemASD exampleRedeemPublicKey
attrs = AddrAttributes hap asd
hap = Just (HDAddressPayload (getBytes 15 32))
asd = SingleKeyDistr exampleStakeholderId

exampleAddress3 :: Address
exampleAddress3 = makeAddress easd attrs
where
easd = ScriptASD exampleScript
attrs = AddrAttributes hap exampleMultiKeyDistr
hap = Just (HDAddressPayload (getBytes 17 32))

exampleAddress4 :: Address
exampleAddress4 = makeAddress easd attrs
where
easd = UnknownASD 7 "test value"
attrs = AddrAttributes Nothing (SingleKeyDistr sId)
[sId] = exampleStakeholderIds 7 1

exampleMultiKeyDistr :: AddrStakeDistribution
exampleMultiKeyDistr = case mkMultiKeyDistr (M.fromList pairs) of
Left err -> error $
"exampleMultiKeyDistr: improperly constructed stake map: " <> show err
Right asd -> asd
where
pairs = zip stakeIds (map CoinPortion (remainderCP : coinPortions))
stakeIds = map abstractHash (examplePublicKeys 7 4)
coinPortions = [ (10 :: Word64) ^ (12 :: Word64)
, ( 7 :: Word64) ^ (11 :: Word64)
, ( 6 :: Word64) ^ (14 :: Word64)
]
remainderCP = coinPortionDenominator - sum coinPortions

exampleGenesisConfiguration_GCSrc :: GenesisConfiguration
exampleGenesisConfiguration_GCSrc =
GCSrc "dRaMwdYsH3QA3dChe" (abstractHash (Raw "Test"))
Expand Down
44 changes: 43 additions & 1 deletion core/test/Test/Pos/Core/Json.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,49 @@ import Test.Pos.Util.Tripping (discoverRoundTrip,
import Universum

--------------------------------------------------------------------------------
-- GensisConfiguration
-- Address
--------------------------------------------------------------------------------

golden_Address0 :: Property
golden_Address0 =
goldenTestJSON
exampleAddress
"test/golden/json/Address0"

golden_Address1 :: Property
golden_Address1 =
goldenTestJSON
exampleAddress1
"test/golden/json/Address1"

golden_Address2 :: Property
golden_Address2 =
goldenTestJSON
exampleAddress2
"test/golden/json/Address2"

golden_Address3 :: Property
golden_Address3 =
goldenTestJSON
exampleAddress3
"test/golden/json/Address3"

golden_Address4 :: Property
golden_Address4 =
goldenTestJSON
exampleAddress4
"test/golden/json/Address4"

roundTripAddressShow :: Property
roundTripAddressShow =
eachOf 100 genAddress roundTripsAesonShow

roundTripAddressBuildable :: Property
roundTripAddressBuildable =
eachOf 100 genAddress roundTripsAesonBuildable

--------------------------------------------------------------------------------
-- GenesisConfiguration
--------------------------------------------------------------------------------

golden_GenesisConfiguration_GCSpec :: Property
Expand Down
1 change: 1 addition & 0 deletions core/test/golden/json/Address0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2RhQhCGqYPDpFgTsnBTbnvPvCwpqAkjwLqQkWpkqXbLRmNxd4xNd262nGsr8JiynyKRUeMLSJ9Ntho9i76uvBTrVXdJJG5yiNLb8frmUe5qX7E"
1 change: 1 addition & 0 deletions core/test/golden/json/Address1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Ae2tdPwUPEZDoUnyXuAgqzhkjNXNJeiZ5nqwprg9sArZmRNjySfJ5uz4FjB"
1 change: 1 addition & 0 deletions core/test/golden/json/Address2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"dRNpRgY7sgwXaGbEZQ7KtFprY5PE3sxejht9kFEKLmSowgUegSinCjx3yuKGHQbRHL2EUP89BuAurEScfrgWxahCjD1M9QKYoTj5KrbR5TDnqBE3oSNx7UcXhrGKM9aau48SASu8i88Sq8hPb3z5K662spTXX"
1 change: 1 addition & 0 deletions core/test/golden/json/Address3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"a2x5MVsL5Pr1SESUZbGb7d64coe2VpRJhEFsYCUHfaimAE3wvmNHd44H7ue1wFx1RqrS9vnAmTVri19FttwaRLWG5L2rLMe1tCSzZ4zJjeUwej8kEX4VmYbL7t7o1rmucebNvz8qGod2s6LKCkAxN6dWVv9jZ3gCkWrNsXq3JeSjaBLPT7RNwSExRmPAwJ6geZmadnKSArbiPjYXkaJa5GQyDUYbni8jCyXmMHB7Qsj1Pgc7qCKA7AebV13kADRv3wSbMgWEAbBrxEmBRnHgXw5Nh6EJ5n7ejVYJAJY3kJ8Q2xisLJxW54Y48BK8a4AW7M3fU"
1 change: 1 addition & 0 deletions core/test/golden/json/Address4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"5FCjkr138i9wjRVwawmYMd4Vc9KxU7TuQhMyjMGpnykg9yb2qMpUCerDFzXvfAJMFgJTHyD7Sn4ybLXm2M6zeWAaWe7ctjq5QjVL427vGRx"

0 comments on commit a85c456

Please sign in to comment.