Encode accepts non-conformant JS Values for OrToken #2544
Labels
bug
Something isn't working
Michelson 🥸
Related to Michelson language and Taquito's handling of same
Michelson-encoder
ux/dx
Related to Developer Experience
Milestone
Description
In the spirit of enforcing type checking on the JS side that is equivalent to that on the Micheline side, OrToken.Encode(val) should only accept an object with a single key, one that corresponds to a Micheline Left-Right position, and one whose type is consistent with the Micheline type found in that Left-Right position of the root OrToken.
The current OrToken.Encode(val) accepts objects with multiple keys. It traverses the root OrToken looking for non-or Token with a matching key. Processing terminates with the first one found. This allows a developer to erroneously conclude that they have successfully encoded a JS object with multiple keys, as an equivalent JSON encoded Micheline value. In the spirit of tight type checking any attempt to OrToken.Encode a val with more than one key should fail.
Steps To Reproduce
Consider the following:
Or1.Execute(val) maps conformant JSON-encoded Micheline values to a flat object with a single key.
However, Or1.Encode( {“0”: 5, “1”: “foo”, “2”: true}) returns a JSON-encoded value for:
Left (Left 5). The other key-value pairs of are simply ignored. A correct result would be for the Encode to raise an invalid-type error.
Expected behavior
Add logic to OrToken.Encode(val) to ensure that any attempt to encode a val with more than one key fails.
Additional context
Refer to AS-IS OrToken document
The text was updated successfully, but these errors were encountered: