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

add check for not found tx and block for trace endpoints #1811

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions jsonrpc/endpoints_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (d *DebugEndpoints) TraceBlockByNumber(number BlockNumber, cfg *traceConfig

block, err := d.state.GetL2BlockByNumber(ctx, blockNumber, dbTx)
if errors.Is(err, state.ErrNotFound) {
return nil, newRPCError(defaultErrorCode, "genesis is not traceable")
return nil, newRPCError(defaultErrorCode, fmt.Sprintf("block #%d not found", blockNumber))
} else if err == state.ErrNotFound {
return rpcErrorResponse(defaultErrorCode, "failed to get block by number", err)
}
Expand All @@ -92,7 +92,7 @@ func (d *DebugEndpoints) TraceBlockByHash(hash argHash, cfg *traceConfig) (inter
return d.txMan.NewDbTxScope(d.state, func(ctx context.Context, dbTx pgx.Tx) (interface{}, rpcError) {
block, err := d.state.GetL2BlockByHash(ctx, hash.Hash(), dbTx)
if errors.Is(err, state.ErrNotFound) {
return nil, newRPCError(defaultErrorCode, "genesis is not traceable")
return nil, newRPCError(defaultErrorCode, fmt.Sprintf("block %s not found", hash.Hash().String()))
} else if err == state.ErrNotFound {
return rpcErrorResponse(defaultErrorCode, "failed to get block by hash", err)
}
Expand Down Expand Up @@ -135,7 +135,9 @@ func (d *DebugEndpoints) buildTraceTransaction(ctx context.Context, hash common.
}

result, err := d.state.DebugTransaction(ctx, hash, traceConfig, dbTx)
if err != nil {
if errors.Is(err, state.ErrNotFound) {
return rpcErrorResponse(defaultErrorCode, "genesis is not traceable", nil)
} else if err != nil {
const errorMessage = "failed to get trace"
log.Infof("%v: %v", errorMessage, err)
return nil, newRPCError(defaultErrorCode, errorMessage)
Expand Down
195 changes: 195 additions & 0 deletions test/e2e/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,201 @@ import (

const fixedTxGasLimit uint64 = 100000

func TestDebugTraceTransactionNotFoundTx(t *testing.T) {
if testing.Short() {
t.Skip()
}

const l2NetworkURL = "http://localhost:8124"
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))
}()

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)

const l1NetworkName, l2NetworkName = "Local L1", "Local L2"

networks := []struct {
Name string
URL string
WebSocketURL string
ChainID uint64
PrivateKey string
}{
{
Name: l1NetworkName,
URL: operations.DefaultL1NetworkURL,
ChainID: operations.DefaultL1ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
{
Name: l2NetworkName,
URL: l2NetworkURL,
ChainID: operations.DefaultL2ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
}

for _, network := range networks {
log.Debugf(network.Name)
tx := types.NewTx(&types.LegacyTx{
Nonce: 10,
})

response, err := jsonrpc.JSONRPCCall(network.URL, "debug_traceTransaction", tx.Hash().String())
require.NoError(t, err)
require.Nil(t, response.Result)
require.NotNil(t, response.Error)

require.Equal(t, -32000, response.Error.Code)
require.Equal(t, "genesis is not traceable", response.Error.Message)
require.Nil(t, response.Error.Data)
}
}

func TestDebugTraceBlockByNumberNotFoundTx(t *testing.T) {
if testing.Short() {
t.Skip()
}

const l2NetworkURL = "http://localhost:8124"
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))
}()

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)

const l1NetworkName, l2NetworkName = "Local L1", "Local L2"

networks := []struct {
Name string
URL string
WebSocketURL string
ChainID uint64
PrivateKey string
}{
{
Name: l1NetworkName,
URL: operations.DefaultL1NetworkURL,
ChainID: operations.DefaultL1ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
{
Name: l2NetworkName,
URL: l2NetworkURL,
ChainID: operations.DefaultL2ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
}

for _, network := range networks {
log.Debugf(network.Name)

response, err := jsonrpc.JSONRPCCall(network.URL, "debug_traceBlockByNumber", hex.EncodeBig(big.NewInt(999999999999)))
require.NoError(t, err)
require.Nil(t, response.Result)
require.NotNil(t, response.Error)

require.Equal(t, -32000, response.Error.Code)
require.Equal(t, "block #999999999999 not found", response.Error.Message)
require.Nil(t, response.Error.Data)
}
}

func TestDebugTraceBlockByHashNotFoundTx(t *testing.T) {
if testing.Short() {
t.Skip()
}

const l2NetworkURL = "http://localhost:8124"
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))
}()

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)

const l1NetworkName, l2NetworkName = "Local L1", "Local L2"

networks := []struct {
Name string
URL string
WebSocketURL string
ChainID uint64
PrivateKey string
}{
{
Name: l1NetworkName,
URL: operations.DefaultL1NetworkURL,
ChainID: operations.DefaultL1ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
{
Name: l2NetworkName,
URL: l2NetworkURL,
ChainID: operations.DefaultL2ChainID,
PrivateKey: operations.DefaultSequencerPrivateKey,
},
}

for _, network := range networks {
log.Debugf(network.Name)

response, err := jsonrpc.JSONRPCCall(network.URL, "debug_traceBlockByHash", common.Hash{}.String())
require.NoError(t, err)
require.Nil(t, response.Result)
require.NotNil(t, response.Error)

require.Equal(t, -32000, response.Error.Code)
require.Equal(t, "block 0x0000000000000000000000000000000000000000000000000000000000000000 not found", response.Error.Message)
require.Nil(t, response.Error.Data)
}
}

func TestDebugTraceTransaction(t *testing.T) {
if testing.Short() {
t.Skip()
Expand Down