-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Minor improvement: Check sources #3502
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- returns error, if "sources" is an array, an empty object or not defined - Added new test-cases in test/libsolidity/StandardCompiler.cpp
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,42 @@ BOOST_AUTO_TEST_CASE(no_sources) | |
| BOOST_CHECK(containsError(result, "JSONError", "No input sources specified.")); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(no_sources_empty_object) | ||
| { | ||
| char const* input = R"( | ||
| { | ||
| "language": "Solidity", | ||
| "sources": {} | ||
| } | ||
| )"; | ||
| Json::Value result = compile(input); | ||
| BOOST_CHECK(containsError(result, "JSONError", "No input sources specified.")); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(no_sources_empty_array) | ||
| { | ||
| char const* input = R"( | ||
| { | ||
| "language": "Solidity", | ||
| "sources": [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should result in an error stating it is an invalid input.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its nicely reflected with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the other tests it seems we do not have any more granular reporting, so it should be fine for the moment. Can revisit in the future.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait a second,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we need another check for that, another PR?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just do it in this one.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense. |
||
| } | ||
| )"; | ||
| Json::Value result = compile(input); | ||
| BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object.")); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(sources_is_array) | ||
| { | ||
| char const* input = R"( | ||
| { | ||
| "language": "Solidity", | ||
| "sources": ["aa", "bb"] | ||
| } | ||
| )"; | ||
| Json::Value result = compile(input); | ||
| BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object.")); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(smoke_test) | ||
| { | ||
| char const* input = R"( | ||
|
|
||
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.
Why do we need
isNullhere?Is
IsObjecttrue when the value is null?Uh oh!
There was an error while loading. Please reload this page.
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.
@axic nope.. but
nullis also not an object.. so if there is nosourcesobject at all, it is also not an object..!sources.isObject()is alsotrue- that's why I do the additional check here.however, just in case you didn't noticed: I introduced a slightly different error message here:
Sources input is not a JSON object.in contrast toSource input is not a JSON object.- from my point of view its nice nice to distinguish betweensourcesis not a json object, and if items ofsources- so individual members of thesourcesobject -sourceis not a json object.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.
Ah, yes that makes sense :)