Skip to content

Commit

Permalink
Merge pull request #619 from NethermindEth/618fix
Browse files Browse the repository at this point in the history
618fix
  • Loading branch information
tkstanczak authored Jul 4, 2019
2 parents 1869a17 + 6865703 commit f6eda10
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Cli/Modules/EthCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public JsValue GetTransactionReceipt(string txHash)
}

[CliFunction("eth", "getBalance")]
public JsValue GetBalance(string address, string blockParameter)
public BigInteger GetBalance(string address, string blockParameter)
{
return NodeManager.PostJint("eth_getBalance", CliParseAddress(address), blockParameter).Result;
return NodeManager.Post<BigInteger>("eth_getBalance", CliParseAddress(address), blockParameter).Result;
}

[CliProperty("eth", "protocolVersion")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,5 +766,15 @@ public void Cannot_mark_as_success_when_actions_stacked()
tracer.ReportAction(1000L, 10, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Call, false);
Assert.Throws<InvalidOperationException>(() => tracer.MarkAsSuccess(TestItem.AddressA, 21000, Bytes.Empty, new LogEntry[] {}));
}

[Test]
public void Is_tracing_rewards_only_when_rewards_trace_type_selected()
{
ParityLikeBlockTracer tracer = new ParityLikeBlockTracer(ParityTraceTypes.All ^ ParityTraceTypes.Rewards);
Assert.False(tracer.IsTracingRewards);

ParityLikeBlockTracer tracer2 = new ParityLikeBlockTracer(ParityTraceTypes.Rewards);
Assert.True(tracer2.IsTracingRewards);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public ParityLikeBlockTracer(Keccak txHash, ParityTraceTypes types)
: base(txHash)
{
_types = types;
IsTracingRewards = (types & ParityTraceTypes.Rewards) == ParityTraceTypes.Rewards;
}

public ParityLikeBlockTracer(ParityTraceTypes types)
{
_types = types;
IsTracingRewards = (types & ParityTraceTypes.Rewards) == ParityTraceTypes.Rewards;
}

protected override ParityLikeTxTracer OnStart(Keccak txHash)
Expand All @@ -50,7 +52,7 @@ protected override ParityLikeTxTrace OnEnd(ParityLikeTxTracer txTracer)
return txTracer.BuildResult();
}

public override bool IsTracingRewards => (_types & ParityTraceTypes.Trace) != ParityTraceTypes.None;
public override bool IsTracingRewards { get; }

public override void ReportReward(Address author, string rewardType, UInt256 rewardValue)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Evm/Tracing/ParityTraceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum ParityTraceTypes
VmTrace = 1,
StateDiff = 2,
Trace = 4,
All = 7,
Rewards = 8,
All = 15,
}
}
41 changes: 28 additions & 13 deletions src/Nethermind/Nethermind.JsonRpc.Test/Modules/EthModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Eth_get_balance(string blockParameter, string expectedResult)
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true), blockParameter);
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"{expectedResult}\"}}", serialized);
}

[TestCase("earliest", "0x0")]
[TestCase("latest", "0x0")]
[TestCase("pending", "0x0")]
Expand All @@ -138,7 +138,7 @@ public void Eth_get_tx_count(string blockParameter, string expectedResult)
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getTransactionCount", TestItem.AddressA.Bytes.ToHexString(true), blockParameter);
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"{expectedResult}\"}}", serialized);
}

[TestCase("earliest", "0xabcdef")]
[TestCase("latest", "0xabcdef")]
[TestCase("pending", "0xabcdef")]
Expand Down Expand Up @@ -166,21 +166,21 @@ public void Eth_get_balance_internal_error()

string serialized = RpcTest.TestSerializedRequest(module, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true), "0x01");

Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32603,\"message\":\"Incorrect head block\",\"data\":null}}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Incorrect head block\",\"data\":null}}", serialized);
}

[Test]
public void Eth_get_balance_incorrect_number_of_params()
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true));
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
}

[Test]
public void Eth_get_balance_incorrect_parameters()
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBalance", TestItem.KeccakA.Bytes.ToHexString(true), "0x01");
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters\",\"data\":null}}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters\",\"data\":null}}", serialized);
}

[Test]
Expand Down Expand Up @@ -234,7 +234,7 @@ public void Eth_tx_count_by_hash()
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockTransactionCountByHash", _blockTree.Genesis.Hash.ToString());
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"0x0\"}", serialized);
}

[Test]
public void Eth_uncle_count_by_hash()
{
Expand All @@ -251,7 +251,7 @@ public void Eth_uncle_count_by_number(string blockParameter, string expectedResu
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getUncleCountByBlockNumber", blockParameter);
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{expectedResult}}}", serialized);
}

[TestCase("earliest", "\"0x0\"")]
[TestCase("latest", "\"0x0\"")]
[TestCase("pending", "\"0x0\"")]
Expand All @@ -273,7 +273,7 @@ public void Eth_get_block_by_hash()
public void Eth_get_block_by_hash_null()
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockByHash", Keccak.Zero.ToString(), "true");
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\"}", serialized);
}

[TestCase("earliest", "{\"number\":\"0x0\",\"hash\":\"0x2167088a0f0de66028d2b728235af6d467108c1750c3e11a8f6e6cd60fddb0e4\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x00000000000003e8\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"difficulty\":\"0xf4240\",\"totalDifficulty\":\"0xf4240\",\"extraData\":\"0x010203\",\"size\":\"0x0\",\"gasLimit\":\"0x3d0900\",\"gasUsed\":\"0x0\",\"timestamp\":\"0xf4240\",\"transactions\":[],\"uncles\":[]}")]
Expand All @@ -284,7 +284,15 @@ public void Eth_get_block_by_hash_null()
public void Eth_get_block_by_number(string blockParameter, string expectedResult)
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockByNumber", blockParameter, "true");
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{expectedResult}}}", serialized);

if (expectedResult == "null")
{
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\"}}", serialized);
}
else
{
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{expectedResult}}}", serialized);
}
}

[TestCase("earliest", "{\"number\":\"0x0\",\"hash\":\"0x2167088a0f0de66028d2b728235af6d467108c1750c3e11a8f6e6cd60fddb0e4\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"nonce\":\"0x00000000000003e8\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"difficulty\":\"0xf4240\",\"totalDifficulty\":\"0xf4240\",\"extraData\":\"0x010203\",\"size\":\"0x0\",\"gasLimit\":\"0x3d0900\",\"gasUsed\":\"0x0\",\"timestamp\":\"0xf4240\",\"transactions\":[],\"uncles\":[]}")]
Expand All @@ -295,7 +303,14 @@ public void Eth_get_block_by_number(string blockParameter, string expectedResult
public void Eth_get_block_by_number_no_details(string blockParameter, string expectedResult)
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockByNumber", blockParameter, "false");
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{expectedResult}}}", serialized);
if (expectedResult == "null")
{
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\"}}", serialized);
}
else
{
Assert.AreEqual($"{{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{expectedResult}}}", serialized);
}
}

[Test]
Expand All @@ -309,14 +324,14 @@ public void Eth_get_code()
public void Eth_get_block_by_number_with_number_bad_number()
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockByNumber", "'0x1234567890123456789012345678901234567890123456789012345678901234567890'", "true");
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters\",\"data\":null}}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters\",\"data\":null}}", serialized);
}

[Test]
public void Eth_get_block_by_number_empty_param()
{
string serialized = RpcTest.TestSerializedRequest(_ethModule, "eth_getBlockByNumber", "", "true");
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
}

[Test]
Expand Down Expand Up @@ -348,7 +363,7 @@ public void Eth_get_transaction_receipt_returns_null_on_missing_receipt()

string serialized = RpcTest.TestSerializedRequest(module, "eth_getTransactionReceipt", TestItem.KeccakA.ToString());

Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\"}", serialized);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.JsonRpc/JsonRpcResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class JsonRpcResponse
[JsonProperty(PropertyName = "jsonrpc", Order = 1)]
public string JsonRpc { get; set; }

[JsonProperty(PropertyName = "result", Order = 2)]
[JsonProperty(PropertyName = "result", NullValueHandling = NullValueHandling.Ignore, Order = 2)]
public object Result { get; set; }

[JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore, Order = 3)]
Expand All @@ -43,7 +43,7 @@ public class JsonRpcResponse<T>
[JsonProperty(PropertyName = "jsonrpc", Order = 1)]
public string JsonRpc { get; set; }

[JsonProperty(PropertyName = "result", Order = 2)]
[JsonProperty(PropertyName = "result", NullValueHandling = NullValueHandling.Ignore, Order = 2)]
public T Result { get; set; }

[JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore, Order = 3)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ private void WriteJson(JsonWriter writer, ParityTraceAction traceAction, JsonSer

writer.WriteStartObject();
writer.WriteProperty("action", traceAction, serializer);
// writer.WriteProperty("blockHash", value.BlockHash, serializer);
// writer.WriteProperty("blockNumber", value.BlockNumber, serializer);
if (traceAction.Error == null)
{
writer.WriteProperty("result", traceAction.Result, serializer);
Expand All @@ -110,7 +108,6 @@ private void WriteJson(JsonWriter writer, ParityTraceAction traceAction, JsonSer
writer.WritePropertyName("traceAddress");
_traceAddressConverter.WriteJson(writer, traceAction.TraceAddress, serializer);

// writer.WriteProperty("transactionPosition", value.TransactionPosition);
writer.WriteProperty("type", traceAction.Type);
writer.WriteEndObject();
foreach (ParityTraceAction subtrace in traceAction.Subtraces) WriteJson(writer, subtrace, serializer);
Expand Down

0 comments on commit f6eda10

Please sign in to comment.