diff --git a/test/e2e/debug_calltracer_test.go b/test/e2e/debug_calltracer_test.go index 26ad06c2e1..b8da5da9de 100644 --- a/test/e2e/debug_calltracer_test.go +++ b/test/e2e/debug_calltracer_test.go @@ -21,6 +21,10 @@ import ( "github.com/stretchr/testify/require" ) +const ( + dockersArePreLaunchedForCallTracerTests = false +) + func TestDebugTraceTransactionCallTracer(t *testing.T) { if testing.Short() { t.Skip() @@ -30,23 +34,27 @@ func TestDebugTraceTransactionCallTracer(t *testing.T) { const l2ExplorerRPCComponentName = "l2-explorer-json-rpc" var err error - err = operations.Teardown() - require.NoError(t, err) - - defer func() { - require.NoError(t, operations.Teardown()) - require.NoError(t, operations.StopComponent(l2ExplorerRPCComponentName)) - }() + if !dockersArePreLaunchedForCallTracerTests { + err = operations.Teardown() + require.NoError(t, err) + defer func() { + require.NoError(t, operations.Teardown()) + require.NoError(t, operations.StopComponent(l2ExplorerRPCComponentName)) + }() + } ctx := context.Background() opsCfg := operations.GetDefaultOperationsConfig() - opsMan, err := operations.NewManager(ctx, opsCfg) - require.NoError(t, err) - err = opsMan.Setup() - require.NoError(t, err) - - err = operations.StartComponent(l2ExplorerRPCComponentName, func() (bool, error) { return operations.NodeUpCondition(l2NetworkURL) }) - require.NoError(t, err) + if !dockersArePreLaunchedForCallTracerTests { + opsMan, err := operations.NewManager(ctx, opsCfg) + require.NoError(t, err) + err = opsMan.Setup() + require.NoError(t, err) + err = operations.StartComponent(l2ExplorerRPCComponentName, func() (bool, error) { return operations.NodeUpCondition(l2NetworkURL) }) + require.NoError(t, err) + } else { + log.Info("Using pre-launched dockers: no reset Database") + } const l1NetworkName, l2NetworkName = "Local L1", "Local L2" @@ -277,23 +285,27 @@ func TestDebugTraceBlockCallTracer(t *testing.T) { const l2ExplorerRPCComponentName = "l2-explorer-json-rpc" var err error - err = operations.Teardown() - require.NoError(t, err) - - defer func() { - require.NoError(t, operations.Teardown()) - require.NoError(t, operations.StopComponent(l2ExplorerRPCComponentName)) - }() + if !dockersArePreLaunchedForCallTracerTests { + err = operations.Teardown() + require.NoError(t, err) + defer func() { + require.NoError(t, operations.Teardown()) + require.NoError(t, operations.StopComponent(l2ExplorerRPCComponentName)) + }() + } ctx := context.Background() opsCfg := operations.GetDefaultOperationsConfig() - opsMan, err := operations.NewManager(ctx, opsCfg) - require.NoError(t, err) - err = opsMan.Setup() - require.NoError(t, err) - - err = operations.StartComponent(l2ExplorerRPCComponentName, func() (bool, error) { return operations.NodeUpCondition(l2NetworkURL) }) - require.NoError(t, err) + if !dockersArePreLaunchedForCallTracerTests { + opsMan, err := operations.NewManager(ctx, opsCfg) + require.NoError(t, err) + err = opsMan.Setup() + require.NoError(t, err) + err = operations.StartComponent(l2ExplorerRPCComponentName, func() (bool, error) { return operations.NodeUpCondition(l2NetworkURL) }) + require.NoError(t, err) + } else { + log.Info("Using pre-launched dockers: no reset Database") + } const l1NetworkName, l2NetworkName = "Local L1", "Local L2" @@ -317,8 +329,9 @@ func TestDebugTraceBlockCallTracer(t *testing.T) { PrivateKey: operations.DefaultSequencerPrivateKey, }, } - - results := map[string]json.RawMessage{} + require.Equal(t, len(networks), 2, "only support 2 networks!") + //var results map[string]map[string]interface{} + results := map[string]map[string]interface{}{} type testCase struct { name string @@ -355,6 +368,7 @@ func TestDebugTraceBlockCallTracer(t *testing.T) { log.Debug("************************ ", tc.name, " ************************") for _, network := range networks { + debugID := fmt.Sprintf("[%s/%s]", tc.name, network.Name) log.Debug("------------------------ ", network.Name, " ------------------------") ethereumClient := operations.MustGetClient(network.URL) auth := operations.MustGetAuth(network.PrivateKey, network.ChainID) @@ -371,7 +385,7 @@ func TestDebugTraceBlockCallTracer(t *testing.T) { err = ethereumClient.SendTransaction(ctx, signedTx) require.NoError(t, err) - log.Debugf("tx sent: %v", signedTx.Hash().String()) + log.Debugf("%s tx sent: %v", debugID, signedTx.Hash().String()) err = operations.WaitTxToBeMined(ctx, ethereumClient, signedTx, operations.DefaultTimeoutTxToBeMined) if err != nil && !strings.HasPrefix(err.Error(), "transaction has failed, reason:") { @@ -391,37 +405,39 @@ func TestDebugTraceBlockCallTracer(t *testing.T) { var response types.Response if tc.blockNumberOrHash == "number" { + log.Infof("%s debug_traceBlockByNumber %v", debugID, receipt.BlockNumber) response, err = client.JSONRPCCall(network.URL, "debug_traceBlockByNumber", hex.EncodeBig(receipt.BlockNumber), debugOptions) } else { + log.Infof("%s debug_traceBlockByHash %v", debugID, receipt.BlockHash.String()) response, err = client.JSONRPCCall(network.URL, "debug_traceBlockByHash", receipt.BlockHash.String(), debugOptions) } require.NoError(t, err) require.Nil(t, response.Error) require.NotNil(t, response.Result) + log.Debugf("%s response:%s", debugID, string(response.Result)) - results[network.Name] = response.Result + txHash := signedTx.Hash().String() + resultForTx := findTxInResponse(t, response.Result, txHash, debugID) + results[network.Name] = resultForTx } - referenceTransactions := []interface{}{} - err = json.Unmarshal(results[l1NetworkName], &referenceTransactions) - require.NoError(t, err) - - for networkName, result := range results { - if networkName == l1NetworkName { - continue - } - - resultTransactions := []interface{}{} - err = json.Unmarshal(result, &resultTransactions) - require.NoError(t, err) - - for transactionIndex := range referenceTransactions { - referenceTransactionMap := referenceTransactions[transactionIndex].(map[string]interface{}) - resultTransactionMap := resultTransactions[transactionIndex].(map[string]interface{}) - - compareCallFrame(t, referenceTransactionMap, resultTransactionMap, networkName) - } - } + referenceTransactions := results[l1NetworkName] + resultTransactions := results[l2NetworkName] + compareCallFrame(t, referenceTransactions, resultTransactions, l2NetworkName) }) } } + +func findTxInResponse(t *testing.T, response json.RawMessage, txHash string, debugPrefix string) map[string]interface{} { + valueMap := []interface{}{} + err := json.Unmarshal(response, &valueMap) + require.NoError(t, err) + log.Infof("%s Reponse Length: %d", debugPrefix, len(valueMap)) + for transactionIndex := range valueMap { + if valueMap[transactionIndex].(map[string]interface{})["txHash"] == txHash { + return valueMap[transactionIndex].(map[string]interface{}) + } + } + log.Infof("%s Transaction not found: %s, returning first index", debugPrefix, txHash) + return valueMap[0].(map[string]interface{}) +} diff --git a/test/e2e/debug_shared.go b/test/e2e/debug_shared.go index d2e6993ab4..9db03a8631 100644 --- a/test/e2e/debug_shared.go +++ b/test/e2e/debug_shared.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/0xPolygonHermez/zkevm-node/hex" + "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/BridgeA" "github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/BridgeB" "github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/BridgeC" @@ -111,13 +112,13 @@ func createScCallSignedTx(t *testing.T, ctx context.Context, auth *bind.Transact func prepareERC20Transfer(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client) (map[string]interface{}, error) { _, tx, sc, err := ERC20.DeployERC20(auth, client, "MyToken", "MT") require.NoError(t, err) - + log.Debugf("prepareERC20Transfer DeployERC20 tx: %s", tx.Hash().String()) err = operations.WaitTxToBeMined(ctx, client, tx, operations.DefaultTimeoutTxToBeMined) require.NoError(t, err) tx, err = sc.Mint(auth, big.NewInt(1000000000)) require.NoError(t, err) - + log.Debugf("prepareERC20Transfer Mint tx: %s", tx.Hash().String()) err = operations.WaitTxToBeMined(ctx, client, tx, operations.DefaultTimeoutTxToBeMined) require.NoError(t, err)