|
18 | 18 | using Neo.SmartContract.Native; |
19 | 19 | using Neo.VM; |
20 | 20 | using Neo.VM.Types; |
| 21 | +using Org.BouncyCastle.Asn1.Tsp; |
21 | 22 | using System; |
22 | 23 | using System.Collections.Generic; |
23 | 24 | using System.Linq; |
@@ -152,7 +153,7 @@ public void TestEmitAppCall3() |
152 | 153 | sb.EmitDynamicCall(UInt160.Zero, "AAAAA", true); |
153 | 154 | byte[] tempArray = new byte[38]; |
154 | 155 | tempArray[0] = (byte)OpCode.PUSHT; |
155 | | - tempArray[1] = (byte)OpCode.PUSH1;//arg.Length |
| 156 | + tempArray[1] = (byte)OpCode.PUSH1;//arg.Length |
156 | 157 | tempArray[2] = (byte)OpCode.PACK; |
157 | 158 | tempArray[3] = (byte)OpCode.PUSH15;//(byte)CallFlags.All; |
158 | 159 | tempArray[4] = (byte)OpCode.PUSHDATA1; |
@@ -401,6 +402,7 @@ public void TestEmitPush3() |
401 | 402 | TestEmitPush3Byte(); |
402 | 403 | TestEmitPush3Short(); |
403 | 404 | TestEmitPush3Ushort(); |
| 405 | + TestEmitPush3Char(); |
404 | 406 | TestEmitPush3Int(); |
405 | 407 | TestEmitPush3Uint(); |
406 | 408 | TestEmitPush3Long(); |
@@ -472,6 +474,16 @@ private void TestEmitPush3Ushort() |
472 | 474 | CollectionAssert.AreEqual(tempArray, sb.ToArray()); |
473 | 475 | } |
474 | 476 |
|
| 477 | + private void TestEmitPush3Char() |
| 478 | + { |
| 479 | + ScriptBuilder sb = new ScriptBuilder(); |
| 480 | + char temp = char.MinValue; |
| 481 | + VM.Helper.EmitPush(sb, temp); |
| 482 | + byte[] tempArray = new byte[1]; |
| 483 | + tempArray[0] = (byte)OpCode.PUSH0; |
| 484 | + CollectionAssert.AreEqual(tempArray, sb.ToArray()); |
| 485 | + } |
| 486 | + |
475 | 487 | private void TestEmitPush3Short() |
476 | 488 | { |
477 | 489 | ScriptBuilder sb = new ScriptBuilder(); |
@@ -630,5 +642,28 @@ private void TestToParaMeter2VMArray() |
630 | 642 | Assert.AreEqual(ContractParameterType.Array, parameter.Type); |
631 | 643 | Assert.AreEqual(0, ((List<ContractParameter>)parameter.Value).Count); |
632 | 644 | } |
| 645 | + |
| 646 | + [TestMethod] |
| 647 | + public void TestCharAsUInt16() |
| 648 | + { |
| 649 | + Assert.AreEqual(ushort.MaxValue, char.MaxValue); |
| 650 | + Assert.AreEqual(ushort.MinValue, char.MinValue); |
| 651 | + |
| 652 | + // test every char in a loop |
| 653 | + for (int i = ushort.MinValue; i < char.MinValue; i++) |
| 654 | + { |
| 655 | + var c = Convert.ToChar(i); |
| 656 | + Assert.AreEqual(i, c); |
| 657 | + } |
| 658 | + |
| 659 | + for (int i = ushort.MinValue; i < ushort.MaxValue; i++) |
| 660 | + { |
| 661 | + using var sbUInt16 = new ScriptBuilder(); |
| 662 | + using var sbChar = new ScriptBuilder(); |
| 663 | + sbUInt16.EmitPush((ushort)i); |
| 664 | + sbChar.EmitPush(Convert.ToChar(i)); |
| 665 | + CollectionAssert.AreEqual(sbUInt16.ToArray(), sbChar.ToArray()); |
| 666 | + } |
| 667 | + } |
633 | 668 | } |
634 | 669 | } |
0 commit comments