IntersectMBO / cardano-node

The core component that is used to participate in a Cardano decentralised blockchain.
https://cardano.org
Apache License 2.0
3.06k stars 721 forks source link

[BUG] - cardano-api's Value type equality breaks with entries with quantity 0 #4790

Open sjoerdvisscher opened 1 year ago

sjoerdvisscher commented 1 year ago

Internal/External Internal

Area Other: cardano-api

Summary The equality of Value is derived:

newtype Value = Value (Map AssetId Quantity)
  deriving Eq

But this breaks equality for entries with quantity 0.

The code tries to make sure these entries are not created, but this is hard to do. I found one example where this goes wrong:

lovelaceToValue :: Lovelace -> Value
lovelaceToValue = Value . Map.singleton AdaAssetId . lovelaceToQuantity

I.e. lovelaceToValue 0 creates a Value with a zero quantity entry.

Now it would be good to fix this too, but the safer fix is to write an Eq instance manually that allows for zero quantity entries.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 120 days.