Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Emulator tests #14

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zmrocze
Copy link
Contributor

@zmrocze zmrocze commented Jul 4, 2024

Hey,

we were not able to provide the emulator test suite in time. Therefore we only provide the WIP branch - you may find it of use, but be noted that it is in quite WIP and uncommented state of things.

So maybe of bigger value would be if I describe what needs to be done to test in the emulator.

But first, why that'd be great to do is that it improves the developer experience a lot. The tests run quicker and TxOutRef needs to be set in code and no scripts need to be regenerated with every additional test run. All test runs can mint their own NFT thread token so tests become reproducible. Also you could run these tests in CI. I recommend it a lot to put a bit of time into this improvement, it'll pay of.

To test in lucid emulator:

  1. Swap lucid blockfrost instance for lucid emulator instance. Change all occurences of Date.now() to Emulator.now(). Fund the generated private keys that are needed in the tests in the emulator configuration.
  2. Apply scripts to parameters in offchain code (only). Why? We don't want to and can't set a TxOutRef to be used for the NFT mint. Only after we query the utxos in the emulator, we can apply the scripts. (*) This demands to apply the scripts to the parameters (NftParams, TokenName etc.) dynamically, that is from the lucid offchain testing code, not in the haskell onchain.

The pr here did 1. but then 2. needs some debuggin work to be done. The script paramaters are not properly serialized to be provided to the scripts for application.
The step 2. is the harder one. Great care needs to be taken to properly serialize the data to be passed to the scripts. Also the scripts are changed in how they parse the parameters. In other words - this is a big change that needs to be properly tested and influences the scripts. After the change all scripts should be applied in the same way from lucid offchain, to avoid errors when haskell onchain produces different scripts than lucid offchain. Consider the choice here as: significant amount of work could bring significant improvement.

As a added benefit, you already define the offchain infrastructure that would be needed either way - if you are to use multiple instances of the protocol, spawned automatically from offchain code.

(*): Comment needs to be made here, because there is a simpler, though a bit hacky way to define emulator tests. Namely: because the UTXOs defined in the emulator have predictable TxoutRef's - this means that the step 2. is not needed if the tests are run with scripts using such TxoutRef that will be present in the lucid emulator. In this way the scripts can be defined in the same as now, from haskell code by hardcoding the TxOutRef - one TxOutRef for real use, another for emulator tests.
This would be the much simpler and safer aproach - and would still bring most of the testing benefits!

@zmrocze
Copy link
Contributor Author

zmrocze commented Jul 11, 2024

@Timekiller7 Hey,
pushing a piece of work, you may or may not find useful at some point.
We don't expect you guys to act in any way on the pr here. Just sharing for that work not to get lost - and maybe thats something at least somewhat useful to you at a later date.

Would be great if we managed to provide this in a working form, but that was not the case in the timespan.
The pr here has a problem with the way data is serialized to be provided to the scripts. There's significant amount of debugging likely ahead to complete this change, so decide if thats even worth for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants