예제 #1
0
        public void TrimTest()
        {
            UInt256 val256   = UInt256.Zero;
            var     snapshot = Blockchain.Singleton.GetSnapshot().CreateSnapshot();

            TestUtils.SetupHeaderWithValues(uut, val256, out _, out _, out _, out _, out _);
            uut.Witness = new Witness()
            {
                InvocationScript = new byte[0], VerificationScript = new byte[0]
            };

            UT_SmartContractHelper.BlocksAdd(snapshot, uut.Hash, new TrimmedBlock()
            {
                Timestamp     = uut.Timestamp,
                PrevHash      = uut.PrevHash,
                MerkleRoot    = uut.MerkleRoot,
                ConsensusData = new ConsensusData(),
                Hashes        = new UInt256[0],
                NextConsensus = uut.NextConsensus,
                Witness       = uut.Witness
            });

            var trim = NativeContract.Ledger.GetTrimmedBlock(snapshot, uut.Hash);

            trim.Version.Should().Be(uut.Version);
            trim.PrevHash.Should().Be(uut.PrevHash);
            trim.MerkleRoot.Should().Be(uut.MerkleRoot);
            trim.Timestamp.Should().Be(uut.Timestamp);
            trim.Index.Should().Be(uut.Index);
            trim.NextConsensus.Should().Be(uut.NextConsensus);
            trim.Witness.Should().BeEquivalentTo(uut.Witness);
            trim.Hashes.Length.Should().Be(0);
        }
예제 #2
0
        public void TrimTest()
        {
            UInt256 val256 = UInt256.Zero;
            var snapshot = TestBlockchain.GetTestSnapshot().CreateSnapshot();
            TestUtils.SetupHeaderWithValues(uut, val256, out _, out _, out _, out _, out _, out _);
            uut.Witness = new Witness() { InvocationScript = Array.Empty<byte>(), VerificationScript = Array.Empty<byte>() };

            UT_SmartContractHelper.BlocksAdd(snapshot, uut.Hash, new TrimmedBlock()
            {
                Header = new Header
                {
                    Timestamp = uut.Timestamp,
                    PrevHash = uut.PrevHash,
                    MerkleRoot = uut.MerkleRoot,
                    NextConsensus = uut.NextConsensus,
                    Witness = uut.Witness
                },
                Hashes = Array.Empty<UInt256>()
            });

            var trim = NativeContract.Ledger.GetTrimmedBlock(snapshot, uut.Hash);
            var header = trim.Header;

            header.Version.Should().Be(uut.Version);
            header.PrevHash.Should().Be(uut.PrevHash);
            header.MerkleRoot.Should().Be(uut.MerkleRoot);
            header.Timestamp.Should().Be(uut.Timestamp);
            header.Index.Should().Be(uut.Index);
            header.NextConsensus.Should().Be(uut.NextConsensus);
            header.Witness.InvocationScript.Span.SequenceEqual(uut.Witness.InvocationScript.Span).Should().BeTrue();
            header.Witness.VerificationScript.Span.SequenceEqual(uut.Witness.VerificationScript.Span).Should().BeTrue();
            trim.Hashes.Length.Should().Be(0);
        }
예제 #3
0
        public void TestGetBlock()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();
            var tx1      = TestUtils.GetTransaction(UInt160.Zero);

            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(UInt160.Zero);

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

            UT_SmartContractHelper.TransactionAdd(snapshot, state1, state2);

            TrimmedBlock tblock = GetTrimmedBlockWithNoTransaction();

            tblock.Hashes = new UInt256[] { tx1.Hash, tx2.Hash };
            UT_SmartContractHelper.BlocksAdd(snapshot, tblock.Hash, tblock);

            Block block = NativeContract.Ledger.GetBlock(snapshot, tblock.Hash);

            block.Index.Should().Be(1);
            block.MerkleRoot.Should().Be(UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff02"));
            block.Transactions.Length.Should().Be(2);
            block.Transactions[0].Hash.Should().Be(tx1.Hash);
            block.Witness.InvocationScript.ToHexString().Should().Be(tblock.Header.Witness.InvocationScript.ToHexString());
            block.Witness.VerificationScript.ToHexString().Should().Be(tblock.Header.Witness.VerificationScript.ToHexString());
        }