-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of trace_call and trace_callMany #3571
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kjazgar
changed the title
Trace call call many implementation
Implementation of trace_call and trace_callMany
Nov 2, 2021
MarekM25
reviewed
Nov 2, 2021
MarekM25
reviewed
Nov 2, 2021
LukaszRozmej
requested changes
Nov 3, 2021
...rmind/Nethermind.Blockchain/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Evm/TransactionProcessing/BuildUpTransactionProcessorAdapter.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Trace/ITraceRpcModule.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceRpcModule.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceRpcModule.cs
Outdated
Show resolved
Hide resolved
LukaszRozmej
reviewed
Nov 4, 2021
Comment on lines
538
to
610
public async Task trace_call_test() | ||
{ | ||
Context context = new(); | ||
await context.Build(); | ||
TestRpcBlockchain blockchain = context.Blockchain; | ||
UInt256 currentNonceAddressA = blockchain.State.GetAccount(TestItem.AddressA).Nonce; | ||
UInt256 currentNonceAddressB = blockchain.State.GetAccount(TestItem.AddressB).Nonce; | ||
await blockchain.AddFunds(TestItem.AddressA, 10000.Ether()); | ||
|
||
Address? contractAddress = ContractAddress.From(TestItem.AddressA, currentNonceAddressA); | ||
byte[] code = Prepare.EvmCode | ||
.Call(contractAddress, 50000) | ||
.Call(contractAddress, 50000) | ||
.Op(Instruction.STOP) | ||
.Done; | ||
|
||
Transaction transaction = Build.A.Transaction.WithNonce(currentNonceAddressB++) | ||
.WithData(code).SignedAndResolved(TestItem.PrivateKeyB) | ||
.WithTo(TestItem.AddressC) | ||
.WithGasLimit(93548).TestObject; | ||
await blockchain.AddBlock(transaction); | ||
|
||
|
||
Transaction transaction2 = Build.A.Transaction.WithNonce(currentNonceAddressB++) | ||
.WithData(code).SignedAndResolved(TestItem.PrivateKeyB) | ||
.WithTo(TestItem.AddressC) | ||
.WithGasLimit(93548).TestObject; | ||
await blockchain.AddBlock(transaction2); | ||
|
||
TransactionForRpc transactionRpc = new(transaction2); | ||
|
||
string[] traceTypes = {"trace"}; | ||
|
||
ResultWrapper<ParityTxTraceFromReplay> traces = context.TraceRpcModule.trace_call(transactionRpc, traceTypes,null); | ||
Assert.AreEqual("call", traces.Data.Action.CallType); | ||
Assert.AreEqual(TestItem.AddressB, traces.Data.Action.From); | ||
Assert.AreEqual(TestItem.AddressC, traces.Data.Action.To); | ||
} | ||
|
||
public async Task trace_call_test2() | ||
{ | ||
Context context = new(); | ||
await context.Build(); | ||
|
||
TestRpcBlockchain blockchain = context.Blockchain; | ||
UInt256 currentNonceAddressA = blockchain.State.GetAccount(TestItem.AddressA).Nonce; | ||
Transaction transaction = Build.A.Transaction.WithNonce(currentNonceAddressA++).WithTo(TestItem.AddressC) | ||
.SignedAndResolved(TestItem.PrivateKeyA).TestObject; | ||
await blockchain.AddBlock(transaction); | ||
TransactionForRpc txForRpc = new(transaction); | ||
string[] traceTypes = {"Trace"}; | ||
|
||
ResultWrapper<ParityTxTraceFromReplay> tr = context.TraceRpcModule.trace_call(txForRpc, traceTypes, new BlockParameter(16)); | ||
Assert.AreEqual(TestItem.AddressC, tr.Data.Action.To); | ||
Assert.AreEqual("call", tr.Data.Action.Type.ToString()); | ||
} | ||
|
||
[TestCase("{\"from\":\"0xaaaaaaaa8583de65cc752fe3fad5098643244d22\",\"to\":\"0xd6a8d04cb9846759416457e2c593c99390092df6\"}", "[\"trace\"]","{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"0x\",\"stateDiff\":null,\"trace\":[{\"action\":{\"callType\":\"call\",\"from\":\"0xaaaaaaaa8583de65cc752fe3fad5098643244d22\",\"gas\":\"0x5f58ef8\",\"input\":\"0x\",\"to\":\"0xd6a8d04cb9846759416457e2c593c99390092df6\",\"value\":\"0x0\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[],\"type\":\"call\"}],\"vmTrace\":null},\"id\":67}")] | ||
[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 request1, string request2, string expectedResult) | ||
{ | ||
Context context = new(); | ||
await context.Build(); | ||
string serialized = RpcTest.TestSerializedRequest( | ||
EthModuleFactory.Converters.Union(TraceModuleFactory.Converters).ToList(), context.TraceRpcModule, | ||
"trace_call", request1, request2); | ||
|
||
Assert.AreEqual(expectedResult, serialized, serialized.Replace("\"", "\\\"")); | ||
} | ||
|
||
[Test] | ||
public async Task trace_callMany_test() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more descriptive names to those tests
LukaszRozmej
approved these changes
Nov 4, 2021
MarekM25
approved these changes
Nov 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes:
Implementation of trace_call and trace_callMany methods in TraceRpcModule.
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
In case you checked yes, did you write tests??