Liqwid-Labs / plutarch-context-builder

Apache License 2.0
3 stars 1 forks source link

`Value` doesn't normalize across different `mint`s #46

Open Renegatto opened 1 year ago

Renegatto commented 1 year ago

Example

Given:

v1 :: Value
v1 = singleton "123a" "feea" 3

v2 :: Value
v2 = singleton "124b" "feeb" 12

make :: SpendingBuilder -> ScriptContext
make = buildSpending mempty . mkNormalized . mappend minimalCtx

minimalCtx :: SpendingBuilder
minimalCtx = withSpendingOutRef ref <> input (withRef ref)
  where ref = TxOutRef "a0" 0

getMint :: ScriptContext -> [(CurrencySymbol, Map TokenName Integer)]
getMint = toList . getValue . txInfoMint . scriptContextTxInfo

Expected:

ghci> getMint (make $ mint $ mconcat [v1,v2]) == getMint (make $ mint v1 <> mint v2)
True

Got:

ghci> getMint (make $ mint $ mconcat [v1,v2]) == getMint (make $ mint v1 <> mint v2)
False

Details:

ghci> getMint (make (mint $ mconcat [v1,v2]))
[(124b,Map {unMap = [("feeb",12)]}),(,Map {unMap = [("",0)]}),(123a,Map {unMap = [("feea",3)]})]
ghci> getMint (make (mint v1 <> mint v2))
[(123a,Map {unMap = [("feea",3)]}),(,Map {unMap = [("",0)]}),(124b,Map {unMap = [("feeb",12)]})]
Renegatto commented 1 year ago

Wrong example

Renegatto commented 1 year ago

Fixed example.

SeungheonOh commented 1 year ago

Sort is missing somewhere I think

adamczykm commented 1 year ago

Basically, it looks like the values in ScriptContexts built by PCB lose their guarantees, which is wrong - Plutarch expects them in place. I wasn't sure if I should open another issue for this.