-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add byte.AsString and Map UTs #303
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
64378ba
add byte.AsString and Map UTs
49cc027
fix
c0c5ace
Update src/Neo.SmartContract.Framework/Helper.cs
ShawnYun 7d39164
fix
5cdbd88
Merge branch 'master' into support-byte-asstring
shargon 2376c21
fix
1d7d97a
Merge branch 'support-byte-asstring' of https://github.com/ShawnYun/n…
f860f75
Merge branch 'master' into support-byte-asstring
9d2c2b1
Merge branch 'master' into support-byte-asstring
shargon afe9e63
Merge branch 'master' of https://github.com/neo-project/neo-devpack-d…
d8232c0
Merge branch 'support-byte-asstring' of https://github.com/ShawnYun/n…
1dd3755
fix Enum and Iterator Test
4a5b93d
Merge branch 'master' into support-byte-asstring
shargon 91e7e9f
update neo
6e008cf
Merge branch 'support-byte-asstring' of https://github.com/ShawnYun/n…
242d92d
fix
1c0d44c
merge
412d761
fix map key and UT
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Compiler.MSIL.UnitTests.Utils; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
|
||
namespace Neo.SmartContract.Framework.UnitTests | ||
{ | ||
[TestClass] | ||
public class MapTest | ||
{ | ||
private TestEngine _engine; | ||
|
||
[TestInitialize] | ||
public void Init() | ||
{ | ||
_engine = new TestEngine(); | ||
_engine.AddEntryScript("./TestClasses/Contract_Map.cs"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestByteArray() | ||
{ | ||
_engine.Reset(); | ||
_engine.ExecuteTestCaseStandard("testByteArray"); | ||
Assert.AreEqual(VMState.FAULT, _engine.State); | ||
} | ||
|
||
[TestMethod] | ||
public void TestByteArray2() | ||
{ | ||
_engine.Reset(); | ||
StackItem key = System.Text.Encoding.ASCII.GetBytes("a"); | ||
var result = _engine.ExecuteTestCaseStandard("testByteArray2", key); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(ByteString)); | ||
// Except: {"a":"teststring2"} | ||
Assert.AreEqual("7b2261223a2274657374737472696e6732227d", (item as ByteString).GetSpan().ToHexString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestByteArray3() | ||
{ | ||
_engine.Reset(); | ||
var result = _engine.ExecuteTestCaseStandard("testByteArray3"); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(ByteString)); | ||
// Except: {"\u0001\u0001":"\u0022\u0022"} | ||
Assert.AreEqual("7b225c75303030315c7530303031223a225c75303032325c7530303232227d", (item as ByteString).GetSpan().ToHexString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestUnicode() | ||
{ | ||
_engine.Reset(); | ||
StackItem key = System.Text.Encoding.UTF8.GetBytes("中"); | ||
var result = _engine.ExecuteTestCaseStandard("testUnicode", key); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(ByteString)); | ||
// Except: {"\u4E2D":"129840test10022939"} | ||
Assert.AreEqual("7b225c7534453244223a22313239383430746573743130303232393339227d", (item as ByteString).GetSpan().ToHexString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestUnicodeValue() | ||
{ | ||
_engine.Reset(); | ||
StackItem value = System.Text.Encoding.UTF8.GetBytes("文"); | ||
var result = _engine.ExecuteTestCaseStandard("testUnicodeValue", value); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(ByteString)); | ||
// Except: {"ab":"\u6587"} | ||
Assert.AreEqual("7b226162223a225c7536353837227d", (item as ByteString).GetSpan().ToHexString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestUnicodeKeyValue() | ||
{ | ||
_engine.Reset(); | ||
StackItem key = System.Text.Encoding.UTF8.GetBytes("中"); | ||
StackItem value = System.Text.Encoding.UTF8.GetBytes("文"); | ||
var result = _engine.ExecuteTestCaseStandard("testUnicodeKeyValue", key, value); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(ByteString)); | ||
// Except: {"\u4E2D":"\u6587"} | ||
Assert.AreEqual("7b225c7534453244223a225c7536353837227d", (item as ByteString).GetSpan().ToHexString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestInt() | ||
{ | ||
_engine.Reset(); | ||
StackItem key = 1; | ||
_engine.ExecuteTestCaseStandard("testInt", key); | ||
// Int cannot be used as the key for serializing Map | ||
Assert.AreEqual(VMState.FAULT, _engine.State); | ||
} | ||
|
||
[TestMethod] | ||
public void TestBool() | ||
{ | ||
_engine.Reset(); | ||
StackItem key = true; | ||
_engine.ExecuteTestCaseStandard("testBool", key); | ||
// Bool cannot be used as the key for serializing Map | ||
Assert.AreEqual(VMState.FAULT, _engine.State); | ||
} | ||
|
||
[TestMethod] | ||
public void TestDeserialize() | ||
{ | ||
_engine.Reset(); | ||
var result = _engine.ExecuteTestCaseStandard("testDeserialize", "a"); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(1, result.Count); | ||
|
||
var item = result.Pop(); | ||
Assert.IsInstanceOfType(item, typeof(Map)); | ||
var map = item as Map; | ||
Assert.AreEqual(1, map.Count); | ||
Assert.IsTrue(map.ContainsKey("a")); | ||
Assert.AreEqual((ByteString)"testdeserialize", map["a"]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should we do conversion when loading argument?
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 a byte[] should be converted to
Buffer
.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.
Sure. But you shouldn't convert it when loading. I think the conversion should be done when the data is pushed onto the stack.
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, here is the opcode
LDARG
, arg will be pushed onto stack.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 conversion should be done when the first time that the data is pushed onto the stack.
LDARG
loads the data from the slot, and the data from the slot is from stack before.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.
Otherwise, you have to convert it everytime when load from slot.
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 args appears to be pushed on the stack before
Loadscript
? The compiler cannot convert 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.
Then don't convert it. The argument should be
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.
Or we can check the type of agrs in
INITSLOT
. Now in NeoVM we only check the count, not the type.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 think it's good, it may not be efficient for compiler to check the parameter type after
INITSLOT
.