public void Can_encode_decode_sample2()
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(ParityTraceDecoder).TypeHandle);

            ParityTraceAction reward = new ParityTraceAction();

            reward.CallType     = "reward";
            reward.Author       = TestItem.AddressA;
            reward.RewardType   = "block";
            reward.Value        = 2.Ether();
            reward.TraceAddress = new int[] { };

            ParityLikeTxTrace txTrace = new ParityLikeTxTrace();

            txTrace.Action = reward;

            txTrace.BlockHash           = TestItem.KeccakB;
            txTrace.BlockNumber         = 123456;
            txTrace.TransactionHash     = null;
            txTrace.TransactionPosition = null;

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance = new ParityStateChange <UInt256>(0, 2.Ether());

            txTrace.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            txTrace.StateChanges.Add(TestItem.AddressA, stateChange);

            Rlp rlp = Rlp.Encode(txTrace);
            ParityLikeTxTrace deserialized = Rlp.Decode <ParityLikeTxTrace>(rlp);

            deserialized.Should().BeEquivalentTo(txTrace);
        }
Exemplo n.º 2
0
        public void Can_trace_raw_parity_style()
        {
            Tracer            tracer = new Tracer(_processor, NullReceiptStorage.Instance, _blockTree, new MemDb());
            ParityLikeTxTrace result = tracer.ParityTraceRawTransaction(Bytes.FromHexString("f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f"), ParityTraceTypes.Trace);

            Assert.AreEqual(1L, result.BlockNumber);
        }
Exemplo n.º 3
0
        public static ParityTxTraceFromStore[] FromTxTrace(ParityLikeTxTrace txTrace)
        {
            List <ParityTxTraceFromStore> results = new List <ParityTxTraceFromStore>();

            AddActionsRecursively(results, txTrace, txTrace.Action);
            return(results.ToArray());
        }
        public void Can_trace_call_code_calls_with_large_data_offset()
        {
            byte[] deployedCode = new byte[3];

            byte[] initCode = Prepare.EvmCode
                              .ForInitOf(deployedCode)
                              .Done;

            byte[] createCode = Prepare.EvmCode
                                .Create(initCode, 0)
                                .Op(Instruction.STOP)
                                .Done;

            TestState.CreateAccount(TestItem.AddressC, 1.Ether());
            Keccak createCodeHash = TestState.UpdateCode(createCode);

            TestState.UpdateCodeHash(TestItem.AddressC, createCodeHash, Spec);

            byte[] code = Prepare.EvmCode
                          .CallCode(TestItem.AddressC, 50000, UInt256.MaxValue, ulong.MaxValue)
                          .Op(Instruction.STOP)
                          .Done;

            ParityLikeTxTrace trace = ExecuteAndTraceParityCall(code).trace;

            trace.Action !.Error.Should().BeNullOrEmpty();
        }
Exemplo n.º 5
0
 public ParityTxTraceFromReplay(ParityLikeTxTrace txTrace, bool includeTransactionHash = false)
 {
     Output          = txTrace.Output;
     VmTrace         = txTrace.VmTrace;
     Action          = txTrace.Action;
     StateChanges    = txTrace.StateChanges;
     TransactionHash = includeTransactionHash ? txTrace.TransactionHash : null;
 }
        public void Can_serialize_creation_method()
        {
            string expectedResult = "{\"output\":null,\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":\"=\",\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}},\"trace\":[{\"action\":{\"creationMethod\":\"create2\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"init\":\"0x010203040506\",\"value\":\"0x3039\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":[1,2,3],\"type\":\"create\"},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":[0,0],\"type\":null}],\"vmTrace\":null}";

            ParityTraceAction subtrace = new ParityTraceAction
            {
                Value        = 67890,
                CallType     = "call",
                From         = TestItem.AddressC,
                To           = TestItem.AddressD,
                Input        = Array.Empty <byte>(),
                Gas          = 10000,
                TraceAddress = new int[] { 0, 0 }
            };

            ParityLikeTxTrace result = new ParityLikeTxTrace
            {
                Action = new ParityTraceAction
                {
                    Value          = 12345,
                    Type           = "create",
                    CallType       = "create",
                    CreationMethod = "create2",
                    From           = TestItem.AddressA,
                    To             = null,
                    Input          = new byte[] { 1, 2, 3, 4, 5, 6 },
                    Gas            = 40000,
                    TraceAddress   = new int[] { 0 }
                },
                BlockHash           = TestItem.KeccakB,
                BlockNumber         = 123456,
                TransactionHash     = TestItem.KeccakC,
                TransactionPosition = 5
            };

            result.Action.TraceAddress = new int[] { 1, 2, 3 };
            result.Action.Subtraces.Add(subtrace);

            ParityAccountStateChange stateChange = new ParityAccountStateChange
            {
                Balance = new ParityStateChange <UInt256?>(1, 2),
                Nonce   = new ParityStateChange <UInt256?>(0, 1),
                Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > {
                    [1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 })
                }
            };

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange> {
                { TestItem.AddressC, stateChange }
            };
            TestToJson(new ParityTxTraceFromReplay(result, false), expectedResult);
        }
Exemplo n.º 7
0
        public void Trace_replay_transaction(string types)
        {
            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value        = 67890;
            subtrace.CallType     = "call";
            subtrace.From         = TestObject.AddressC;
            subtrace.To           = TestObject.AddressD;
            subtrace.Input        = Bytes.Empty;
            subtrace.Gas          = 10000;
            subtrace.TraceAddress = new int[] { 0, 0 };

            ParityLikeTxTrace result = new ParityLikeTxTrace();

            result.Action              = new ParityTraceAction();
            result.Action.Value        = 12345;
            result.Action.CallType     = "init";
            result.Action.From         = TestObject.AddressA;
            result.Action.To           = TestObject.AddressB;
            result.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            result.Action.Gas          = 40000;
            result.Action.TraceAddress = new int[] { 0 };
            result.Action.Subtraces.Add(subtrace);

            result.BlockHash           = TestObject.KeccakB;
            result.BlockNumber         = 123456;
            result.TransactionHash     = TestObject.KeccakC;
            result.TransactionPosition = 5;
            result.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            result.StateChanges.Add(TestObject.AddressC, stateChange);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTrace(TestObject.KeccakC, Arg.Any <ParityTraceTypes>()).Returns(result);

            ITraceModule module = new TraceModule(Substitute.For <IConfigProvider>(), NullLogManager.Instance, new UnforgivingJsonSerializer(), tracer);

            JsonRpcResponse response = RpcTest.TestRequest(module, "trace_replayTransaction", TestObject.KeccakC.ToString(true), types);

            Assert.IsNull(response.Error, "error");
            Assert.NotNull(response.Result, "result");
//            Assert.False(response.Result is string s && s.Contains("\""));
        }
        public void Can_encode_decode_sample1()
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(ParityTraceDecoder).TypeHandle);

            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value          = 67890;
            subtrace.CallType       = "call";
            subtrace.From           = TestItem.AddressC;
            subtrace.To             = TestItem.AddressD;
            subtrace.Input          = Bytes.Empty;
            subtrace.Gas            = 10000;
            subtrace.TraceAddress   = new int[] { 0, 0 };
            subtrace.Result.Output  = Bytes.Empty;
            subtrace.Result.GasUsed = 15000;

            ParityLikeTxTrace txTrace = new ParityLikeTxTrace();

            txTrace.Action              = new ParityTraceAction();
            txTrace.Action.Value        = 12345;
            txTrace.Action.CallType     = "init";
            txTrace.Action.From         = TestItem.AddressA;
            txTrace.Action.To           = TestItem.AddressB;
            txTrace.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            txTrace.Action.Gas          = 40000;
            txTrace.Action.TraceAddress = new int[] { 0 };
            txTrace.Action.Subtraces.Add(subtrace);
            txTrace.Action.Result.Output  = Bytes.Empty;
            txTrace.Action.Result.GasUsed = 30000;

            txTrace.BlockHash           = TestItem.KeccakB;
            txTrace.BlockNumber         = 123456;
            txTrace.TransactionHash     = TestItem.KeccakC;
            txTrace.TransactionPosition = 5;
            txTrace.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            txTrace.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            txTrace.StateChanges.Add(TestItem.AddressC, stateChange);

            Rlp rlp = Rlp.Encode(txTrace);
            ParityLikeTxTrace deserialized = Rlp.Decode <ParityLikeTxTrace>(rlp);

            deserialized.Should().BeEquivalentTo(txTrace);
        }
Exemplo n.º 9
0
        public void Trace_replay_transaction()
        {
            ParityLikeTxTrace result = BuildParityTxTrace();

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTrace(TestItem.KeccakC, Arg.Any <ParityTraceTypes>()).Returns(result);

            ITraceModule module = new TraceModule(Substitute.For <IBlockchainBridge>(), NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(TraceModuleFactory.Converters, module, "trace_replayTransaction", TestItem.KeccakC.ToString(true), "[\"stateDiff\", \"trace\"]");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"output\":null,\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x02\"}},\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}},\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":[1,2,3],\"type\":null},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":[0,0],\"type\":null}],\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"vmTrace\":null}}", serialized);
        }
        public void Trace_replay_transaction()
        {
            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value        = 67890;
            subtrace.CallType     = "call";
            subtrace.From         = TestItem.AddressC;
            subtrace.To           = TestItem.AddressD;
            subtrace.Input        = Bytes.Empty;
            subtrace.Gas          = 10000;
            subtrace.TraceAddress = new int[] { 0, 0 };

            ParityLikeTxTrace result = new ParityLikeTxTrace();

            result.Action              = new ParityTraceAction();
            result.Action.Value        = 12345;
            result.Action.CallType     = "init";
            result.Action.From         = TestItem.AddressA;
            result.Action.To           = TestItem.AddressB;
            result.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            result.Action.Gas          = 40000;
            result.Action.TraceAddress = new int[] { 0 };
            result.Action.Subtraces.Add(subtrace);

            result.BlockHash           = TestItem.KeccakB;
            result.BlockNumber         = 123456;
            result.TransactionHash     = TestItem.KeccakC;
            result.TransactionPosition = 5;
            result.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            result.StateChanges.Add(TestItem.AddressC, stateChange);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTrace(TestItem.KeccakC, Arg.Any <ParityTraceTypes>()).Returns(result);

            ITraceModule module = new TraceModule(NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(module, "trace_replayTransaction", TestItem.KeccakC.ToString(true), "[\"stateDiff\", \"trace\"]");

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":{\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":\"[1, 2, 3]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"init\"},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":\"[0, 0]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"call\"}],\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":\"=\",\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}}}}", serialized);
        }
        protected static ParityLikeTxTrace BuildParityTxTrace()
        {
            ParityTraceAction subtrace = new ParityTraceAction
            {
                Value        = 67890,
                CallType     = "call",
                From         = TestItem.AddressC,
                To           = TestItem.AddressD,
                Input        = Array.Empty <byte>(),
                Gas          = 10000,
                TraceAddress = new int[] { 0, 0 }
            };

            ParityLikeTxTrace result = new ParityLikeTxTrace
            {
                Action = new ParityTraceAction
                {
                    Value        = 12345,
                    CallType     = "init",
                    From         = TestItem.AddressA,
                    To           = TestItem.AddressB,
                    Input        = new byte[] { 1, 2, 3, 4, 5, 6 },
                    Gas          = 40000,
                    TraceAddress = new int[] { 0 }
                },
                BlockHash           = TestItem.KeccakB,
                BlockNumber         = 123456,
                TransactionHash     = TestItem.KeccakC,
                TransactionPosition = 5
            };

            result.Action.TraceAddress = new int[] { 1, 2, 3 };
            result.Action.Subtraces.Add(subtrace);

            ParityAccountStateChange stateChange = new ParityAccountStateChange
            {
                Balance = new ParityStateChange <UInt256?>(1, 2),
                Nonce   = new ParityStateChange <UInt256?>(0, 1),
                Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > {
                    [1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 })
                },
                Code = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 })
            };

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange> {
                { TestItem.AddressC, stateChange }
            };
            return(result);
        }
        public void Can_serialize(bool includeTransactionHash, string expectedResult)
        {
            ParityTraceAction subtrace = new ParityTraceAction
            {
                Value        = 67890,
                CallType     = "call",
                From         = TestItem.AddressC,
                To           = TestItem.AddressD,
                Input        = Array.Empty <byte>(),
                Gas          = 10000,
                TraceAddress = new int[] { 0, 0 }
            };

            ParityLikeTxTrace result = new ParityLikeTxTrace
            {
                Action = new ParityTraceAction
                {
                    Value        = 12345,
                    CallType     = "init",
                    From         = TestItem.AddressA,
                    To           = TestItem.AddressB,
                    Input        = new byte[] { 1, 2, 3, 4, 5, 6 },
                    Gas          = 40000,
                    TraceAddress = new int[] { 0 }
                },
                BlockHash           = TestItem.KeccakB,
                BlockNumber         = 123456,
                TransactionHash     = TestItem.KeccakC,
                TransactionPosition = 5
            };

            result.Action.TraceAddress = new int[] { 1, 2, 3 };
            result.Action.Subtraces.Add(subtrace);

            ParityAccountStateChange stateChange = new ParityAccountStateChange
            {
                Balance = new ParityStateChange <UInt256?>(1, 2),
                Nonce   = new ParityStateChange <UInt256?>(0, 1),
                Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > {
                    [1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 })
                }
            };

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange> {
                { TestItem.AddressC, stateChange }
            };
            TestToJson(new ParityTxTraceFromReplay(result, includeTransactionHash), expectedResult);
        }
        public void Can_serialize_reward()
        {
            Block        block       = Build.A.Block.WithNumber(long.Parse("4563918244f40000".AsSpan(), NumberStyles.AllowHexSpecifier)).TestObject;
            IBlockTracer blockTracer = new ParityLikeBlockTracer(ParityTraceTypes.Trace | ParityTraceTypes.StateDiff);

            blockTracer.StartNewBlockTrace(block);
            ITxTracer txTracer = blockTracer.StartNewTxTrace(null);

            txTracer.ReportBalanceChange(TestItem.AddressA, 0, 3.Ether());
            blockTracer.EndTxTrace();
            blockTracer.ReportReward(TestItem.AddressA, "block", UInt256.One);

            ParityLikeTxTrace trace = ((ParityLikeBlockTracer)blockTracer).BuildResult().SingleOrDefault();

            TestOneWaySerialization(trace, "{\"trace\":[{\"action\":{\"callType\":\"reward\",\"from\":null,\"gas\":\"0x0\",\"input\":null,\"to\":null,\"value\":\"0x1\"},\"blockHash\":\"0xfed4f714d3626e046786ef043cbb30a4b87cdc288469d0b70e4529bbd4e15396\",\"blockNumber\":\"0x4563918244f40000\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":\"[]\",\"transactionHash\":null,\"transactionPosition\":null,\"type\":\"reward\"}],\"stateDiff\":{\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\":{\"balance\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x29a2241af62c0000\"}},\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}}}");
        }
        public void Can_serialize_reward_state_only()
        {
            Block        block       = Build.A.Block.WithNumber(long.Parse("4563918244f40000".AsSpan(), NumberStyles.AllowHexSpecifier)).TestObject;
            IBlockTracer blockTracer = new ParityLikeBlockTracer(ParityTraceTypes.StateDiff);

            blockTracer.StartNewBlockTrace(block);
            ITxTracer txTracer = blockTracer.StartNewTxTrace(null);

            txTracer.ReportBalanceChange(TestItem.AddressA, 0, 3.Ether());
            blockTracer.EndTxTrace();
            blockTracer.ReportReward(TestItem.AddressA, "block", UInt256.One);

            ParityLikeTxTrace trace = ((ParityLikeBlockTracer)blockTracer).BuildResult().SingleOrDefault();

            TestOneWaySerialization(trace, "{\"trace\":null,\"stateDiff\":{\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\":{\"balance\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x29a2241af62c0000\"}},\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}}}");
        }
        public void Can_serialize_reward()
        {
            Block        block       = Build.A.Block.WithNumber(long.Parse("4563918244f40000".AsSpan(), NumberStyles.AllowHexSpecifier)).TestObject;
            IBlockTracer blockTracer = new ParityLikeBlockTracer(ParityTraceTypes.Trace | ParityTraceTypes.StateDiff);

            blockTracer.StartNewBlockTrace(block);
            ITxTracer txTracer = blockTracer.StartNewTxTrace(null);

            txTracer.ReportBalanceChange(TestItem.AddressA, 0, 3.Ether());
            blockTracer.EndTxTrace();
            blockTracer.ReportReward(TestItem.AddressA, "block", UInt256.One);

            ParityLikeTxTrace trace = ((ParityLikeBlockTracer)blockTracer).BuildResult().SingleOrDefault();

            TestToJson(new ParityTxTraceFromReplay(trace), "{\"output\":null,\"stateDiff\":{\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\":{\"balance\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x29a2241af62c0000\"}},\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}},\"trace\":[{\"action\":{\"author\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"rewardType\":\"block\",\"value\":\"0x1\"},\"result\":null,\"subtraces\":0,\"traceAddress\":[],\"type\":\"reward\"}],\"vmTrace\":null}");
        }
Exemplo n.º 16
0
        private static ParityLikeTxTrace BuildParityTxTrace()
        {
            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value        = 67890;
            subtrace.CallType     = "call";
            subtrace.From         = TestItem.AddressC;
            subtrace.To           = TestItem.AddressD;
            subtrace.Input        = Bytes.Empty;
            subtrace.Gas          = 10000;
            subtrace.TraceAddress = new int[] { 0, 0 };

            ParityLikeTxTrace result = new ParityLikeTxTrace();

            result.Action              = new ParityTraceAction();
            result.Action.Value        = 12345;
            result.Action.CallType     = "init";
            result.Action.From         = TestItem.AddressA;
            result.Action.To           = TestItem.AddressB;
            result.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            result.Action.Gas          = 40000;
            result.Action.TraceAddress = new int[] { 0 };
            result.Action.Subtraces.Add(subtrace);

            result.BlockHash           = TestItem.KeccakB;
            result.BlockNumber         = 123456;
            result.TransactionHash     = TestItem.KeccakC;
            result.TransactionPosition = 5;
            result.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256?>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256?>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });
            stateChange.Code       = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            result.StateChanges.Add(TestItem.AddressC, stateChange);
            return(result);
        }
Exemplo n.º 17
0
        public void Can_serialize()
        {
            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value        = 67890;
            subtrace.CallType     = "call";
            subtrace.From         = TestItem.AddressC;
            subtrace.To           = TestItem.AddressD;
            subtrace.Input        = Bytes.Empty;
            subtrace.Gas          = 10000;
            subtrace.TraceAddress = new int[] { 0, 0 };

            ParityLikeTxTrace result = new ParityLikeTxTrace();

            result.Action              = new ParityTraceAction();
            result.Action.Value        = 12345;
            result.Action.CallType     = "init";
            result.Action.From         = TestItem.AddressA;
            result.Action.To           = TestItem.AddressB;
            result.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            result.Action.Gas          = 40000;
            result.Action.TraceAddress = new int[] { 0 };
            result.Action.Subtraces.Add(subtrace);

            result.BlockHash           = TestItem.KeccakB;
            result.BlockNumber         = 123456;
            result.TransactionHash     = TestItem.KeccakC;
            result.TransactionPosition = 5;
            result.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            result.StateChanges.Add(TestItem.AddressC, stateChange);

            TestOneWaySerialization(result, "{\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":40000,\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":\"[1, 2, 3]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"init\"},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":10000,\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":\"[0, 0]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"call\"}],\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":\"=\",\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}}}");
        }
Exemplo n.º 18
0
        public void Trace_raw_transaction()
        {
            ParityLikeTxTrace result1 = BuildParityTxTrace();
            ParityLikeTxTrace result2 = BuildParityTxTrace();

            Block             block            = Build.A.Block.TestObject;
            IBlockchainBridge blockchainBridge = Substitute.For <IBlockchainBridge>();

            blockchainBridge.FindEarliestBlock().Returns(block);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTraceBlock(block.Hash, Arg.Any <ParityTraceTypes>()).Returns(new[] { result1, result2 });

            ITraceModule module = new TraceModule(blockchainBridge, NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(TraceModuleFactory.Converters, module, "trace_rawTransaction", "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675", "[\"trace\"]");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
Exemplo n.º 19
0
        public void Trace_block()
        {
            ParityLikeTxTrace result1 = BuildParityTxTrace();
            ParityLikeTxTrace result2 = BuildParityTxTrace();

            Block             block            = Build.A.Block.TestObject;
            IBlockchainBridge blockchainBridge = Substitute.For <IBlockchainBridge>();

            blockchainBridge.FindEarliestBlock().Returns(block);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTraceBlock(block.Hash, Arg.Any <ParityTraceTypes>()).Returns(new[] { result1, result2 });

            ITraceModule module = new TraceModule(blockchainBridge, NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(module, "trace_block", "earliest");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":[{\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":\"[1, 2, 3]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"init\"},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":\"[0, 0]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"call\"}],\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x02\"}},\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}}},{\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":\"[1, 2, 3]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"init\"},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"blockHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"blockNumber\":\"0x1e240\",\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":\"[0, 0]\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"transactionPosition\":5,\"type\":\"call\"}],\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x02\"}},\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}}}]}", serialized);
        }
Exemplo n.º 20
0
        public ParityLikeTxTrace ReplayBlockTransactions(string blockNumber, string[] traceTypes)
        {
            ParityLikeTxTrace parityLikeTxTrace = NodeManager.Post <ParityLikeTxTrace>("trace_replayBlockTransactions", blockNumber, traceTypes).Result;

            return(parityLikeTxTrace);
        }
        public void Can_encode_decode_sample3()
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(ParityTraceDecoder).TypeHandle);

            ParityTraceAction subtrace001 = new ParityTraceAction();

            subtrace001.Value          = 67890;
            subtrace001.CallType       = "call";
            subtrace001.From           = TestItem.AddressC;
            subtrace001.To             = TestItem.AddressD;
            subtrace001.Input          = Bytes.Empty;
            subtrace001.Gas            = 10000;
            subtrace001.TraceAddress   = new int[] { 0, 0, 1 };
            subtrace001.Result.Output  = Bytes.Empty;
            subtrace001.Result.GasUsed = 15000;

            ParityTraceAction subtrace000 = new ParityTraceAction();

            subtrace000.Value          = 67890;
            subtrace000.CallType       = "create";
            subtrace000.From           = TestItem.AddressC;
            subtrace000.To             = TestItem.AddressD;
            subtrace000.Input          = Bytes.Empty;
            subtrace000.Gas            = 10000;
            subtrace000.TraceAddress   = new int[] { 0, 0, 2 };
            subtrace000.Result.Output  = Bytes.Empty;
            subtrace000.Result.GasUsed = 15000;

            ParityTraceAction subtrace00 = new ParityTraceAction();

            subtrace00.Value          = 67890;
            subtrace00.CallType       = "call";
            subtrace00.From           = TestItem.AddressC;
            subtrace00.To             = TestItem.AddressD;
            subtrace00.Input          = Bytes.Empty;
            subtrace00.Gas            = 10000;
            subtrace00.TraceAddress   = new int[] { 0, 0 };
            subtrace00.Result.Output  = Bytes.Empty;
            subtrace00.Result.GasUsed = 15000;
            subtrace00.Subtraces.Add(subtrace000);
            subtrace00.Subtraces.Add(subtrace001);

            ParityTraceAction subtrace01 = new ParityTraceAction();

            subtrace01.Value          = 67890;
            subtrace01.CallType       = "call";
            subtrace01.From           = TestItem.AddressC;
            subtrace01.To             = TestItem.AddressD;
            subtrace01.Input          = Bytes.Empty;
            subtrace01.Gas            = 10000;
            subtrace01.TraceAddress   = new int[] { 0, 1 };
            subtrace01.Result.Output  = Bytes.Empty;
            subtrace01.Result.GasUsed = 15000;

            ParityLikeTxTrace txTrace = new ParityLikeTxTrace();

            txTrace.Action              = new ParityTraceAction();
            txTrace.Action.Value        = 12345;
            txTrace.Action.CallType     = "init";
            txTrace.Action.From         = TestItem.AddressA;
            txTrace.Action.To           = TestItem.AddressB;
            txTrace.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            txTrace.Action.Gas          = 40000;
            txTrace.Action.TraceAddress = new int[] { 0 };
            txTrace.Action.Subtraces.Add(subtrace00);
            txTrace.Action.Subtraces.Add(subtrace01);
            txTrace.Action.Result.Output  = Bytes.Empty;
            txTrace.Action.Result.GasUsed = 30000;

            txTrace.BlockHash           = TestItem.KeccakB;
            txTrace.BlockNumber         = 123456;
            txTrace.TransactionHash     = TestItem.KeccakC;
            txTrace.TransactionPosition = 5;
            txTrace.Action.TraceAddress = new int[] { 1, 2, 3 };

            Rlp rlp = Rlp.Encode(txTrace);
            ParityLikeTxTrace deserialized = Rlp.Decode <ParityLikeTxTrace>(rlp);

            deserialized.Should().BeEquivalentTo(txTrace);
        }
Exemplo n.º 22
0
        public ParityLikeTxTrace ReplayTransaction(string txHash, string[] traceTypes)
        {
            ParityLikeTxTrace parityLikeTxTrace = NodeManager.Post <ParityLikeTxTrace>("trace_replayTransaction", txHash, traceTypes).Result;

            return(parityLikeTxTrace);
        }
Exemplo n.º 23
0
        private static void AddActionsRecursively(List <ParityTxTraceFromStore> results, ParityLikeTxTrace txTrace, ParityTraceAction txTraceAction)
        {
            ParityTxTraceFromStore result = new ParityTxTraceFromStore
            {
                Action              = txTraceAction,
                Result              = txTraceAction.Result,
                Subtraces           = txTraceAction.Subtraces.Count,
                Type                = txTraceAction.Type,
                BlockHash           = txTrace.BlockHash,
                BlockNumber         = txTrace.BlockNumber,
                TransactionHash     = txTrace.TransactionHash,
                TransactionPosition = txTrace.TransactionPosition,
                TraceAddress        = txTraceAction.TraceAddress
            };

            results.Add(result);

            foreach (ParityTraceAction subtrace in txTraceAction.Subtraces)
            {
                AddActionsRecursively(results, txTrace, subtrace);
            }
        }