public void Throws_when_recording_unexpected_trace()
        {
            Keccak txHash = TestObject.KeccakA;
            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer(txHash);

            Assert.Throws <InvalidOperationException>(() => ((IBlockTracer)blockTracer).StartNewTxTrace(TestObject.KeccakB));
        }
示例#2
0
        private GethLikeTxTrace Trace(Block block, Keccak txHash, GethTraceOptions options)
        {
            GethLikeBlockTracer listener = new GethLikeBlockTracer(txHash, options, _cancellationToken);

            _processor.Process(block, ProcessingOptions.Trace, listener);
            return(listener.BuildResult().SingleOrDefault());
        }
示例#3
0
        private GethLikeTxTrace Trace(Block block, Keccak txHash)
        {
            GethLikeBlockTracer listener = new GethLikeBlockTracer(txHash);

            _processor.Process(block, ProcessingOptions.ForceProcessing | ProcessingOptions.WithRollback | ProcessingOptions.ReadOnlyChain, listener);
            return(listener.BuildResult().SingleOrDefault());
        }
        public void Starts_with_trace_set_to_null()
        {
            Keccak txHash = TestObject.KeccakA;
            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer(txHash);

            Assert.IsNull(blockTracer.BuildResult().SingleOrDefault(), $"starts with trace set to null");
        }
示例#5
0
        private GethLikeTxTrace[] TraceBlock(Block?block, GethTraceOptions options, CancellationToken cancellationToken, Keccak?txHash = null)
        {
            if (block == null)
            {
                throw new InvalidOperationException("Only canonical, historical blocks supported");
            }

            if (!block.IsGenesis)
            {
                BlockHeader?parent = _blockTree.FindParentHeader(block.Header, BlockTreeLookupOptions.None);
                if (parent?.Hash is null)
                {
                    throw new InvalidOperationException("Cannot trace blocks with invalid parents");
                }

                if (!_blockTree.IsMainChain(parent.Hash))
                {
                    throw new InvalidOperationException("Cannot trace orphaned blocks");
                }
            }

            GethLikeBlockTracer listener = txHash == null ? new GethLikeBlockTracer(options) : new GethLikeBlockTracer(txHash, options);

            _processor.Process(block, ProcessingOptions.Trace, listener.WithCancellation(cancellationToken));
            return(listener.BuildResult().ToArray());
        }
        private void LogDiagnosticTrace(IBlockTracer blockTracer)
        {
            GethLikeBlockTracer   gethTracer   = blockTracer as GethLikeBlockTracer;
            ParityLikeBlockTracer parityTracer = blockTracer as ParityLikeBlockTracer;

            if (gethTracer != null)
            {
                var serializer = new EthereumJsonSerializer();
                var trace      = gethTracer.BuildResult();
                var serialized = serializer.Serialize(trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info(serialized);
                }
            }

            if (parityTracer != null)
            {
                var serializer = new EthereumJsonSerializer();
                var trace      = parityTracer.BuildResult();
                var serialized = serializer.Serialize(trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info(serialized);
                }
            }
        }
示例#7
0
        private void LogDiagnosticTrace(IBlockTracer blockTracer, Block block)
        {
            FileStream GetDiagnosticFile() => new FileStream($"trace_{block}.txt", FileMode.Create, FileAccess.Write);

            GethLikeBlockTracer   gethTracer   = blockTracer as GethLikeBlockTracer;
            ParityLikeBlockTracer parityTracer = blockTracer as ParityLikeBlockTracer;

            if (gethTracer != null)
            {
                using var diagnosticFile = GetDiagnosticFile();
                var serializer = new EthereumJsonSerializer();
                var trace      = gethTracer.BuildResult();
                serializer.Serialize(diagnosticFile, trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info($"Created trace of block {block} in file {diagnosticFile.Name}");
                }
            }

            if (parityTracer != null)
            {
                using var diagnosticFile = GetDiagnosticFile();
                var serializer = new EthereumJsonSerializer();
                var trace      = parityTracer.BuildResult();
                serializer.Serialize(diagnosticFile, trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info($"Created trace of block {block} in file {diagnosticFile.Name}");
                }
            }
        }
示例#8
0
        public GethLikeTxTrace Trace(long blockNumber, Transaction tx, GethTraceOptions options)
        {
            Block block = _blockTree.FindBlock(blockNumber, BlockTreeLookupOptions.RequireCanonical);

            if (block == null)
            {
                throw new InvalidOperationException("Only historical blocks");
            }
            block.Body = new BlockBody(new[] { tx }, new BlockHeader[] { });
            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer(tx.Hash, options, _cancellationToken);

            _processor.Process(block, ProcessingOptions.Trace, blockTracer);
            return(blockTracer.BuildResult().SingleOrDefault());
        }
示例#9
0
        public GethLikeTxTrace Trace(UInt256 blockNumber, Transaction tx)
        {
            Block block = _blockTree.FindBlock(blockNumber);

            if (block == null)
            {
                throw new InvalidOperationException("Only historical blocks");
            }
            block.Transactions = new[] { tx };
            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer(tx.Hash);

            _processor.Process(block, ProcessingOptions.ForceProcessing | ProcessingOptions.NoValidation | ProcessingOptions.WithRollback | ProcessingOptions.ReadOnlyChain, blockTracer);
            return(blockTracer.BuildResult().SingleOrDefault());
        }
        public void Number_of_tx_traces_equals_number_of_txs_in_a_block()
        {
            Block block = Build.A.Block.TestObject;

            block.Transactions = new Transaction[3];

            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer();

            for (int i = 0; i < block.Transactions.Length; i++)
            {
                ((IBlockTracer)blockTracer).StartNewTxTrace(TestObject.KeccakA);
                ((IBlockTracer)blockTracer).EndTxTrace();
            }

            Assert.AreEqual(3, blockTracer.BuildResult().Count);
        }
        public void Throws_when_ending_without_starting()
        {
            Block block = Build.A.Block.TestObject;

            block.Transactions    = new Transaction[3];
            block.Transactions[0] = Build.A.Transaction.TestObject;
            block.Transactions[1] = Build.A.Transaction.TestObject;
            block.Transactions[2] = Build.A.Transaction.TestObject;

            GethLikeBlockTracer blockTracer1 = new GethLikeBlockTracer();

            Assert.Throws <InvalidOperationException>(() => ((IBlockTracer)blockTracer1).EndTxTrace());

            GethLikeBlockTracer blockTracer2 = new GethLikeBlockTracer();

            ((IBlockTracer)blockTracer2).StartNewTxTrace(block.Transactions[0].Hash);
            Assert.DoesNotThrow(() => ((IBlockTracer)blockTracer2).EndTxTrace());
            Assert.Throws <InvalidOperationException>(() => ((IBlockTracer)blockTracer2).EndTxTrace());
        }
        public void Records_trace_properly()
        {
            Block block = Build.A.Block.TestObject;

            block.Transactions = new Transaction[3];

            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer();

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestObject.KeccakA);
            ((IBlockTracer)blockTracer).EndTxTrace();

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestObject.KeccakB);
            ((IBlockTracer)blockTracer).EndTxTrace();

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestObject.KeccakC);
            ((IBlockTracer)blockTracer).EndTxTrace();

            Assert.NotNull(blockTracer.BuildResult().First(), "0");
            Assert.NotNull(blockTracer.BuildResult().Skip(1).First(), "1");
            Assert.NotNull(blockTracer.BuildResult().Last(), "2");
        }
示例#13
0
        private GethLikeTxTrace[] TraceBlock(Block block, GethTraceOptions options, Keccak txHash = null)
        {
            if (block == null)
            {
                throw new InvalidOperationException("Only canonical, historical blocks supported");
            }

            if (block.Number != 0)
            {
                BlockHeader parent = _blockTree.FindParentHeader(block.Header, BlockTreeLookupOptions.None);
                if (!_blockTree.IsMainChain(parent.Hash))
                {
                    throw new InvalidOperationException("Cannot trace orphaned blocks");
                }
            }

            GethLikeBlockTracer listener = txHash == null ? new GethLikeBlockTracer(options) : new GethLikeBlockTracer(txHash, options);

            _processor.Process(block, ProcessingOptions.Trace, listener);
            return(listener.BuildResult().ToArray());
        }
示例#14
0
        private GethLikeTxTrace[] TraceBlock(Block block)
        {
            if (block == null)
            {
                throw new InvalidOperationException("Only canonical, historical blocks supported");
            }

            if (block.Number != 0)
            {
                Block parent = _blockTree.FindParent(block);
                if (!_blockTree.IsMainChain(parent.Hash))
                {
                    throw new InvalidOperationException("Cannot trace orphaned blocks");
                }
            }

            GethLikeBlockTracer listener = new GethLikeBlockTracer();

            _processor.Process(block, ProcessingOptions.ForceProcessing | ProcessingOptions.WithRollback | ProcessingOptions.ReadOnlyChain | ProcessingOptions.NoValidation, listener);
            return(listener.BuildResult().ToArray());
        }
        public void Records_trace_properly()
        {
            Block block = Build.A.Block.TestObject;

            block.Body = new BlockBody(new Transaction[3], new BlockHeader[0]);

            GethLikeBlockTracer blockTracer = new GethLikeBlockTracer(GethTraceOptions.Default);

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestItem.KeccakA);
            ((IBlockTracer)blockTracer).EndTxTrace();

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestItem.KeccakB);
            ((IBlockTracer)blockTracer).EndTxTrace();

            ((IBlockTracer)blockTracer).StartNewTxTrace(TestItem.KeccakC);
            ((IBlockTracer)blockTracer).EndTxTrace();

            Assert.NotNull(blockTracer.BuildResult().First(), "0");
            Assert.NotNull(blockTracer.BuildResult().Skip(1).First(), "1");
            Assert.NotNull(blockTracer.BuildResult().Last(), "2");
        }