Skip to content
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 15 commits into from
Nov 4, 2021

Conversation

kjazgar
Copy link
Contributor

@kjazgar kjazgar commented Nov 2, 2021

Changes:

Implementation of trace_call and trace_callMany methods in TraceRpcModule.

Types of changes

What types of changes does your code introduce?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Testing

Requires testing

  • Yes
  • No

In case you checked yes, did you write tests??

  • Yes
  • No

@kjazgar kjazgar changed the title Trace call call many implementation Implementation of trace_call and trace_callMany Nov 2, 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()
Copy link
Member

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 LukaszRozmej merged commit d066c3a into master Nov 4, 2021
@LukaszRozmej LukaszRozmej deleted the trace_call_callMany_implementation branch November 4, 2021 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants