예제 #1
0
        public void Test_GetHeight()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("getHeight");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(_block.Index, item.GetInteger());
        }
        public void Test_Storage()
        {
            _engine.Reset();
            _engine.ExecuteTestCaseStandard("put2", "a");
            Assert.AreEqual(VMState.HALT, _engine.State);

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("get2", "a");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(3, result.Pop());
        }
        public void Test_GetTxVMState()
        {
            _engine.Reset();
            EvaluationStack result = _engine.ExecuteTestCaseStandard("getTxVMState", UInt256.Zero.ToArray());

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);
            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual((int)VMState.NONE, item.GetInteger());

            // Hash

            var tx = _block.Transactions[0];

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("getTxVMState", tx.Hash.ToArray());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual((int)VMState.HALT, item.GetInteger());
        }
예제 #4
0
        public void Test_SHA256()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("SHA256", "asd");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(VM.Types.ByteString));
            Assert.AreEqual("688787d8ff144c502c7f5cffaafe2cc588d86079f9de88304c26b0cb99ce91c6", item.GetSpan().ToArray().ToHexString());
        }
예제 #5
0
        public void Test_SHA256()
        {
            var data = _engine.ScriptContainer.GetHashData();

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("SHA256", data);

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(ByteString));
            Assert.AreEqual("293ba9cd0c05e23da15e39d29bcb8edfa5b2eeb29163a325c3229e81feed3d11", item.GetSpan().ToArray().ToHexString());
        }
예제 #6
0
        public void Test_CreateCallDestroy()
        {
            // Create

            var script   = _engine.Build("./TestClasses/Contract_Create.cs");
            var manifest = ContractManifest.FromJson(JObject.Parse(script.finalManifest));

            // Check first

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());

            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Create

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Array));
            var itemArray = item as Array;

            Assert.AreEqual(script.finalNEF, itemArray[0]); // Script
            Assert.AreEqual(false, itemArray[1]);           // HasStorage
            Assert.AreEqual(false, itemArray[2]);           // Payable

            // Call

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(123, item.GetBigInteger());

            // Destroy

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("destroy");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Check again for failures

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray());
            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);
        }
예제 #7
0
        public void intForeach_test()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("intForeach");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(10, result.Pop().GetInteger());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("intForeachBreak", 3);

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(6, result.Pop().GetInteger());
        }
        public void AtoiTest()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("atoi", "-1", 10);

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop <VM.Types.Integer>();

            Assert.AreEqual(-1, item.GetInteger());
        }
예제 #9
0
        public void TestHexToBytes()
        {
            // 0a0b0c0d0E0F

            var result = _engine.ExecuteTestCaseStandard("testHexToBytes");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(ByteString));
            Assert.AreEqual("0a0b0c0d0e0f", (item as ByteString).GetSpan().ToHexString());
        }
        public void Test_CreateCallDestroy()
        {
            // Create

            byte[] script;
            using (var scriptBuilder = new ScriptBuilder())
            {
                // Drop arguments

                scriptBuilder.Emit(VM.OpCode.DROP);
                scriptBuilder.Emit(VM.OpCode.DROP);

                // Return 123

                scriptBuilder.EmitPush(123);
                script = scriptBuilder.ToArray();
            }

            var manifest = ContractManifest.CreateDefault(script.ToScriptHash());

            // Check first

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("Call", manifest.Hash.ToArray());

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

            // Create

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("Create", script, manifest.ToJson().ToString());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(InteropInterface <Ledger.ContractState>));
            Assert.AreEqual(manifest.Hash,
                            ((InteropInterface <Ledger.ContractState>)item).GetInterface <Ledger.ContractState>().ScriptHash);

            // Call

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("Call", manifest.Hash.ToArray(), Null.Null, Null.Null);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(ByteArray));
            Assert.AreEqual(123, item.GetBigInteger());

            // Destroy

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("Destroy");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(ByteArray));
            Assert.AreEqual(0, item.GetByteLength());

            // Check again for failures

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("Call", manifest.Hash.ToArray());
            Assert.AreEqual(VMState.FAULT, _engine.State);
        }
        public void Test_CreateCallDestroy()
        {
            // Create

            TestEngine engine = new();

            engine.AddEntryScript("./TestClasses/Contract_Create.cs");
            var manifest = ContractManifest.FromJson(engine.Manifest);
            var nef      = new NefFile()
            {
                Script = engine.Nef.Script, Compiler = "unit-test-1.0", Tokens = System.Array.Empty <MethodToken>()
            };

            nef.CheckSum = NefFile.ComputeChecksum(nef);

            var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.CheckSum, manifest.Name);

            // Create

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("create", nef.ToArray(), manifest.ToJson().ToString());

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Array));
            var itemArray = item as Array;

            Assert.AreEqual(1, itemArray[0].GetInteger());                                                                   // Id
            Assert.AreEqual(0, itemArray[1].GetInteger());                                                                   // UpdateCounter
            Assert.AreEqual(hash.ToArray(), itemArray[2]);                                                                   // Hash
            Assert.AreEqual(nef.ToJson().AsString(), itemArray[3].GetSpan().AsSerializable <NefFile>().ToJson().AsString()); // Nef
            var ritem = new ContractManifest();

            ((IInteroperable)ritem).FromStackItem(itemArray[4]);
            Assert.AreEqual(manifest.ToString(), ritem.ToString()); // Manifest

            // Call

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", hash.ToArray(), "oldContract", (byte)CallFlags.All, new Array());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(123, item.GetInteger());

            // Destroy

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("destroy", _engine.Nef);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Check again for failures

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", hash.ToArray());
            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);
        }
예제 #12
0
        public void Test_NEO()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("NEO_Decimals");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(0, item.GetInteger());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_Name");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(ByteString));
            Assert.AreEqual("NEO", item.GetString());

            _engine.Reset();
            var account = new byte[] { 0xf6, 0x64, 0x43, 0x49, 0x8d, 0x38, 0x78, 0xd3, 0x2b, 0x99, 0x4e, 0x4e, 0x12, 0x83, 0xc6, 0x93, 0x44, 0x21, 0xda, 0xfe };

            result = _engine.ExecuteTestCaseStandard("NEO_BalanceOf", account);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(0, item.GetInteger());

            // Before RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_GetCandidates");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Array));
            Assert.AreEqual(0, ((Array)item).Count);

            // RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_RegisterCandidate", pubKey);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Boolean));
            Assert.AreEqual(true, item.GetBoolean());

            // After RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_GetCandidates");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Array));
            Assert.AreEqual(1, ((Array)item).Count);
            var candidate = ((Array)item)[0];

            Assert.IsInstanceOfType(candidate, typeof(Struct));
            var candidatePubKey = ((Struct)candidate)[0];
            var candidateVotes  = ((Struct)candidate)[1];

            Assert.IsInstanceOfType(candidatePubKey, typeof(ByteString));
            Assert.AreEqual(true, candidatePubKey.Equals((ByteString)pubKey));
            Assert.IsInstanceOfType(candidateVotes, typeof(Integer));
            Assert.AreEqual(0, candidateVotes.GetInteger());
        }
 public void TestAddChecked()
 {
     _engine.Reset();
     _engine.ExecuteTestCaseStandard("addChecked", int.MaxValue, 1);
     Assert.AreEqual(VMState.FAULT, _engine.State);
 }
예제 #14
0
        public void Test_NEO()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("NEO_Decimals");

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(0, item.GetInteger());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_Name");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(VM.Types.ByteString));
            Assert.AreEqual("NEO", item.GetString());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_BalanceOf", account);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(0, item.GetInteger());

            // Before RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_GetCandidates");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Array));
            Assert.AreEqual(0, ((Array)item).Count);

            // RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_RegisterCandidate", pubKey);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Boolean));
            Assert.AreEqual(true, item.GetBoolean());

            // After RegisterCandidate
            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_GetCandidates");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Array));
            Assert.AreEqual(1, ((Array)item).Count);
            var candidate = ((Array)item)[0];

            Assert.IsInstanceOfType(candidate, typeof(Struct));
            var candidatePubKey = ((Struct)candidate)[0];
            var candidateVotes  = ((Struct)candidate)[1];

            Assert.IsInstanceOfType(candidatePubKey, typeof(VM.Types.ByteString));
            Assert.AreEqual(true, candidatePubKey.Equals((VM.Types.ByteString)pubKey));
            Assert.IsInstanceOfType(candidateVotes, typeof(Integer));
            Assert.AreEqual(0, candidateVotes.GetInteger());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_Transfer", account, account, 0);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Boolean));
            Assert.AreEqual(false, item.GetBoolean());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_UnclaimedGas", account, 0);
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(0, item.GetInteger());

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("NEO_GetGasPerBlock");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(500000000, item.GetInteger());
        }
예제 #15
0
        public void TestNextIntArray()
        {
            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("testNextIntArray", new Array(new StackItem[] { 1, 2, 3 }));

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(6, item.GetInteger());
        }
        public void Test_CreateCallDestroy()
        {
            // Create

            var script   = _engine.Build("./TestClasses/Contract_Create.cs");
            var manifest = ContractManifest.FromJson(JObject.Parse(script.finalManifest));
            var nef      = new NefFile()
            {
                Script = script.finalNEFScript, Compiler = "unit-test", Version = "1.0"
            };
            var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.Script);

            nef.CheckSum = NefFile.ComputeChecksum(nef);

            // Create

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("create", nef.ToArray(), manifest.ToJson().ToString());

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Array));
            var itemArray = item as Array;

            Assert.AreEqual(1, itemArray[0].GetInteger());                  // Id
            Assert.AreEqual(0, itemArray[1].GetInteger());                  // UpdateCounter
            Assert.AreEqual(hash.ToArray(), itemArray[2]);                  // Hash
            Assert.AreEqual(script.finalNEFScript, itemArray[3]);           // Script
            Assert.AreEqual(manifest.ToString(), itemArray[4].GetString()); // Manifest

            // Call

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", hash.ToArray(), "oldContract", new Array());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(123, item.GetInteger());

            // Destroy

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("destroy");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Check again for failures

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", hash.ToArray());
            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);
        }
예제 #17
0
        public void IsNull()
        {
            // True

            testengine.Reset();
            var result = testengine.ExecuteTestCaseStandard("isNull", StackItem.Null);
            var item   = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Boolean));
            Assert.IsTrue(item.GetBoolean());

            // False

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("isNull", new Integer(1));
            item   = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Boolean));
            Assert.IsFalse(item.GetBoolean());
        }
        public void Test_Time()
        {
            var result = _engine.ExecuteTestCaseStandard("getTime");

            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(1234, item.GetInteger());
        }
예제 #19
0
        public void Test_Time()
        {
            ((TestSnapshot)_engine.Snapshot).SetPersistingBlock(new Block()
            {
                Index         = 123,
                Timestamp     = 1234,
                ConsensusData = new ConsensusData(),
                Transactions  = new Transaction[0],
                Witness       = new Witness()
                {
                    InvocationScript   = new byte[0],
                    VerificationScript = new byte[0]
                },
                NextConsensus = UInt160.Zero,
                MerkleRoot    = UInt256.Zero,
                PrevHash      = UInt256.Zero
            });

            var result = _engine.ExecuteTestCaseStandard("GetTime");

            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(1234, item.GetBigInteger());
        }
        public void LongParse_Test()
        {
            using var testengine = new TestEngine(snapshot: new TestDataCache());
            testengine.AddEntryScript("./TestClasses/Contract_IntegerParse.cs");
            string methodname = "testLongparse";

            var result = testengine.ExecuteTestCaseStandard(methodname, " -9223372036854775808");
            var value  = result.Pop().GetInteger();

            Assert.AreEqual(-9223372036854775808, value);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "9223372036854775807");

            value = result.Pop().GetInteger();
            Assert.AreEqual(9223372036854775807, value);

            //test backspace trip
            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "20 ");

            value = result.Pop().GetInteger();
            Assert.AreEqual(20, value);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, " 20 ");

            value = result.Pop().GetInteger();
            Assert.AreEqual(20, value);


            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "-9223372036854775809");

            Assert.AreEqual(VMState.FAULT, testengine.State);
            Assert.IsNotNull(testengine.FaultException);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "9223372036854775808");

            Assert.AreEqual(VMState.FAULT, testengine.State);
            Assert.IsNotNull(testengine.FaultException);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "");

            Assert.AreEqual(VMState.FAULT, testengine.State);
            Assert.IsNotNull(testengine.FaultException);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "abc");

            Assert.AreEqual(VMState.FAULT, testengine.State);
            Assert.IsNotNull(testengine.FaultException);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard(methodname, "@");

            Assert.AreEqual(VMState.FAULT, testengine.State);
            Assert.IsNotNull(testengine.FaultException);
        }
예제 #21
0
        public void Test_CreateCallDestroy()
        {
            // Create

            var script   = _engine.Build("./TestClasses/Contract_Create.cs");
            var manifest = ContractManifest.FromJson(JObject.Parse(script.finalManifest));

            // Check first

            _engine.Reset();
            var result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());

            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Create

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            var item = result.Pop();

            Assert.IsTrue(item.Type == VM.Types.StackItemType.InteropInterface);
            var ledger = (item as InteropInterface).GetInterface <Ledger.ContractState>();

            Assert.AreEqual(manifest.Hash, ledger.ScriptHash);

            // Call

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);

            item = result.Pop();
            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(123, item.GetBigInteger());

            // Destroy

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("destroy");
            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(0, result.Count);

            // Check again for failures

            _engine.Reset();
            result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray());
            Assert.AreEqual(VMState.FAULT, _engine.State);
            Assert.AreEqual(0, result.Count);
        }
        public void UInt160_ValidateAddress()
        {
            var address = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(ProtocolSettings.Default.AddressVersion);

            using var testengine = new TestEngine();
            testengine.AddEntryScript("./TestClasses/Contract_UIntTypes.cs");

            // True

            var result = testengine.ExecuteTestCaseStandard("validateAddress", address.ToArray());

            Assert.AreEqual(1, result.Count);
            var item = result.Pop();

            Assert.IsTrue(item.GetBoolean());

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", new ByteString(address.ToArray()));
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsTrue(item.GetBoolean());

            // False

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", new byte[1] {
                1
            }.Concat(address.ToArray()).ToArray());
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", BigInteger.One);
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());

            testengine.Reset();
            testengine.ExecuteTestCaseStandard("validateAddress", StackItem.Null);
            Assert.AreEqual(VMState.FAULT, testengine.State);

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", new VM.Types.Array());
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", new Struct());
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", new Map());
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());

            testengine.Reset();
            result = testengine.ExecuteTestCaseStandard("validateAddress", StackItem.True);
            Assert.AreEqual(1, result.Count);
            item = result.Pop();
            Assert.IsFalse(item.GetBoolean());
        }
예제 #23
0
        public void Test_TryCatch_Succ()
        {
            testengine.Reset();
            var result = testengine.ExecuteTestCaseStandard("try01");

            Console.WriteLine("state=" + testengine.State + "  result on stack= " + result.Count);
            var value = result.Pop();

            Console.WriteLine("result:" + value.Type + "  " + value.ToString());
            var num = value as Neo.VM.Types.Integer;

            Console.WriteLine("result = " + num.GetInteger().ToString());
            Assert.AreEqual(num.GetInteger(), 3);
        }
예제 #24
0
        public void TestCount()
        {
            _engine.Reset();
            StackItem count  = 4;
            var       result = _engine.ExecuteTestCaseStandard("testCount", count);

            Assert.AreEqual(VMState.HALT, _engine.State);
            Assert.AreEqual(1, result.Count);
            var item = result.Pop();

            Assert.IsInstanceOfType(item, typeof(Integer));
            Assert.AreEqual(4, (item as Integer).GetInteger());
        }