From 85b2830efeaa49efe882512b298e5e3443163062 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Tue, 26 Nov 2024 18:11:45 +0900 Subject: [PATCH] fix lint --- app/upgrade.go | 12 ++-- jsonrpc/namespaces/eth/filters/api_test.go | 78 ++++++++++++++++++++++ tests/app_creator.go | 3 +- tests/tx_helper.go | 3 +- 4 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 jsonrpc/namespaces/eth/filters/api_test.go diff --git a/app/upgrade.go b/app/upgrade.go index 6429fd4..ee4e13b 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -22,7 +22,7 @@ import ( opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" ) -const upgradeName = "0.6.6" +const upgradeName = "0.6.7" // RegisterUpgradeHandlers returns upgrade handlers func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { @@ -38,11 +38,13 @@ func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { } // set non-zero default values for new params - params.HookMaxGas = opchildtypes.DefaultHookMaxGas + if params.HookMaxGas == 0 { + params.HookMaxGas = opchildtypes.DefaultHookMaxGas - err = app.OPChildKeeper.SetParams(ctx, params) - if err != nil { - return nil, err + err = app.OPChildKeeper.SetParams(ctx, params) + if err != nil { + return nil, err + } } //////////////////////////// MINIEVM /////////////////////////////////// diff --git a/jsonrpc/namespaces/eth/filters/api_test.go b/jsonrpc/namespaces/eth/filters/api_test.go new file mode 100644 index 0000000..c9538f0 --- /dev/null +++ b/jsonrpc/namespaces/eth/filters/api_test.go @@ -0,0 +1,78 @@ +package filters_test + +import ( + "context" + "crypto/ecdsa" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/server" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/ethereum/go-ethereum/common" + + minitiaapp "github.com/initia-labs/minievm/app" + "github.com/initia-labs/minievm/indexer" + "github.com/initia-labs/minievm/jsonrpc/backend" + "github.com/initia-labs/minievm/jsonrpc/config" + "github.com/initia-labs/minievm/jsonrpc/namespaces/eth/filters" + "github.com/initia-labs/minievm/tests" +) + +type testInput struct { + app *minitiaapp.MinitiaApp + indexer indexer.EVMIndexer + backend *backend.JSONRPCBackend + addrs []common.Address + privKeys []*ecdsa.PrivateKey + cometRPC *tests.MockCometRPC + filterAPI *filters.FilterAPI +} + +func setupFilterAPI(t *testing.T) testInput { + app, addrs, privKeys := tests.CreateApp(t) + indexer := app.EVMIndexer() + + ctx := context.Background() + svrCtx := server.NewDefaultContext() + clientCtx := client.Context{}.WithCodec(app.AppCodec()). + WithInterfaceRegistry(app.AppCodec().InterfaceRegistry()). + WithTxConfig(app.TxConfig()). + WithLegacyAmino(app.LegacyAmino()). + WithAccountRetriever(authtypes.AccountRetriever{}) + + cfg := config.DefaultJSONRPCConfig() + cfg.Enable = true + cfg.FilterTimeout = 3 * time.Second + + mockCometRPC := tests.NewMockCometRPC(app.BaseApp) + clientCtx = clientCtx.WithClient(mockCometRPC) + + backend, err := backend.NewJSONRPCBackend(ctx, app, app.Logger(), svrCtx, clientCtx, cfg) + require.NoError(t, err) + + filterAPI := filters.NewFilterAPI(ctx, app, backend, app.Logger()) + + return testInput{ + app: app, + indexer: indexer, + backend: backend, + addrs: addrs, + privKeys: privKeys, + cometRPC: mockCometRPC, + filterAPI: filterAPI, + } +} + +func Test_NewPendingTransactionFilter(t *testing.T) { + input := setupFilterAPI(t) + defer input.app.Close() + + fullTx := false + filterID, err := input.filterAPI.NewPendingTransactionFilter(&fullTx) + require.NoError(t, err) + require.NotEmpty(t, filterID) +} diff --git a/tests/app_creator.go b/tests/app_creator.go index 3f7a08d..22a20b0 100644 --- a/tests/app_creator.go +++ b/tests/app_creator.go @@ -51,7 +51,8 @@ func CreateApp(t *testing.T) (*minitiaapp.MinitiaApp, []common.Address, []*ecdsa _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) - app.Commit() + _, err = app.Commit() + require.NoError(t, err) return app, addrs, privKeys } diff --git a/tests/tx_helper.go b/tests/tx_helper.go index 2f75f55..7e3572c 100644 --- a/tests/tx_helper.go +++ b/tests/tx_helper.go @@ -203,7 +203,8 @@ func ExecuteTxs(t *testing.T, app *minitiaapp.MinitiaApp, txs ...sdk.Tx) (*abcit TxResults: resBlock.TxResults, } - app.Commit() + _, err = app.Commit() + require.NoError(t, err) return finalizeReq, finalizeRes }