Skip to content

Commit

Permalink
this unittest for
Browse files Browse the repository at this point in the history
  • Loading branch information
lightszero committed Mar 5, 2020
1 parent adf9425 commit d4a231a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@
</None>
</ItemGroup>

<ItemGroup>
<Compile Update="UnitTest_TypeConvert.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
</ItemGroup>

</Project>
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;
}


}
}
31 changes: 31 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_TypeConvert.cs
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);
}

}
}

0 comments on commit d4a231a

Please sign in to comment.