3 level Michelson structure missing elements when transformed to JS in for PairToken #2540
Labels
bug
Something isn't working
Michelson 🥸
Related to Michelson language and Taquito's handling of same
Michelson-encoder
Milestone
Description
The transformation from JSON encoded Micheline value into JS representation skips flattens 3 level schema into 2 levels and skips an element.
Steps To Reproduce
This bug manifests when we have three-levels of pair nesting:
Pair1, Pair2, Pair3 return PairToken.Execute Object1, Object2, Object3 results respectively.
Pair2 knows that Pair3 is annotated with “A3'' and Pair2.Execute returns Object2, a JS object with a nested JS object accessed via the A3 key. However, Pair2 erroneously establishes an idx value to its rightValue as if both Object3 keys are visible at the Object2 level (i.e., an idx=2). When Pairing1 retrieves a Pairing2 result it correctly establishes an idx value for its rightValue based on the number of keys contained in Object 2 (once again, an idx=2). As a result, the rightValue.Execute result for Pair1 may contribute a value for the “2” key which overwrites a “2” key value contributed by Pair2.
Expected behavior
Micheline pairs correspond to a kind of record structure. As such they are mapped to JavaScript (JS) objects. In the case where an unannotated pair is referenced by a parent pair, the nesting is abstracted away in the mapping of a Micheline Pair to a JS object. In the case where an annotated pair is referenced by a parent pair, the nesting is preserved in the mapping of a Micheline Pair to a JS object; a new JS object is nested in the parent object with the Micheline pair annotation serving as the parent object key.
Pseudo code for PairToken.Execute( val, idx)
PairToken idx management ensures that mapped-to objects have their own default property namespace. This corresponds naturally with the notion of object property namespaces in JS.
Additional context
A coding experiment was conducted to illustrate this.
For a JSON encoded Micheline schema,
We constructed the JSON encoded Micheline value,
And obtained a result for
const JSValue = storageSchema.Execute(MichelsonValue);
namely:
Here we can see that the Boolean true value from the rightValue.Execute for Pair1 has contributed a value for the “2” key which has overwritten the “2” key value (“33”) contributed by Pair2.
The correct result is:
Request access to the google document when working on this issue from Inna
The text was updated successfully, but these errors were encountered: