Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Strange behavior of toCardanoTxBody (missing datums) #139

Closed
anton-k opened this issue Nov 23, 2021 · 4 comments · Fixed by #167
Closed

Strange behavior of toCardanoTxBody (missing datums) #139

anton-k opened this issue Nov 23, 2021 · 4 comments · Fixed by #167
Labels
bug Something isn't working

Comments

@anton-k
Copy link
Contributor

anton-k commented Nov 23, 2021

Summary

I try to test my contracts with functions toCardanoTxBody and evaulateTransactionExecutionUnits.
I build Plutus Tx by hand and convert it to cardano Tx to use evaluation function.

Something strange happens when I update datum from the input to output on the same address.
It can not find datum by datum hash. The function that I use to create part of Tx that pays to script:

-- | Pay to the script.
payToScript :: ToData (DatumType a) => TypedValidator a -> DatumType a -> Value -> Tx
payToScript tv dat val =
  mempty
    { txOutputs = [TxOut (validatorAddress tv) val (Just dh)]
    , txData = M.singleton dh datum
    }
  where
    dh = datumHash datum
    datum = Datum $ toBuiltinData dat

So it seems that I fill up txData and set up datum hash properly.
But when I use it in the code datum can only be found if it is the same as used in the inputs. If I change the datum validator can not find it in the outputs of TxInfo by hash although datum hash is present.
I tried to lookup how the function toCardanoTxBody works and I can see that it does not use txData.
Or maybe I miss something?
Please can you explain how txData should be used in the Cardano TxBody properly so that I can continue with my testing?
or how it should be used in toCardanoTxBody?

As I understand Cardano Tx does not contain datum's and only hashes are used.
How can the datums be visible to evaluateTransactionExecutionUnits?

I've tried to include also output datums in the UTxO argument of evaluateTransactionExecutionUnits and it also can not find them :(

@anton-k anton-k added the bug Something isn't working label Nov 23, 2021
@anton-k anton-k changed the title Strange behavior of toCardanoTxBody (missing datum's) Strange behavior of toCardanoTxBody (missing datums) Nov 23, 2021
@bhoudebert
Copy link

Hi, faced similar issue but only in offChain code.

100% working in simulator I got datum directly but when running against testnet only hash without any correspondence.

It could be related to a WIP on plutus/pab side.

@Yasuke
Copy link
Contributor

Yasuke commented Nov 26, 2021

Thank you for raising this issue, we have a goal to resolve these discrepancies on our roadmap, and after we get there we would expect to see the datum handled the same on both testnet and emulation.

@cstml
Copy link

cstml commented Nov 30, 2021

This might offer some insight cardano-foundation/CIPs#160. Currently, an eutxo on-chain doesn't contain the Datum itself, but only its hash.

@anton-k
Copy link
Contributor Author

anton-k commented Dec 1, 2021

@cstml I'm aware of that. But we need to have some way to pass datums for validation.
And after conversion they are present for inputs but not for outputs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants