Skip to content

Client/Michelson: Ignore indentation of Michelson scripts in `convert script` and `hash script` commands

Context

The Micheline parser has an option to ignore indentation but IFAIK it is currently unused; all client commands fail when given a badly-indented file as input. This MR uses the option to ignore indentation in the two commands for which it was the easiest: convert script and hash script.

Ignoring indentation in convert script can be useful to use it as a Michelson formatter with the following call tezos-client convert script <script> from Michelson to Michelson.

Ignoring indentation in hash script can be useful when checking hash of scripts produced by tools that don't honor the Micheline indentation rules such as Mi-Cho-Coq.

Related: #1136 and #1310 (closed).

Manually testing the MR

Here is a manual test:

$ cat > badly_indented.tz <<END
parameter string;
  storage string;
 code {CDR; NIL operation; PAIR}
END
$ # check that the contract is rejected by the typecheck command
$ mockup_client typecheck script badly_indented.tz
At line 2 characters 2 to 16, misaligned expression
At line 3 characters 1 to 32, misaligned expression
Fatal error:
  syntax error in program
$ HASH_BEFORE=$(mockup_client hash script badly_indented.tz)
$ mockup_client convert script badly_indented.tz from Michelson to Michelson > well_indented.tz
$ HASH_AFTER=$(mockup_client hash script well_indented.tz)
$ [ $HASH_BEFORE = $HASH_AFTER ] && echo "Same hash"
Same hash
$ mockup_client typecheck script well_indented.tz
Well typed
Gas remaining: 1039996.720 units remaining

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, the Development Version section of CHANGES.md for everything else).
  • Select suitable reviewers using the Reviewers field below.
Edited by Raphaël Cauderlier

Merge request reports