@@ -19,15 +19,18 @@ import Cardano.Testnet
1919
2020import Prelude
2121
22+ import Control.Monad ((<=<) )
2223import qualified Data.ByteString as BS
2324import qualified Data.ByteString.Short as SBS
2425import Data.Default.Class
26+ import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds )
2527import Data.Word (Word64 )
2628import Lens.Micro
2729
2830import Testnet.Process.Run
2931import Testnet.Property.Util (integrationRetryWorkspace )
3032import Testnet.Start.Types
33+ import Testnet.Types (nodeConnectionInfo )
3134
3235import qualified Hedgehog as H
3336import qualified Hedgehog.Extras as H
@@ -46,7 +49,7 @@ hprop_rpc_fetch_block = integrationRetryWorkspace 2 "rpc-fetch-block" $ \tempAbs
4649 creationOptions = def{creationEra = AnyShelleyBasedEra sbe}
4750 runtimeOptions = def{runtimeEnableRpc = RpcEnabled }
4851
49- TestnetRuntime
52+ tr @ TestnetRuntime
5053 { testnetMagic
5154 , testnetNodes = node0@ TestnetNode {nodeSprocket} : _
5255 } <-
@@ -92,5 +95,17 @@ hprop_rpc_fetch_block = integrationRetryWorkspace 2 "rpc-fetch-block" $ \tempAbs
9295 -- height is the block number from ChainDB
9396 block ^. U5c. cardano . U5c. header . U5c. height H. === blockNo
9497
95- -- timestamp is not available without era history, defaults to 0
96- block ^. U5c. cardano . U5c. timestamp H. === 0
98+ -- Compute expected timestamp via N2C IPC
99+ connectionInfo <- nodeConnectionInfo tr 0
100+ (systemStart, eraHistory) <-
101+ (H. leftFail <=< H. leftFailM) . H. evalIO $
102+ executeLocalStateQueryExpr connectionInfo VolatileTip $ do
103+ ss <- querySystemStart
104+ eh <- queryEraHistory
105+ pure $ (,) <$> ss <*> eh
106+ expectedTimestampMs :: Word64 <- H. leftFail $ do
107+ utcTime <- slotToUTCTime systemStart eraHistory (SlotNo slot)
108+ pure . round $ utcTimeToPOSIXSeconds utcTime * 1000
109+
110+ -- Verify timestamp is within 1000ms of expected
111+ H. assertWithinTolerance (block ^. U5c. cardano . U5c. timestamp) expectedTimestampMs 1000
0 commit comments