// {
        //   "output": "0x",
        //   "stateDiff": null,
        //   "trace": [{
        //     "action": { ... },
        //     "result": {
        //       "gasUsed": "0x0",
        //       "output": "0x"
        //     },
        //     "subtraces": 0,
        //     "traceAddress": [],
        //     "type": "call"
        //   }],
        //   "vmTrace": null
        // }
        private void WriteJson(JsonWriter writer, ParityTraceAction traceAction, JsonSerializer serializer)
        {
            if (!traceAction.IncludeInTrace)
            {
                return;
            }

            writer.WriteStartObject();
            writer.WriteProperty("action", traceAction, serializer);
            if (traceAction.Error == null)
            {
                writer.WriteProperty("result", traceAction.Result, serializer);
            }
            else
            {
                writer.WriteProperty("error", traceAction.Error, serializer);
            }

            writer.WriteProperty("subtraces", traceAction.Subtraces.Count(s => s.IncludeInTrace));
            writer.WritePropertyName("traceAddress");
            _traceAddressConverter.WriteJson(writer, traceAction.TraceAddress, serializer);

            writer.WriteProperty("type", traceAction.Type);
            writer.WriteEndObject();
            foreach (ParityTraceAction subtrace in traceAction.Subtraces)
            {
                WriteJson(writer, subtrace, serializer);
            }
        }
        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);
        }
        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()
            {
                Value        = 67890,
                CallType     = "call",
                From         = TestItem.AddressC,
                To           = TestItem.AddressD,
                Input        = Array.Empty <byte>(),
                Gas          = 10000,
                TraceAddress = new int[] { 0, 0 }
            };

            ParityLikeTxTrace result = new()
            {
                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()
            {
                Balance = new ParityStateChange <UInt256?>(1, 2),
                Nonce   = new ParityStateChange <UInt256?>(0, 1),
                Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > {
                    [1] = new(new byte[] { 1 }, new byte[] { 2 })
                }
            };

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange> {
                { TestItem.AddressC, stateChange }
            };
            TestToJson(new ParityTxTraceFromReplay(result, false), expectedResult);
        }
示例#4
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);
        }
示例#6
0
        public void Can_serialize()
        {
            ParityTraceAction action = new ParityTraceAction();

            action.From         = TestItem.AddressA;
            action.Gas          = 12345;
            action.Input        = new byte[] { 6, 7, 8, 9, 0 };
            action.To           = TestItem.AddressB;
            action.Value        = 24680;
            action.CallType     = "call";
            action.TraceAddress = new int[] { 1, 3, 5, 7 };

            TestOneWaySerialization(action, "{\"callType\":\"call\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x3039\",\"input\":\"0x0607080900\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x6068\"}");
        }
        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()
            {
                Value        = 67890,
                CallType     = "call",
                From         = TestItem.AddressC,
                To           = TestItem.AddressD,
                Input        = Array.Empty <byte>(),
                Gas          = 10000,
                TraceAddress = new int[] { 0, 0 }
            };

            ParityLikeTxTrace result = new()
            {
                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()
            {
                Balance = new ParityStateChange <UInt256?>(1, 2),
                Nonce   = new ParityStateChange <UInt256?>(0, 1),
                Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > {
                    [1] = new(new byte[] { 1 }, new byte[] { 2 })
                }
            };

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange> {
                { TestItem.AddressC, stateChange }
            };
            TestToJson(new ParityTxTraceFromReplay(result, includeTransactionHash), expectedResult);
        }
 /*
  *    "action": {
  *      "callType": "call",
  *      "from": "0x430adc807210dab17ce7538aecd4040979a45137",
  *      "gas": "0x1a1f8",
  *      "input": "0x",
  *      "to": "0x9bcb0733c56b1d8f0c7c4310949e00485cae4e9d",
  *      "value": "0x2707377c7552d8000"
  *    },
  *    "blockHash": "0x3aa472d57e220458fe5b9f1587b9211de68b27504064f5f6e427c68fc1691a29",
  *    "blockNumber": 2392500,
  *    "result": {
  *      "gasUsed": "0x2162",
  *      "output": "0x"
  *    },
  *    "subtraces": 2,
  *    "traceAddress": [],
  *    "transactionHash": "0x847ed5e2e9430bc6ee925a81137ebebe0cea1352209f96723d3503eb7a707aa8",
  *    "transactionPosition": 42,
  *    "type": "call"
  */
 private void WriteJson(JsonWriter writer, ParityLikeTxTrace value, ParityTraceAction traceAction, JsonSerializer serializer)
 {
     writer.WriteStartObject();
     writer.SerializeProperty("action", traceAction, serializer);
     writer.SerializeProperty("blockHash", value.BlockHash, serializer);
     writer.SerializeProperty("blockNumber", value.BlockNumber, serializer);
     writer.SerializeProperty("result", traceAction.Result, serializer);
     writer.WriteProperty("subtraces", traceAction.Subtraces.Count);
     writer.WritePropertyName("traceAddress");
     _traceAddressConverter.WriteJson(writer, traceAction.TraceAddress, serializer);
     writer.SerializeProperty("transactionHash", value.TransactionHash, serializer);
     writer.WriteProperty("transactionPosition", value.TransactionPosition);
     writer.WriteProperty("type", traceAction.CallType);
     writer.WriteEndObject();
     foreach (ParityTraceAction subtrace in traceAction.Subtraces)
     {
         WriteJson(writer, value, subtrace, serializer);
     }
 }
示例#11
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);
        }
示例#12
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\"}}}}}}");
        }
示例#13
0
        private static void AddActionsRecursively(List <ParityTxTraceFromStore> results, ParityLikeTxTrace txTrace, ParityTraceAction txTraceAction)
        {
            ParityTxTraceFromStore result = new()
            {
                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);
            }
        }
        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);
        }
示例#15
0
        public void Can_serialize_nulls()
        {
            ParityTraceAction action = new ParityTraceAction();

            TestOneWaySerialization(action, "{\"callType\":null,\"from\":null,\"gas\":\"0x0\",\"input\":null,\"to\":null,\"value\":\"0x0\"}");
        }