예제 #1
0
        public void Get_trace()
        {
            GethTxTraceEntry entry = new GethTxTraceEntry();

            entry.Storage = new Dictionary <string, string>
            {
                { "1".PadLeft(64, '0'), "2".PadLeft(64, '0') },
                { "3".PadLeft(64, '0'), "4".PadLeft(64, '0') },
            };

            entry.Memory = new List <string>
            {
                "5".PadLeft(64, '0'),
                "6".PadLeft(64, '0')
            };

            entry.Stack = new List <string>
            {
                "7".PadLeft(64, '0'),
                "8".PadLeft(64, '0')
            };

            entry.Operation = "STOP";
            entry.Gas       = 22000;
            entry.GasCost   = 1;
            entry.Depth     = 1;

            var trace = new GethLikeTxTrace();

            trace.ReturnValue = Bytes.FromHexString("a2");
            trace.Entries.Add(entry);

            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();

            debugBridge.GetTransactionTrace(Arg.Any <Keccak>(), Arg.Any <GethTraceOptions>()).Returns(trace);

            DebugModule module   = new DebugModule(NullLogManager.Instance, debugBridge);
            string      response = RpcTest.TestSerializedRequest <IDebugModule>(DebugModuleFactory.Converters, module, "debug_traceTransaction", TestItem.KeccakA.ToString(true), "{}");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"gas\":\"0x0\",\"failed\":false,\"returnValue\":\"0xa2\",\"structLogs\":[{\"pc\":0,\"op\":\"STOP\",\"gas\":22000,\"gasCost\":1,\"depth\":1,\"error\":null,\"stack\":[\"0000000000000000000000000000000000000000000000000000000000000007\",\"0000000000000000000000000000000000000000000000000000000000000008\"],\"memory\":[\"0000000000000000000000000000000000000000000000000000000000000005\",\"0000000000000000000000000000000000000000000000000000000000000006\"],\"storage\":{\"0000000000000000000000000000000000000000000000000000000000000001\":\"0000000000000000000000000000000000000000000000000000000000000002\",\"0000000000000000000000000000000000000000000000000000000000000003\":\"0000000000000000000000000000000000000000000000000000000000000004\"}}]}}", response);
        }
예제 #2
0
        public void Trace()
        {
            var trace = ExecuteAndTrace(
                (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");
            GethTxTraceEntry entry = trace.Entries[1];

            Assert.AreEqual(1, 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));
        }