Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 946743c

Browse files
committed
more informative test output
1 parent 649067f commit 946743c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/lib/Chainweb/Test/Orphans/Internal.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Chainweb.Test.Orphans.Internal
6060
) where
6161

6262
import Control.Applicative
63-
import Control.Lens (view)
63+
import Control.Lens (view, set)
6464
import Control.Monad
6565
import Control.Monad.Catch
6666

@@ -119,6 +119,7 @@ import Chainweb.Crypto.MerkleLog
119119
import Chainweb.Cut.Create
120120
import Chainweb.Cut.CutHashes
121121
import Chainweb.Difficulty
122+
import Chainweb.ForkState
122123
import Chainweb.Graph
123124
import Chainweb.HostAddress
124125
import Chainweb.Mempool.Mempool
@@ -166,7 +167,6 @@ import P2P.Test.Orphans ()
166167
import System.Logger.Types
167168

168169
import Utils.Logging
169-
import Chainweb.ForkState
170170

171171
-- -------------------------------------------------------------------------- --
172172
-- Utils
@@ -299,7 +299,7 @@ instance Arbitrary NodeInfo where
299299
, nodeGraphHistory = graphs
300300
, nodeLatestBehaviorHeight = latestBehaviorAt v
301301
, nodeGenesisHeights = map (\c -> (chainIdToText c, genesisHeight v c)) $ HS.toList $ chainIds v
302-
, nodeHistoricalChains = ruleElems $ fmap (HM.toList . HM.map HS.toList . toAdjacencySets) $ _versionGraphs v
302+
, nodeHistoricalChains = ruleElems $ HM.toList . HM.map HS.toList . toAdjacencySets <$> _versionGraphs v
303303
, nodeServiceDate = T.pack <$> _versionServiceDate v
304304
, nodeBlockDelay = _versionBlockDelay v
305305
}
@@ -329,7 +329,12 @@ instance Arbitrary EpochStartTime where
329329
arbitrary = EpochStartTime <$> arbitrary
330330

331331
instance Arbitrary ForkState where
332-
arbitrary = ForkState <$> arbitrary
332+
arbitrary = do
333+
votes <- chooseBoundedIntegral (0, int forkEpochLength * voteStep)
334+
number <- chooseBoundedIntegral (0, 100000000)
335+
return $ ForkState 0
336+
& set forkVotes votes
337+
& set forkNumber number
333338

334339
instance Arbitrary BlockHeader where
335340
arbitrary = arbitrary >>= arbitraryBlockHeaderVersion

test/lib/Chainweb/Test/Utils/TestHeader.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import Data.Aeson
4141
import Data.Aeson.Types
4242
import Data.Foldable
4343
import qualified Data.HashMap.Strict as HM
44+
import qualified Data.Text as T
4445

4546
import Debug.Trace
4647

@@ -59,6 +60,7 @@ import Chainweb.BlockHeight
5960
import Chainweb.ChainValue
6061
import Chainweb.Test.Orphans.Internal
6162
import Chainweb.Version
63+
import Chainweb.Utils
6264

6365
import Chainweb.Storage.Table
6466

@@ -70,7 +72,14 @@ data TestHeader = TestHeader
7072
, _testHeaderParent :: !ParentHeader
7173
, _testHeaderAdjs :: ![ParentHeader]
7274
}
73-
deriving (Show, Eq, Ord, Generic)
75+
deriving (Eq, Ord, Generic)
76+
77+
instance Show TestHeader where
78+
show (TestHeader h p a) = T.unpack $ encodeToText $ object [
79+
"header" .= ExtendedObjectEncoded h,
80+
"parent" .= ExtendedObjectEncoded (_parentHeader p),
81+
"adjacents" .= fmap (ExtendedObjectEncoded . _parentHeader) a
82+
]
7483

7584
makeLenses ''TestHeader
7685

0 commit comments

Comments
 (0)