-
Notifications
You must be signed in to change notification settings - Fork 1k
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 VM: FIX] the GetString() methods of bytestring requires strictUTF8 #3110
Conversation
src/Neo.VM/EvaluationStack.cs
Outdated
@@ -45,7 +45,7 @@ public override string ToString() | |||
StackItemType.Pointer => $"({((Pointer)p).Position})", | |||
StackItemType.Boolean => $"({p.GetBoolean()})", | |||
StackItemType.Integer => $"({p.GetInteger()})", | |||
StackItemType.ByteString => $"(\"{p.GetString()}\")", | |||
StackItemType.ByteString => p.GetSpan().ToArray().TryGetString(out var str) ? $"(\"{str}\")" : $"(\"{Convert.ToBase64String(p.GetSpan())}\")", |
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.
Mixing base64 and strings (that can be valid base64 as well) is not a good idea to me, how can I differentiate 41414141
from 000000
then?
This also is an incompatible change.
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.
Mixing base64 and strings (that can be valid base64 as well) is not a good idea to me, how can I differentiate
41414141
from000000
then?This also is an incompatible change.
@roman-khimov What? this is only for the ease of debug and unit test,,,, how come it can be incompatible to something? we dont print the executionstack anywhere but unit test (I added it in some pr that not yet merged). But maybe i should add somthing to tell if its base64 or string.
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 how exactly it's used in the current codebase, but it's public
. If it's debug/test only, then maybe it's OK (can it be used by plugins/other tools?).
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.
yes, cause i originally added this to debug the devpack, currently nowhere in the master branch is using it.
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.
Doesn't matter it's in the main Neo.VM
. If it's for tests then add it to the unit test's code. Don't add testing code to the main source. Add ONLY to test projects.
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.
thought about it, but we will need it cross all unit tests, including devpack.
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 put test in main code. It can get mixed up to easily. Especially for a new person and if it's not documented. If it ends up being in main code. It needs to fail, unless running in a test. Just create new library for unit tests functionality that is the same for the test projects. What if for example someone end up getting alot of free gas cause they called a test function?
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.
will update.
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.
Refs. #3033 (not in any release yet, can be changed/removed). I agree with @cschuchardt88, this shouldn't be widely exposed if it's debug/test only.
…ded. As it is a test method and only unit test will need it.
@shargon @cschuchardt88 please check. |
This isn't a must but all filenames and classes should start with |
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.
Like this @Jim8y https://github.com/neo-project/neo/pull/3103/files#diff-4faae5d98adc622a6e3016c1f98c157bd6cbabf32b55440248d30020edfd0b99
Look at filename
and class
.
This one alignes with existing file and tests, maybe update them all together in another pr. but before that, i think we should keep it this way. Take a look at: https://github.com/neo-project/neo/blob/master/tests/Neo.VM.Tests/Helpers/RandomHelper.cs |
Also for Test methods with attribute |
Also i think we can deal with the name some time later, we should leave these to the editorstyle instead of manually. |
I understand that. But this change will make life easier for the future or for someone coming in not knowing whether or not its core functioning code or test code they are debugging and reading so time isn't wasted. |
I understand that name style is a thing, but there are many many rules everywhere, we should not take care of them manually, but use a tool to detect them. |
Surely will, @shargon you going to take this? |
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.
@Jim8y What about override ToString in all stack items?
compound types is hard to print, will make the console impossible to trace, cause it will be printed on every opcode |
It will print only the count, will be the same, but reusable |
@shargon just tried it out, even if you have to sting for each item, you still need a method for stack to print the stack. Just making it easier to implement, but still need somthing on both devpack side and vm side. Or just add it to the core. Come on, @shargon and @cschuchardt88 are caring about different things, this will make our work hard, how about we focus on the functionality first? I have kept moving them here there, but they just work the same. |
Why don't you have a look at |
We can access stack, but we can not access the things in the vm test. Have a new test project solely for a stack.print is not necessary. Cause we will either have to add it as reference in the devpack, or publish it, too much for a print. |
I� need to print the stack, not the stack items, but everything in the stack. |
We can have both |
{ | ||
public static string Print(this EvaluationStack stack) | ||
{ | ||
return $"[{string.Join(", ", stack.Select(p => $"{p.Type}{p}"))}]"; |
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.
In my opinion, we should move this to ToString
no sense to duplicate code everywhere, and also is useful for debug
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.
so you still need to have one in VM test and one in devpack test, what is the difference.
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.
It doesn't hurt, and is good to override ToString
to see something useful during debug, writes, etc
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.
There should a Interface or some way to hook into the VM for override
.
Please stop rushing code designs. It clear that no thought is put into the design when making code changes. Copy and Paste isn't the solution. I am not talking to anyone person, but us as a whole. I do it too. But we need to all stop and have plans. I think we should have in the 1st comment of the PR, what the plan is for design when doing design changes. Yes it takes more time, But we need the time to refactor and think it through.
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.
There should a Interface or some way to hook into the VM for override.
This change is not required for core, is only for debugging and testing purpose
Good to go then |
* master: Related to neo-project#3082 (comment) (neo-project#3119) [VM UT] update UT name (neo-project#3115)
* 'nullable' of github.com:Jim8y/neo: [Neo Fix] fix the store crash issue (neo-project#3124) [Neo VM: FIX] the GetString() methods of bytestring requires strictUTF8 (neo-project#3110)
Description
The GetString methods of StackItem requires strick UTF8.
Type of change
How Has This Been Tested?
Test Configuration:
dotnet test
Checklist: