HeliosLang / compiler

Helios is a DSL for writing Cardano smart contracts. This library lets you compile Helios scripts and build Cardano transactions.
https://www.hyperion-bt.org/helios-book
BSD 3-Clause "New" or "Revised" License
139 stars 30 forks source link

Extend UserError to include Args #81

Closed gavinharris-dev closed 1 year ago

gavinharris-dev commented 1 year ago

Just wondering if you'd be open to adding in the args (CBOR Encoded) into an Attribute of UserError when thrown?

Change would be in TxWitness::executeRedeemer; something like:

if (profile.result instanceof UserError) {
  profile.result.args = encodeArgs(args);
  throw profile.result;
} else {

The encodeArgs would just loop thru the 3 Array entries converting the UplcDataValue into CBOR Hex. Again something like:

function encodeArgs(args) {
  return [
    bytesToHex(args[0].data.toCbor()),
    bytesToHex(args[1].data.toCbor()),
    bytesToHex(args[2].data.toCbor())
  ]
}

This would be useful for integration testing / validation as we can then take the 'args' and provide them into a run with a verion of the contract compiled without removing 'print' and 'trace' statements.

christianschmitz commented 1 year ago

v0.13.37 adds a context property to UserError, which is filled with Datum, Redeemer and ScriptContext for validator scripts throwing an error, and Redeemer and ScriptContext for minting scripts throwing an error.

Eg. error.context.Datum: string