示例#1
0
        public void TestStringAdd1()
        {
            _engine.Reset();
            var result = _engine.GetMethod("testStringAdd1").Run("a").ConvertTo(StackItemType.ByteString);

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual("ahello", result.GetString());
        }
示例#2
0
        public void Test_OneReturn()
        {
            testengine.Reset();
            var result = testengine.GetMethod("subtract").Run(5, 9);

            Integer wantresult = -4;

            Assert.IsTrue(wantresult.Equals(result));
        }
示例#3
0
        public void Test_Return_Integer()
        {
            testengine.Reset();
            var result = testengine.GetMethod("returnInteger").Run();

            Integer wantresult = 42;

            Assert.IsTrue(wantresult.Equals(result));
        }
        public void Test_ByteToByteArray()
        {
            var result = _engine.GetMethod("testByteToByteArray").Run();

            StackItem wantResult = new byte[] { 0x01 };

            Assert.AreEqual(wantResult.ConvertTo(VM.Types.StackItemType.ByteString), result.ConvertTo(VM.Types.StackItemType.ByteString));
        }
示例#5
0
        public void Test_ByteArrayPick()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract2.cs");

            var result = testengine.GetMethod("unitTest_002").Run("hello", 1);

            Assert.AreEqual(3, result.GetInteger());
        }
        public void Test_ContractCall()
        {
            var result = _engine.GetMethod("testContractCall").Run().ConvertTo(StackItemType.ByteString);

            Assert.AreEqual(VMState.HALT, _engine.State);

            StackItem wantresult = new byte[] { 1, 2, 3, 4 };
            var       bequal     = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
示例#7
0
        public void Test_ByteArrayAssignmentOverflowUncheked()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract_ByteArrayAssignment.cs");

            var       result     = testengine.GetMethod("testAssignmentOverflowUncheked").Run();
            StackItem wantresult = new byte[] { 0xFF, 0x02, 0x03 };

            Assert.AreEqual(wantresult.ConvertTo(StackItemType.ByteString), result.ConvertTo(StackItemType.ByteString));
        }
示例#8
0
        public void Test_UnitTest_001()
        {
            var _engine = new TestEngine();

            _engine.AddEntryScript("./TestClasses/Contract_ABIOffset.cs");
            var result = _engine.GetMethod("unitTest_001").Run();

            StackItem wantResult = 3;

            Assert.AreEqual(wantResult.ConvertTo(StackItemType.ByteString), result.ConvertTo(StackItemType.ByteString));
        }
        public void Test_OneReturn()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract_Returns.cs");

            var result = testengine.GetMethod("subtract").Run(5, 9);

            Integer wantresult = -4;

            Assert.IsTrue(wantresult.Equals(result));
        }
        public void Test_ByteArrayPick()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses_VB/Contract_Return2.vb");

            var       result     = testengine.GetMethod("unitTest_002").Run();
            StackItem wantresult = 3;

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
        public void Test_ByteArray_New()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses_VB/Contract_Return1.vb");

            var       result     = testengine.GetMethod("unitTest_001").Run().ConvertTo(StackItemType.ByteString);
            StackItem wantresult = new byte[] { 1, 2, 3, 4 };

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
示例#12
0
        public void Test_ByteArrayPick()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract2.cs");

            var       result     = testengine.GetMethod("testfunc").Run("hello", 1, 2, 3, 4);
            StackItem wantresult = 3;

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
示例#13
0
        public void Test_DoubleReturnB()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract_Returns.cs");

            var result = testengine.GetMethod("mix").RunEx(9, 5);

            Assert.AreEqual(1, result.Count);

            Assert.IsTrue(result.TryPop(out Integer r1));
            Assert.AreEqual(-3, r1);
        }
示例#14
0
        public void Test_ByteArray_New()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract1.cs");


            var       result     = testengine.GetMethod("testfunc").Run();
            StackItem wantresult = new byte[] { 1, 2, 3, 4 };

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
示例#15
0
        public void Test_AutoEntry()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract_autoentrypoint.cs");
            testengine.ScriptEntry.DumpNEF();

            var       result     = testengine.GetMethod("call01").Run();//new test method01
            StackItem wantresult = new byte[] { 1, 2, 3, 4 };

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
        public void Test_DoubleReturnA()
        {
            var testengine = new TestEngine();

            testengine.AddEntryScript("./TestClasses/Contract_Returns.cs");

            var result = testengine.GetMethod("div").RunEx(9, 5);

            Assert.AreEqual(1, result.Count);
            var array = result.Pop() as Array;

            Assert.AreEqual(1, array[0]);
            Assert.AreEqual(4, array[1]);
        }
示例#17
0
        public void Test_Appcall()
        {
            var testengine = new TestEngine();

            testengine.AddAppcallScript("./TestClasses/Contract1.cs", "0102030405060708090A0102030405060708090A");
            //will appcall 0102030405060708090A0102030405060708090A
            testengine.AddEntryScript("./TestClasses/Contract_appcall.cs");

            var       result     = testengine.GetMethod("testfunc").Run();
            StackItem wantresult = new byte[] { 1, 2, 3, 4 };

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }
        public void Test_Appcall()
        {
            var hash       = UInt160.Parse("0102030405060708090A0102030405060708090A");
            var testengine = new TestEngine();

            testengine.Snapshot.Contracts.Add(hash, new Ledger.ContractState()
            {
                Manifest = new SmartContract.Manifest.ContractManifest(),
                Script   = testengine.Build("./TestClasses/Contract1.cs").finalNEF
            });

            //will appcall 0102030405060708090A0102030405060708090A
            testengine.AddEntryScript("./TestClasses/Contract_appcall.cs");

            var       result     = testengine.GetMethod("testfunc").Run();
            StackItem wantresult = new byte[] { 1, 2, 3, 4 };

            var bequal = wantresult.Equals(result);

            Assert.IsTrue(bequal);
        }