Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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);
        }
Esempio n. 4
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());
        }