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_1_to_null() { ParityAccountStateChange result = new ParityAccountStateChange(); result.Balance = new ParityStateChange <UInt256?>(1, null); TestToJson(result, "{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":null}},\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}"); }
public void Can_serialize_null_to_1_change() { ParityAccountStateChange result = new ParityAccountStateChange(); result.Balance = new ParityStateChange <UInt256?>(null, 1); TestToJson(result, "{\"balance\":{\"+\":\"0x1\"},\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}"); }
public void Can_serialize() { ParityAccountStateChange result = new ParityAccountStateChange(); result.Balance = new ParityStateChange <UInt256?>(1, 2); result.Nonce = new ParityStateChange <UInt256?>(0, 1); result.Storage = new Dictionary <UInt256, ParityStateChange <byte[]> >(); result.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 }); TestOneWaySerialization(result, "{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":\"=\",\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}"); }
public void Does_not_throw_on_change_when_code_before_is_null() { JsonWriter writer = Substitute.For <JsonWriter>(); JsonSerializer serializer = Substitute.For <JsonSerializer>(); ParityAccountStateChange change = new ParityAccountStateChange { Code = new ParityStateChange <byte[]>(null, new byte[] { 1 }) }; Assert.DoesNotThrow(() => converter.WriteJson(writer, change, serializer)); }
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); }
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); }
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 Does_not_throw_on_change_storage() { JsonWriter writer = Substitute.For <JsonWriter>(); JsonSerializer serializer = Substitute.For <JsonSerializer>(); ParityAccountStateChange change = new ParityAccountStateChange { Storage = new Dictionary <UInt256, ParityStateChange <byte[]> > { { 1, new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 0 }) } } }; Assert.DoesNotThrow(() => converter.WriteJson(writer, change, serializer)); }
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); }
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); }
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\"}}}}}}"); }
public void Can_serialize_nulls() { ParityAccountStateChange result = new ParityAccountStateChange(); TestOneWaySerialization(result, "{\"balance\":\"=\",\"code\":\"=\",\"nonce\":\"=\",\"storage\":{}}"); }