-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra validation of data for encoding #86
Conversation
@@ -85,6 +85,9 @@ class DataFactory { | |||
} | |||
|
|||
if (type.name === 'list') { | |||
if (!Array.isArray(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to not validate it in the type class ? DataFactory should be general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because later we are calling the map
method of value
, should we move it to FateList
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, I've overlooked that.
However there is non-sense tautology in the error message "list must be an array", same for tuple: "Tuple must be an array". Please try to find a better error message.
Something like "[Fate] List constructor expects an array of values, got X instead"
And slight note on formatting, please have a new line after each block of statements, if that not the last statement in another block. I know I've to commit the rules and it's not obvious from the codebase .. soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Fate] List constructor expects an array of values, got X instead
I'm not sure about the exact message
- won't "Sophia" be more clear than "Fate" for third-party users?
- the constructor seems to be too internal part to mention it
- I would drop "of values" because this is the same for any array, technically we can generate the exact type instead (like array of numbers)
- would be better to name Array from the capital letter to highlight that this is a JS type?
- should we do
JSON.stringify
of X? should we handle the "Do not know how to serialize a BigInt" exception then?
Proposing to change it to "Sophia list must be an Array, got X instead"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My message was just an example, feel free to change it to whatever feel better. However, again on users .. this library has nothing to do with Sophia programming language, but FATE virtual machine :) So please don't use the term sophia, you don't have to use the term fate as well if you don't think it's a good fit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t know really, AEVM is deprecated, so the only VM now is FATE. We also don’t know if there would be any other VM in future so let’s keep it simple? I’m more lean to drop off the calldata from the name as I plan to add full serializaion support anytime soon, however we might just split the serializer and encoder 🤔🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also when looking into the readme that might be confusing. just want to raise that topic now :-)
Would you propose readme changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shouldn't have interferred here 😅 - actually I currently don't have concrete proposals. I am fine with leaving like is for the moment in regards to the readme.
We also don’t know if there would be any other VM in future so let’s keep it simple?
👍
I’m more lean to drop off the calldata from the name as I plan to add full serializaion support anytime soon
might make sense in that case to do this better earlier than later. we should have some reliable release (& npm package) in the near future 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should rush about that, the only user of the lib is the SDK so we should be fine for quite some time.
The lib already have NPM packages and release process in place, once we all agree on it's stability we should tag 1.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.0.0-rc1 perhaps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the DataFactory general - knowing nothing about types specifics, but only how to create types
src/types/FateInt.js
Outdated
try { | ||
this._value = BigInt(value) | ||
} catch (error) { | ||
if (/^Cannot convert .* to a BigInt$/.test(error.message)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason changing the error message ?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using calldata the developer may not use BigInts explicitly, so it may be unclear why an argument should be convertible to BigInt. "number" is more general than "BigInt" so the developer would guess that the problem is rather on his side than in the internals of calldata.
But I'm not 100% sure about it and ok to revert this if @marc0olo @mradkov agrees that this is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhhhh, when thinking about this I don't think we really need this. I mean every experienced dev should know how to handle this or whats the problem, right? Personally I favor the original error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reason, don't hold for me. Please revert.
56c71b0
to
3348eb1
Compare
src/types/FateBytes.js
Outdated
@@ -12,7 +12,13 @@ const toByteArray = (value) => { | |||
return HexStringToByteArray(value) | |||
} | |||
|
|||
return Int2ByteArray(BigInt(value)) | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be reverted as well ? I didn't feel it was necessary to comment on each error message rewrite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea is to show complete error message in case if we wasn't able to convert value to byte array.
Number is the less obvious representation of byte array, can we replace this validation with Array.isArray
to show error like "is not an array" instead "can't convert to BigIng" in case we remove the complete error message?
We need an agreement on developer friendlies. SDK before was too developer friendly, I'm just trying to make the difference not so significant (on calldata side).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m more or less against changing of error messages. Additional validation should be fine. It’s also fine if SDK strive to be developer friendly, however this lib is more low level and doesn’t target non experienced devs. It should be focused on specification conformance, clean code, maintability (that includes minimal solid API) and performance
3348eb1
to
b7e7953
Compare
b7e7953
to
41b478b
Compare
@@ -12,7 +12,11 @@ const toByteArray = (value) => { | |||
return HexStringToByteArray(value) | |||
} | |||
|
|||
return Int2ByteArray(BigInt(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, value converted to BigInt
at the first line of Int2ByteArray
No description provided.