Skip to content

Commit

Permalink
WIP: trace_calloverride tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexb5dh committed Aug 26, 2024
1 parent 9a7094d commit 6cb949c
Showing 1 changed file with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
using Nethermind.Specs;
using Nethermind.Core.Test.Builders;
using Nethermind.Int256;
using Nethermind.JsonRpc.Modules.Eth;
using Nethermind.JsonRpc.Modules.Trace;
using Nethermind.Logging;
using NUnit.Framework;
using Nethermind.Blockchain.Find;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Tracing;
using Nethermind.Consensus.Validators;
using Nethermind.Core.Crypto;
using Nethermind.Db;
using Nethermind.Evm;
using Nethermind.Evm.Tracing.ParityStyle;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Facade.Eth;
using Nethermind.Serialization.Json;
Expand Down Expand Up @@ -699,7 +695,6 @@ public async Task Trace_call_simple_tx_test()
}

[TestCase("{\"from\":\"0x7f554713be84160fdf0178cc8df86f5aabd33397\",\"to\":\"0xbe5c953dd0ddb0ce033a98f36c981f1b74d3b33f\",\"value\":\"0x0\",\"gasPrice\":\"0x119e04a40a\"}", "[\"trace\"]", "{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"0x\",\"stateDiff\":null,\"trace\":[{\"action\":{\"callType\":\"call\",\"from\":\"0x7f554713be84160fdf0178cc8df86f5aabd33397\",\"gas\":\"0x5f58ef8\",\"input\":\"0x\",\"to\":\"0xbe5c953dd0ddb0ce033a98f36c981f1b74d3b33f\",\"value\":\"0x0\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[],\"type\":\"call\"}],\"vmTrace\":null},\"id\":67}")]
[TestCase("{\"from\":\"0xc71acc7863f3bc7347b24c3b835643bd89d4d161\",\"to\":\"0xa760e26aa76747020171fcf8bda108dfde8eb930\",\"value\":\"0x0\",\"gasPrice\":\"0x2108eea5bc\"}", "[\"trace\"]", "{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"0x\",\"stateDiff\":null,\"trace\":[{\"action\":{\"callType\":\"call\",\"from\":\"0xc71acc7863f3bc7347b24c3b835643bd89d4d161\",\"gas\":\"0x5f58ef8\",\"input\":\"0x\",\"to\":\"0xa760e26aa76747020171fcf8bda108dfde8eb930\",\"value\":\"0x0\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[],\"type\":\"call\"}],\"vmTrace\":null},\"id\":67}")]
public async Task Trace_call_without_blockParameter_test(string transaction, string traceTypes, string expectedResult)
{
Context context = new();
Expand Down Expand Up @@ -855,4 +850,43 @@ public async Task Trace_replayBlockTransactions_stateDiff()
state[TestItem.AddressA].Balance!.After.Should().Be(accountA.Balance - 21000 * tx.GasPrice - tx.Value);
state[TestItem.AddressF].Balance!.After.Should().Be(accountF.Balance + tx.Value);
}

[TestCase(
"Nonce increments from state override",
"{\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0xbe5c953dd0ddb0ce033a98f36c981f1b74d3b33f\",\"value\":\"0x1\"}",
"stateDiff",
"{\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\":{\"nonce\":\"0x123\"}}",
"TODO"
)]
[TestCase(
"Uses balance from state override",
"{\"from\":\"0x7f554713be84160fdf0178cc8df86f5aabd33397\",\"to\":\"0xbe5c953dd0ddb0ce033a98f36c981f1b74d3b33f\",\"value\":\"0x100\"}",
"stateDiff",
"{\"0x7f554713be84160fdf0178cc8df86f5aabd33397\":{\"balance\":\"0x100\"}}",
"{\"jsonrpc\":\"2.0\",\"result\":{\"output\":null,\"stateDiff\":{\"0x7f554713be84160fdf0178cc8df86f5aabd33397\":{\"balance\":{\"*\":{\"from\":\"0x100\",\"to\":\"0x0\"}},\"code\":\"=\",\"nonce\":{\"\\u002B\":\"0x1\"},\"storage\":{}},\"0xbe5c953dd0ddb0ce033a98f36c981f1b74d3b33f\":{\"balance\":{\"\\u002B\":\"0x100\"},\"code\":\"=\",\"nonce\":{\"\\u002B\":\"0x0\"},\"storage\":{}}},\"trace\":[],\"vmTrace\":null},\"id\":67}"
)]
[TestCase(
"Executes code from state override",
"{\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0xc200000000000000000000000000000000000000\",\"input\":\"0xf8b2cb4f000000000000000000000000b7705ae4c6f81b66cdb323c65f4e8133690fc099\"}",
"trace",
"{\"0xc200000000000000000000000000000000000000\":{\"code\":\"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063f8b2cb4f14610030575b600080fd5b61004a600480360381019061004591906100e4565b610060565b604051610057919061012a565b60405180910390f35b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100b182610086565b9050919050565b6100c1816100a6565b81146100cc57600080fd5b50565b6000813590506100de816100b8565b92915050565b6000602082840312156100fa576100f9610081565b5b6000610108848285016100cf565b91505092915050565b6000819050919050565b61012481610111565b82525050565b600060208201905061013f600083018461011b565b9291505056fea2646970667358221220172c443a163d8a43e018c339d1b749c312c94b6de22835953d960985daf228c764736f6c63430008120033\"}}",
"{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"0x00000000000000000000000000000000000000000000003635c9adc5de9f09e5\",\"stateDiff\":null,\"trace\":[{\"action\":{\"callType\":\"call\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x5f58d48\",\"input\":\"0xf8b2cb4f000000000000000000000000b7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0xc200000000000000000000000000000000000000\",\"value\":\"0x0\"},\"result\":{\"gasUsed\":\"0x2df\",\"output\":\"0x00000000000000000000000000000000000000000000003635c9adc5de9f09e5\"},\"subtraces\":0,\"traceAddress\":[],\"type\":\"call\"}],\"vmTrace\":null},\"id\":67}"
)]
[TestCase(
"Executes precompile using new address from state override",
"{\"from\":\"0x7f554713be84160fdf0178cc8df86f5aabd33397\",\"to\":\"0x0000000000000000000000000000000000123456\",\"input\":\"0xB6E16D27AC5AB427A7F68900AC5559CE272DC6C37C82B3E052246C82244C50E4000000000000000000000000000000000000000000000000000000000000001C7B8B1991EB44757BC688016D27940DF8FB971D7C87F77A6BC4E938E3202C44037E9267B0AEAA82FA765361918F2D8ABD9CDD86E64AA6F2B81D3C4E0B69A7B055\"}",
"trace",
"{\"0x0000000000000000000000000000000000000001\":{\"movePrecompileToAddress\":\"0x0000000000000000000000000000000000123456\", \"code\": \"0x\"}}",
"{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"0x000000000000000000000000b7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"stateDiff\":null,\"trace\":[{\"action\":{\"callType\":\"call\",\"from\":\"0x7f554713be84160fdf0178cc8df86f5aabd33397\",\"gas\":\"0x5f58878\",\"input\":\"0xb6e16d27ac5ab427a7f68900ac5559ce272dc6c37c82b3e052246c82244c50e4000000000000000000000000000000000000000000000000000000000000001c7b8b1991eb44757bc688016d27940df8fb971d7c87f77a6bc4e938e3202c44037e9267b0aeaa82fa765361918f2d8abd9cdd86e64aa6f2b81d3c4e0b69a7b055\",\"to\":\"0x0000000000000000000000000000000000123456\",\"value\":\"0x0\"},\"result\":{\"gasUsed\":\"0xbb8\",\"output\":\"0x000000000000000000000000b7705ae4c6f81b66cdb323c65f4e8133690fc099\"},\"subtraces\":0,\"traceAddress\":[],\"type\":\"call\"}],\"vmTrace\":null},\"id\":67}"
)]
public async Task Trace_call_with_state_override(string name, string transaction, string traceType, string stateOverride, string expectedResult)
{
Context context = new();
await context.Build();
string serialized = await RpcTest.TestSerializedRequest(
context.TraceRpcModule,
"trace_call", transaction, new[] { traceType }, null, stateOverride);

Assert.That(serialized, Is.EqualTo(expectedResult), serialized.Replace("\"", "\\\""));
}
}

0 comments on commit 6cb949c

Please sign in to comment.