コード例 #1
0
        public void TestVerifyWitnesses()
        {
            var     mockSnapshot1 = new Mock <Snapshot>();
            UInt256 index1        = UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01");
            TestDataCache <UInt256, TrimmedBlock> testDataCache1 = new TestDataCache <UInt256, TrimmedBlock>();

            testDataCache1.Add(index1, new TrimmedBlock());
            testDataCache1.Delete(index1);
            mockSnapshot1.SetupGet(p => p.Blocks).Returns(testDataCache1);
            Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(new Header()
            {
                PrevHash = index1
            }, mockSnapshot1.Object, 100));

            var          mockSnapshot2 = new Mock <Snapshot>();
            UInt256      index2        = UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01");
            TrimmedBlock block2        = new TrimmedBlock();

            block2.NextConsensus = UInt160.Zero;
            TestDataCache <UInt256, TrimmedBlock> testDataCache21 = new TestDataCache <UInt256, TrimmedBlock>();

            testDataCache21.Add(index2, block2);
            Header header2 = new Header()
            {
                PrevHash = index2, Witness = new Witness {
                    VerificationScript = new byte[0]
                }
            };

            mockSnapshot2.SetupGet(p => p.Blocks).Returns(testDataCache21);

            TestDataCache <UInt160, ContractState> testDataCache22 = new TestDataCache <UInt160, ContractState>();

            testDataCache22.Add(UInt160.Zero, new ContractState());
            testDataCache22.Delete(UInt160.Zero);
            mockSnapshot2.SetupGet(p => p.Contracts).Returns(testDataCache22);
            Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(header2, mockSnapshot2.Object, 100));

            var          mockSnapshot3 = new Mock <Snapshot>();
            UInt256      index3        = UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01");
            TrimmedBlock block3        = new TrimmedBlock();

            block3.NextConsensus = UInt160.Zero;
            TestDataCache <UInt256, TrimmedBlock> testDataCache31 = new TestDataCache <UInt256, TrimmedBlock>();

            testDataCache31.Add(index3, block3);
            Header header3 = new Header()
            {
                PrevHash = index3, Witness = new Witness {
                    VerificationScript = new byte[0]
                }
            };

            mockSnapshot3.SetupGet(p => p.Blocks).Returns(testDataCache31);
            TestDataCache <UInt160, ContractState> testDataCache32 = new TestDataCache <UInt160, ContractState>();

            testDataCache32.Add(UInt160.Zero, new ContractState());
            mockSnapshot3.SetupGet(p => p.Contracts).Returns(testDataCache32);
            Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(header3, mockSnapshot3.Object, 100));
        }
コード例 #2
0
        public void TestTotalSupply()
        {
            var         mockSnapshot = new Mock <Snapshot>();
            var         myDataCache  = new TestDataCache <StorageKey, StorageItem>();
            StorageItem item         = new StorageItem
            {
                Value = new byte[] { 0x01 }
            };
            var key = CreateStorageKey(Prefix_TotalSupply);

            var ServiceHash = "test".ToInteropMethodHash();

            byte[] script = null;
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall(ServiceHash);
                script = sb.ToArray();
            }
            var Hash = script.ToScriptHash();

            key.ScriptHash = Hash;

            myDataCache.Add(key, item);
            mockSnapshot.SetupGet(p => p.Storages).Returns(myDataCache);
            TestNep5Token     test      = new TestNep5Token();
            ApplicationEngine ae        = new ApplicationEngine(TriggerType.Application, null, mockSnapshot.Object, 0);
            StackItem         stackItem = test.TotalSupply(ae, null);

            stackItem.GetBigInteger().Should().Be(1);
        }
コード例 #3
0
        public void Init()
        {
            var _        = TestBlockchain.TheNeoSystem;
            var snapshot = new TestDataCache(null);

            _engine = new TestEngine(TriggerType.Application, snapshot: snapshot);
            Assert.IsTrue(_engine.AddEntryScript("./TestClasses/Contract_StdLib.cs").Success);
            scriptHash = _engine.Nef.Script.ToScriptHash();

            snapshot.ContractAdd(new ContractState()
            {
                Hash     = scriptHash,
                Nef      = _engine.Nef,
                Manifest = ContractManifest.FromJson(_engine.Manifest)
            });
        }
コード例 #4
0
        public void Init()
        {
            var _        = TestBlockchain.TheNeoSystem;
            var snapshot = new TestDataCache(null);

            _engine = new TestEngine(TriggerType.Application, snapshot: snapshot);
            _engine.AddEntryScript("./TestClasses/Contract_StdLib.cs");
            scriptHash = _engine.ScriptEntry.finalNEFScript.ToScriptHash();

            snapshot.ContractAdd(new ContractState()
            {
                Hash     = scriptHash,
                Nef      = _engine.ScriptEntry.nefFile,
                Manifest = ContractManifest.Parse(_engine.ScriptEntry.finalManifest)
            });
        }
コード例 #5
0
        public void Init()
        {
            var snapshot = new TestDataCache();
            var hash     = UInt160.Parse("0102030405060708090A0102030405060708090A");

            _engine = new TestEngine(snapshot: snapshot);
            _engine.AddEntryScript("./TestClasses/Contract1.cs");
            snapshot.ContractAdd(new ContractState()
            {
                Hash     = hash,
                Nef      = _engine.Nef,
                Manifest = ContractManifest.FromJson(_engine.Manifest),
            });

            // will ContractCall 0102030405060708090A0102030405060708090A
            _engine.AddEntryScript("./TestClasses/Contract_ContractCall.cs");
        }
コード例 #6
0
        public void TestCreateDummyBlock()
        {
            var          mockSnapshot     = new Mock <Snapshot>();
            UInt256      currentBlockHash = UInt256.Parse("0x0000000000000000000000000000000000000000000000000000000000000000");
            TrimmedBlock block            = new TrimmedBlock();
            var          cache            = new TestDataCache <UInt256, TrimmedBlock>();

            cache.Add(currentBlockHash, block);
            mockSnapshot.SetupGet(p => p.Blocks).Returns(cache);
            TestMetaDataCache <HashIndexState> testCache = new TestMetaDataCache <HashIndexState>();

            mockSnapshot.SetupGet(p => p.BlockHashIndex).Returns(testCache);
            byte[] SyscallSystemRuntimeCheckWitnessHash = new byte[] { 0x68, 0xf8, 0x27, 0xec, 0x8c };
            ApplicationEngine.Run(SyscallSystemRuntimeCheckWitnessHash, mockSnapshot.Object);
            mockSnapshot.Object.PersistingBlock.Version.Should().Be(0);
            mockSnapshot.Object.PersistingBlock.PrevHash.Should().Be(currentBlockHash);
            mockSnapshot.Object.PersistingBlock.MerkleRoot.Should().Be(new UInt256());
        }
コード例 #7
0
        public void NullCollationAndCollation()
        {
            var snapshot    = new TestDataCache();
            var _testengine = new TestEngine(snapshot: snapshot);

            _testengine.AddEntryScript("./TestClasses/Contract_NULL.cs");
            snapshot.ContractAdd(new ContractState()
            {
                Hash     = testengine.EntryScriptHash,
                Nef      = testengine.Nef,
                Manifest = new ContractManifest()
            });

            var result = _testengine.ExecuteTestCaseStandard("nullCollationAndCollation", "nes");
            var item   = result.Pop() as ByteString;

            Assert.AreEqual(123, item.GetSpan()[0]);
        }
コード例 #8
0
        public void NullCollationAndCollation2()
        {
            var snapshot    = new TestDataCache();
            var _testengine = new TestEngine(snapshot: snapshot);

            _testengine.AddEntryScript("./TestClasses/Contract_NULL.cs");
            snapshot.ContractAdd(new ContractState()
            {
                Hash     = testengine.EntryScriptHash,
                Nef      = testengine.Nef,
                Manifest = new ContractManifest()
            });

            var result = _testengine.ExecuteTestCaseStandard("nullCollationAndCollation2", "nes");
            var item   = result.Pop() as ByteString;
            var bts    = System.Text.Encoding.ASCII.GetBytes("111");
            var num    = new System.Numerics.BigInteger(bts);

            Assert.AreEqual(num, item.GetInteger());
        }
コード例 #9
0
        public void TestGetBlock()
        {
            var cache = new TestDataCache <UInt256, TransactionState>();
            var tx1   = TestUtils.GetTransaction();

            tx1.Script = new byte[] { 0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x01 };
            var state1 = new TransactionState
            {
                Transaction = tx1,
                BlockIndex  = 1
            };
            var tx2 = TestUtils.GetTransaction();

            tx2.Script = new byte[] { 0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x01,
                                      0x01, 0x01, 0x01, 0x02 };
            var state2 = new TransactionState
            {
                Transaction = tx2,
                BlockIndex  = 1
            };

            cache.Add(tx1.Hash, state1);
            cache.Add(tx2.Hash, state2);

            TrimmedBlock tblock = GetTrimmedBlockWithNoTransaction();

            tblock.Hashes = new UInt256[] { tx1.Hash, tx2.Hash };
            Block block = tblock.GetBlock(cache);

            block.Index.Should().Be(1);
            block.MerkleRoot.Should().Be(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02"));
            block.Transactions.Length.Should().Be(1);
            block.Transactions[0].Hash.Should().Be(tx2.Hash);
        }
コード例 #10
0
 public void Test_Init()
 {
     snapshot     = new TestDataCache();
     genesisBlock = new NeoSystem(ProtocolSettings.Default).GenesisBlock;
 }
コード例 #11
0
 public void Init()
 {
     snapshot   = new TestDataCache();
     testengine = new TestEngine(snapshot: snapshot);
     testengine.AddEntryScript("./TestClasses/Contract_Delegate.cs");
 }