-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adf9425
commit d4a231a
Showing
3 changed files
with
88 additions
and
0 deletions.
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
51 changes: 51 additions & 0 deletions
51
tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TypeConvert.cs
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,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Numerics; | ||
using Neo.SmartContract.Framework; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests.TestClasses | ||
{ | ||
|
||
class Contract_TypeConvert : SmartContract.Framework.SmartContract | ||
{ | ||
//Integer = 0x21, | ||
//ByteArray = 0x28, | ||
[OpCode(SmartContract.Framework.OpCode.CONVERT, "0x28")] | ||
public extern static byte[] ConvertToByteArray(object from); | ||
|
||
|
||
[OpCode(SmartContract.Framework.OpCode.CONVERT, "0x21")] | ||
public extern static BigInteger ConvertToInteger(byte[] from); | ||
|
||
|
||
|
||
|
||
public static object testType() | ||
{ | ||
BigInteger int0 = 0; | ||
var bts0 = ConvertToByteArray(int0); | ||
BigInteger int1 = 2; | ||
var bts1 = ConvertToByteArray(int1); | ||
|
||
var bts2=new byte[1] { 3 }; | ||
var int2 = ConvertToInteger(bts2); | ||
|
||
var bts3 = ConvertToByteArray(new byte[0]) ; | ||
var int3 = ConvertToInteger(bts3); | ||
|
||
var arrobj = new object[8]; | ||
arrobj[0] = int0; | ||
arrobj[1] = bts0; | ||
arrobj[2] = int1; | ||
arrobj[3] = bts1; | ||
arrobj[4] = bts2; | ||
arrobj[5] = int2; | ||
arrobj[6] = bts3; | ||
arrobj[7] = int3; | ||
return arrobj; | ||
} | ||
|
||
|
||
} | ||
} |
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,31 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Compiler.MSIL.UnitTests.Utils; | ||
using Neo.VM.Types; | ||
using System.Linq; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_TypeConvert | ||
{ | ||
[TestMethod] | ||
public void UnitTest_TestTypeConvert() | ||
{ | ||
var testengine = new TestEngine(); | ||
testengine.AddEntryScript("./TestClasses/Contract_TypeConvert.cs"); | ||
var result = testengine.ExecuteTestCaseStandard("testType"); | ||
|
||
//test 0,1,2 | ||
Assert.IsTrue(result.TryPop(out Array arr)); | ||
Assert.IsTrue(arr[0].Type == StackItemType.Integer); | ||
Assert.IsTrue(arr[1].Type == StackItemType.ByteArray); | ||
Assert.IsTrue(arr[2].Type == StackItemType.Integer); | ||
Assert.IsTrue(arr[3].Type == StackItemType.ByteArray); | ||
Assert.IsTrue(arr[4].Type == StackItemType.ByteArray); | ||
Assert.IsTrue(arr[5].Type == StackItemType.Integer); | ||
Assert.IsTrue(arr[6].Type == StackItemType.ByteArray); | ||
Assert.IsTrue(arr[7].Type == StackItemType.Integer); | ||
} | ||
|
||
} | ||
} |