IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
306 stars 214 forks source link

Emulator fails with no stack trace if initial wallet distribution contains a number of different tokens #417

Open mpetruska opened 2 years ago

mpetruska commented 2 years ago

Summary

An emulator failure happens with no usable information when on the initial distribution one (or more) of the wallets contains a number of different tokens (other than ADA). According to the documentation, the minimum ADA value for UTxOs containing tokens are higher then ADA only UTxOs, but the function splitOffAdaOnlyValue in Wallet/Emulator/Wallet.hs does not take that into consideration, it only sets minAdaTxOut ADA to the non-ADA part.

Steps to reproduce the behavior

  1. Create an emulator trace with initial distribution that contains a number of different token types (with long names and policyIds).
  2. Run the trace.

Actual Result

The test fails with no details:

        This must be replaced by the core-to-plc plugin during compilation: error
        CallStack (from HasCallStack):
          error, called at src/PlutusTx/Utils.hs:7:26 in plutus-tx-0.1.0.0-a375f22d0d8c7641a5b365b3c6ecf3be6ea8edd57bc0b7955fbc2d4c96139e5b:PlutusTx.Utils

Expected Result

The test succeeds, or reports a meaningful message about initial wallet distribution.

Describe the approach you would take to fix this

According to https://cardano-foundation-cardano.readthedocs-hosted.com/en/latest/native-tokens/minimum-ada-value-requirement.html, the required ADA value should be calculated with the same function as it is validated for on-chain.

System info

OS: NixOS Plutus-apps: v2022-04-06

koslambrou commented 2 years ago

Can you provided more details?

We already have a test case which tests this case: https://github.com/input-output-hk/plutus-apps/blob/main/plutus-contract/test/Spec/Balancing.hs#L40-L65

Did we miss something?