Пример #1
0
        private bool CompareEntry(TransactionTraceEntry gethEntry, TransactionTraceEntry nethEntry, string entryDesc)
        {
            if (gethEntry.Op != nethEntry.Op)
            {
                _logger.Warn($"    {entryDesc} operation geth {gethEntry.Op} neth {nethEntry.Op}");
                return(false);
            }

            if (gethEntry.Depth != nethEntry.Depth)
            {
                _logger.Warn($"    {entryDesc} depth geth {gethEntry.Depth} neth {nethEntry.Depth}");
                return(false);
            }

            if (gethEntry.Gas != nethEntry.Gas)
            {
                _logger.Warn($"    {entryDesc} gas geth {gethEntry.Gas} neth {nethEntry.Gas}");
                return(false);
            }

            if (gethEntry.GasCost != nethEntry.GasCost)
            {
                _logger.Warn($"    {entryDesc} gas cost geth {gethEntry.GasCost} neth {nethEntry.GasCost}");
                return(false);
            }

            return
                (CompareLists(gethEntry.Stack, nethEntry.Stack, "stack", entryDesc) &&
                 CompareLists(gethEntry.Memory, nethEntry.Memory, "memory", entryDesc) &&
                 CompareStorage(gethEntry, nethEntry, entryDesc));
        }
Пример #2
0
        public void Trace()
        {
            IsTracingEnabled = true;
            Execute(
                (byte)Instruction.PUSH1,
                0,
                (byte)Instruction.PUSH1,
                0,
                (byte)Instruction.ADD,
                (byte)Instruction.PUSH1,
                0,
                (byte)Instruction.SSTORE);

            Assert.AreEqual(5, _trace.Entries.Count, "number of entries");
            TransactionTraceEntry entry = _trace.Entries[1];

            Assert.AreEqual(0, entry.Depth, nameof(entry.Depth));
            Assert.AreEqual(79000 - GasCostOf.VeryLow, entry.Gas, nameof(entry.Gas));
            Assert.AreEqual(GasCostOf.VeryLow, entry.GasCost, nameof(entry.GasCost));
            Assert.AreEqual(0, entry.Memory.Count, nameof(entry.Memory));
            Assert.AreEqual(1, entry.Stack.Count, nameof(entry.Stack));
            Assert.AreEqual(1, _trace.Entries[4].Storage.Count, nameof(entry.Storage));
            Assert.AreEqual(2, entry.Pc, nameof(entry.Pc));
            Assert.AreEqual("PUSH1", entry.Operation, nameof(entry.Operation));
        }
Пример #3
0
        private bool CompareStorage(TransactionTraceEntry gethEntry, TransactionTraceEntry nethEntry, string entryDesc)
        {
            foreach (KeyValuePair <string, string> keyValuePair in gethEntry.Storage)
            {
                if (!nethEntry.Storage.ContainsKey(keyValuePair.Key))
                {
                    _logger.Warn($"   {entryDesc} missing neth storage {keyValuePair.Key}");
                    return(false);
                }
            }

            foreach (KeyValuePair <string, string> keyValuePair in nethEntry.Storage)
            {
                if (!gethEntry.Storage.ContainsKey(keyValuePair.Key))
                {
                    _logger.Warn($"   {entryDesc} extra neth storage {keyValuePair.Key}");
                    return(false);
                }
            }

            foreach (KeyValuePair <string, string> keyValuePair in nethEntry.Storage)
            {
                if (nethEntry.Storage[keyValuePair.Key] != gethEntry.Storage[keyValuePair.Key])
                {
                    _logger.Warn($"   {entryDesc} different storage values at {keyValuePair.Key} geth {gethEntry.Storage[keyValuePair.Key]} neth {nethEntry.Storage[keyValuePair.Key]}");
                    return(false);
                }
            }

            return(true);
        }