Skip to content
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

[Neo Json Fix] Json null tests #3450

Merged
merged 4 commits into from
Aug 8, 2024
Merged

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Aug 5, 2024

Description

Json JArry has a method AsString but it can not properly convert json into json string, but a string without "[ ]",

{"name":"alice","age":30,"score":100.001,"gender":"female","isMarried":true,"pet":{"name":"Tom","type":"cat"}},{"name":"bob","age":100000,"score":0.001,"gender":"male","isMarried":false,"pet":{"name":"Paul","type":"dog"}}

And it can not handle null value. Thus having this pr that fix this bug and adds more tests.

Fixes #

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TestToStringWithNull
  • TestFromStringWithNull
  • TestAddNull
  • TestSetNull
  • TestInsertNull
  • TestRemoveNull
  • TestContainsNull
  • TestIndexOfNull
  • TestCopyToWithNull

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y added waiting for review bug Used to tag confirmed bugs labels Aug 5, 2024
@@ -252,7 +252,7 @@ public void TestAsString()
bob,
};
var s = jArray.AsString();
Assert.AreEqual(s, "{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}");
Assert.AreEqual(s, "[{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}]");
Copy link
Member

@shargon shargon Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it change the behavior, and it could require a hardfork

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And JSON is available from contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it must be a hardfork, then make it a hardfork, this one also need to be reviewed:

#3037

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the contact behavior is bad,,,,,,,i know, but what we gonna do with tons of problems in the core....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And JSON is available from contracts.

BTW, how does contract use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And without [] is only part of the problem, it also lacks null object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than what is the point of having AsString vs ToString? If they both do the samething.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than what is the point of having AsString vs ToString? If they both do the samething.

To be honest i dont know,,,, and there is no document for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And without [] is only part of the problem, it also lacks null object.

could you fix both at same time, but we need to ensure that is not possible to call it by a smart contract

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And without [] is only part of the problem, it also lacks null object.

could you fix both at same time, but we need to ensure that is not possible to call it by a smart contract

Already fixed.

@shargon
Copy link
Member

shargon commented Aug 8, 2024

change branch to HF?

@Jim8y
Copy link
Contributor Author

Jim8y commented Aug 8, 2024

change branch to HF?

No, this one does not require HF. It is not being used actually.

@shargon shargon merged commit 28043cb into neo-project:master Aug 8, 2024
7 checks passed
@Jim8y Jim8y deleted the json-null-tests branch August 8, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to tag confirmed bugs ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants