taquito
taquito copied to clipboard
ExtractSchema is not aligned with Execute and Encode for OrToken
Background As a Micheline data type OrTokens represent a “one-of” constraint. A conformant value must be a value corresponding to one-of the cited types. On the Micheline side, the cited types are either typ1 or typ2 of the JSON-encoded representation of the Micheline type. The possibility of nested ORs allows for the logical extension of this optionality to more than two non-or types. While the same type may appear more than once, the semantics of a value is inferred by its Left-Right position with respect to the root OrToken.
On the JS side, OrToken.ExtractSchema interprets the OrToken as a JS object type with multiple keys. A conformant value must be a value corresponding to one-of the key-value pairs of the ExtractSchema result. While the same type may appear more than once, in this case, the semantics of a value is inferred by its key.
Description OrToken.ExtractSchema transforms Nested ORs into a JS Object structure that is sensitive to whether a Nested Or is annotated or not. This is not aligned with OrToken.Execute or OrToken.Encode which abstracts away Nested ORs regardless of whether it is annotated or not. The following examples serve to illustrate this point.
Steps To Reproduce One level of nesting
Consider the following:
Or1
Or2
int
string
%A
Bool
Or1.ExtractSchema() interprets this as: {A: {“0”: int, “1”: string}, “1”: bool} it does not properly represent the OrToken one-of constraint described earlier
Expected behavior However, Or1.Execute(val) always maps conformant JSON-encoded Micheline values to a flat object with a single key.
Left (Left 5) maps to {“0”: 5}
Left (Right “foo”) maps to {“1”: “foo”}
Right True maps to {“2”: true}
This suggests that Or1.ExtractSchema should really map to {“0”: int, “1”: string, “2”: bool}.
Additional context Request links to Michelson Encoder "AS-IS OrToken Bugs" google docs from Inna