Skip to content

Commit 5006b56

Browse files
authored
Merge pull request IntersectMBO#5404 from input-output-hk/mgalazyn/fix/fix-missing-tracing-instances
Fix missing `ToObject` tracing instances.
2 parents 712b095 + 36a2730 commit 5006b56

File tree

3 files changed

+83
-21
lines changed
  • cardano-node
  • cardano-testnet/src/Testnet/Property

3 files changed

+83
-21
lines changed

cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,83 @@ instance
146146
, "updates" .= map (toObject verb) updates
147147
]
148148
instance
149-
( Show (PredicateFailure (Ledger.EraRule "DELEG" era))
150-
, Show (PredicateFailure (Ledger.EraRule "POOL" era))
151-
, Show (PredicateFailure (Ledger.EraRule "VDEL" era))
149+
( ToObject (PredicateFailure (Ledger.EraRule "DELEG" era))
150+
, ToObject (PredicateFailure (Ledger.EraRule "POOL" era))
151+
, ToObject (PredicateFailure (Ledger.EraRule "VDEL" era))
152152
) => ToObject (Conway.ConwayCertPredFailure era) where
153-
toObject _verb cfail =
154-
mconcat [ "kind" .= String "ConwayCertPredFailure"
155-
, "failure" .= show cfail -- TODO: Conway era - render in a nicer way
156-
]
153+
toObject verb = mconcat . \case
154+
Conway.DelegFailure f ->
155+
[ "kind" .= String "DelegFailure " , "failure" .= toObject verb f ]
156+
Conway.PoolFailure f ->
157+
[ "kind" .= String "PoolFailure" , "failure" .= toObject verb f ]
158+
Conway.VDelFailure f ->
159+
[ "kind" .= String "VDelFailure" , "failure" .= toObject verb f ]
160+
161+
instance ToObject (Conway.ConwayVDelPredFailure era) where
162+
toObject _verb = mconcat . \case
163+
Conway.ConwayDRepAlreadyRegisteredVDEL credential ->
164+
[ "kind" .= String "ConwayDRepAlreadyRegisteredVDEL"
165+
, "credential" .= String (textShow credential)
166+
, "error" .= String "DRep is already registered"
167+
]
168+
Conway.ConwayDRepNotRegisteredVDEL credential ->
169+
[ "kind" .= String "ConwayDRepNotRegisteredVDEL"
170+
, "credential" .= String (textShow credential)
171+
, "error" .= String "DRep is not registered"
172+
]
173+
Conway.ConwayDRepIncorrectDepositVDEL coin ->
174+
[ "kind" .= String "ConwayDRepIncorrectDepositVDEL"
175+
, "coin" .= coin
176+
, "error" .= String "DRep delegation has incorrect deposit"
177+
]
178+
Conway.ConwayCommitteeHasResignedVDEL kHash ->
179+
[ "kind" .= String "ConwayCommitteeHasResignedVDEL"
180+
, "credential" .= String (textShow kHash)
181+
, "error" .= String "Committee has resigned"
182+
]
183+
184+
instance ToObject (Conway.ConwayDelegPredFailure era) where
185+
toObject _verb = mconcat . \case
186+
Conway.IncorrectDepositDELEG coin ->
187+
[ "kind" .= String "IncorrectDepositDELEG"
188+
, "amount" .= coin
189+
, "error" .= String "Incorrect deposit amount"
190+
]
191+
Conway.StakeKeyAlreadyRegisteredDELEG credential ->
192+
[ "kind" .= String "StakeKeyAlreadyRegisteredDELEG"
193+
, "credential" .= String (textShow credential)
194+
, "error" .= String "Stake key already registered"
195+
]
196+
Conway.StakeKeyNotRegisteredDELEG credential ->
197+
[ "kind" .= String "StakeKeyNotRegisteredDELEG"
198+
, "amount" .= String (textShow credential)
199+
, "error" .= String "Stake key not registered"
200+
]
201+
Conway.StakeKeyHasNonZeroAccountBalanceDELEG coin ->
202+
[ "kind" .= String "StakeKeyHasNonZeroAccountBalanceDELEG"
203+
, "amount" .= coin
204+
, "error" .= String "Stake key has non-zero account balance"
205+
]
206+
Conway.DRepAlreadyRegisteredForStakeKeyDELEG credential ->
207+
[ "kind" .= String "DRepAlreadyRegisteredForStakeKeyDELEG"
208+
, "amount" .= String (textShow credential)
209+
, "error" .= String "DRep already registered for the stake key"
210+
]
211+
Conway.WrongCertificateTypeDELEG ->
212+
[ "kind" .= String "WrongCertificateTypeDELEG"
213+
, "error" .= String "Wrong certificate type"
214+
]
215+
157216

158217
instance ToObject (Set (Credential 'Staking StandardCrypto)) where
159218
toObject _verb creds =
160219
mconcat [ "kind" .= String "StakeCreds"
161-
, "stakeCreds" .= map show (Set.toList creds) -- TODO: Conway era - render in a nicer way
220+
, "stakeCreds" .= map toObject' (Set.toList creds)
162221
]
163-
222+
where
223+
toObject' = object . \case
224+
ScriptHashObj sHash -> ["scriptHash" .= renderScriptHash sHash]
225+
KeyHashObj keyHash -> ["keyHash" .= textShow keyHash]
164226

165227
instance
166228
( Ledger.Era ledgerera
@@ -306,9 +368,9 @@ instance
306368
) => ToObject (AlonzoUtxowPredFailure ledgerera) where
307369
toObject v (ShelleyInAlonzoUtxowPredFailure utxoPredFail) =
308370
toObject v utxoPredFail
309-
toObject _ (MissingRedeemers _scripts) =
371+
toObject _ (MissingRedeemers scripts) =
310372
mconcat [ "kind" .= String "MissingRedeemers"
311-
, "scripts" .= String "TODO: Conway era" --renderMissingRedeemers scripts
373+
, "scripts" .= renderMissingRedeemers scripts
312374
]
313375
toObject _ (MissingRequiredDatums required received) =
314376
mconcat [ "kind" .= String "MissingRequiredDatums"
@@ -347,11 +409,11 @@ renderScriptIntegrityHash (Just witPPDataHash) =
347409
renderScriptIntegrityHash Nothing = Aeson.Null
348410

349411

350-
_renderMissingRedeemers :: ()
412+
renderMissingRedeemers :: ()
351413
=> Ledger.EraCrypto ledgerera ~ StandardCrypto
352414
=> [(Alonzo.ScriptPurpose ledgerera, ScriptHash StandardCrypto)]
353415
-> Aeson.Value
354-
_renderMissingRedeemers scripts = Aeson.object $ map renderTuple scripts
416+
renderMissingRedeemers scripts = Aeson.object $ map renderTuple scripts
355417
where
356418
renderTuple :: ()
357419
=> Ledger.EraCrypto ledgerera ~ StandardCrypto
@@ -360,8 +422,8 @@ _renderMissingRedeemers scripts = Aeson.object $ map renderTuple scripts
360422
renderTuple (scriptPurpose, sHash) =
361423
Aeson.fromText (renderScriptHash sHash) .= renderScriptPurpose scriptPurpose
362424

363-
renderScriptHash :: ScriptHash StandardCrypto -> Text
364-
renderScriptHash = Api.serialiseToRawBytesHexText . Api.fromShelleyScriptHash
425+
renderScriptHash :: ScriptHash StandardCrypto -> Text
426+
renderScriptHash = Api.serialiseToRawBytesHexText . Api.fromShelleyScriptHash
365427

366428
renderScriptPurpose :: ()
367429
=> Ledger.EraCrypto ledgerera ~ StandardCrypto
@@ -1059,9 +1121,9 @@ instance
10591121
, "isvalidating" .= isValidating
10601122
, "reason" .= reason
10611123
]
1062-
toObject _ (Alonzo.CollectErrors _errors) =
1124+
toObject _ (Alonzo.CollectErrors errors) =
10631125
mconcat [ "kind" .= String "CollectErrors"
1064-
, "errors" .= String "TODO: Conway era" -- errors
1126+
, "errors" .= errors
10651127
]
10661128
toObject verb (Alonzo.UpdateFailure pFailure) =
10671129
toObject verb pFailure
@@ -1080,11 +1142,11 @@ instance
10801142
, "error" .= String "NoRedeemer"
10811143
, "scriptpurpose" .= renderScriptPurpose sPurpose
10821144
]
1083-
Alonzo.NoWitness _sHash ->
1145+
Alonzo.NoWitness sHash ->
10841146
object
10851147
[ "kind" .= String "CollectError"
10861148
, "error" .= String "NoWitness"
1087-
, "scripthash" .= String "TODO: Conway era" -- toJSON sHash
1149+
, "scripthash" .= renderScriptHash sHash
10881150
]
10891151
Alonzo.NoCostModel lang ->
10901152
object

cardano-node/test/Test/Cardano/Node/POM.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ testPartialCliConfig =
8989
PartialNodeConfiguration
9090
{ pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty mempty
9191
, pncShutdownConfig = Last . Just $ ShutdownConfig Nothing (Just . ASlot $ SlotNo 42)
92-
, pncStartAsNonProducingNode = Last $ Just $ False
92+
, pncStartAsNonProducingNode = Last $ Just False
9393
, pncConfigFile = mempty
9494
, pncTopologyFile = mempty
9595
, pncDatabaseFile = mempty

cardano-testnet/src/Testnet/Property/Assert.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ assertByDeadlineIOCustom str deadline f = GHC.withFrozenCallStack $ do
6565
H.annotateShow currentTime
6666
H.failMessage GHC.callStack $ "Condition not met by deadline: " <> str
6767

68-
assertChainExtended :: (H.MonadTest m, MonadIO m)
68+
assertChainExtended :: (HasCallStack, H.MonadTest m, MonadIO m)
6969
=> DTC.UTCTime
7070
-> NodeLoggingFormat
7171
-> FilePath

0 commit comments

Comments
 (0)