From d70f556b5e600a835521c3a704374db9bc73f783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Vi=E1=BB=87t=20Ho=C3=A0ng?= Date: Mon, 25 Mar 2024 22:31:49 +0700 Subject: [PATCH] ci: additional workflows and update template (#614) --- .github/pull_request_template.md | 4 ++ .github/workflows/codeql.yml | 41 +++++++++++++++++++ .github/workflows/lint.yml | 54 -------------------------- .github/workflows/markdown_lint.yml | 19 +++++++++ .golangci.yml | 14 +++---- .markdownlint.yaml | 3 +- block/initchain.go | 2 +- block/manager_test.go | 29 ++++++++------ block/production_test.go | 9 ++++- conv/config_test.go | 25 +++++++----- da/avail/avail_test.go | 2 +- da/celestia/celestia_test.go | 14 +++++-- da/celestia/rpc_test.go | 4 +- da/da_test.go | 23 +++++++---- mempool/v1/mempool_test.go | 5 ++- node/node_test.go | 3 +- rpc/client/client_test.go | 2 +- rpc/rpc_test.go | 12 ++++-- settlement/dymension/dymension_test.go | 31 ++++++++++++--- settlement/settlement_test.go | 21 ++++++---- state/txindex/kv/kv_bench_test.go | 4 +- state/txindex/kv/kv_test.go | 8 ++-- 22 files changed, 206 insertions(+), 123 deletions(-) create mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/markdown_lint.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 30357ce0c..18e828bbb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,6 +4,10 @@ --- +Close #XXX + +<-- Briefly describe the content of this pull request --> + For Author: - [ ] Targeted PR against correct branch diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..12226a0fa --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + pull_request: + paths: + - "**.go" + push: + # The branches below must be a subset of the branches above + branches: + - main + - release/** + paths: + - "**.go" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "1.22" + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: "go" + queries: crypto-com/cosmos-sdk-codeql@main,security-and-quality + + - name: Build + run: make build + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index fdf9f514b..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Linters -on: - push: - tags: - - v* - branches: - - "main" - pull_request: - -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - env: - GOPRIVATE: "github.com/dymensionxyz/*" - GH_ACCESS_TOKEN: "${{ secrets.GH_ACCESS_TOKEN }}" - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: 1.22.1 - - run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/ - - name: golangci-lint - uses: golangci/golangci-lint-action@v3.7.0 - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.52.0 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true - markdownlint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: markdownlint-cli - uses: nosborn/github-action-markdown-cli@v3.3.0 - with: - files: . - config-file: .markdownlint.yaml \ No newline at end of file diff --git a/.github/workflows/markdown_lint.yml b/.github/workflows/markdown_lint.yml new file mode 100644 index 000000000..2f1219c64 --- /dev/null +++ b/.github/workflows/markdown_lint.yml @@ -0,0 +1,19 @@ +name: markdown-lint +on: + push: + tags: + - v* + branches: + - main + pull_request: + +jobs: + markdownlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: markdownlint-cli + uses: nosborn/github-action-markdown-cli@v3.2.0 + with: + files: ./ + config_file: .markdownlint.yaml \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 4daad2459..a8cba5db2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,13 +3,6 @@ run: timeout: 5m modules-download-mode: readonly # mempool and indexer code is borrowed from Tendermint - skip-dirs: - - mempool - - state/indexer - - state/txindex - skip-files: - - da/celestia/mock/server.go - - ./*_test.go linters: disable-all: true @@ -29,3 +22,10 @@ linters: issues: exclude-use-default: false + exclude-files: + - da/celestia/mock/server.go + - ./*_test.go + exclude-dirs: + - mempool + - state/indexer + - state/txindex \ No newline at end of file diff --git a/.markdownlint.yaml b/.markdownlint.yaml index ddf071f93..a8f186f39 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -2,7 +2,6 @@ default: true MD010: code_blocks: false MD013: false -MD024: - allow_different_nesting: true +MD024: true MD033: allowed_elements: ["img"] \ No newline at end of file diff --git a/block/initchain.go b/block/initchain.go index c57e42a3e..5c6443d9c 100644 --- a/block/initchain.go +++ b/block/initchain.go @@ -21,7 +21,7 @@ func (m *Manager) RunInitChain(ctx context.Context) error { // This is a hack to make sure the chain can get both addresses without us needing to change comet signatures: // The RDK will save a sequencer, and delete the extra validator after initChain, so we also delete it here // to keep the state in sync. - + //get the proposer's consensus pubkey proposer := m.settlementClient.GetProposer() tmPubKey, err := cryptocodec.ToTmPubKeyInterface(proposer.PublicKey) diff --git a/block/manager_test.go b/block/manager_test.go index 3c747cb71..321de8506 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -31,12 +31,8 @@ import ( "github.com/dymensionxyz/dymint/store" ) -const ( - connectionRefusedErrorMessage = "connection refused" - errorValidatingBatchErrorMessage = "Error validating batch" -) - func TestInitialState(t *testing.T) { + var err error assert := assert.New(t) genesis := testutil.GenerateGenesis(123) sampleState := testutil.GenerateState(1, 128) @@ -44,7 +40,8 @@ func TestInitialState(t *testing.T) { conf := getManagerConfig() logger := log.TestingLogger() pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() + require.NoError(t, err) proxyApp := testutil.GetABCIProxyAppMock(logger.With("module", "proxy")) settlementlc := slregistry.GetClient(slregistry.Mock) _ = settlementlc.Init(settlement.Config{}, pubsubServer, logger) @@ -52,7 +49,7 @@ func TestInitialState(t *testing.T) { // Init empty store and full store emptyStore := store.New(store.NewDefaultInMemoryKVStore()) fullStore := store.New(store.NewDefaultInMemoryKVStore()) - _, err := fullStore.UpdateState(sampleState, nil) + _, err = fullStore.UpdateState(sampleState, nil) require.NoError(t, err) // Init p2p client @@ -130,7 +127,8 @@ func TestProduceOnlyAfterSynced(t *testing.T) { assert.NoError(t, err) daResultSubmitBatch := manager.dalc.SubmitBatch(batch) assert.Equal(t, daResultSubmitBatch.Code, da.StatusSuccess) - manager.settlementClient.SubmitBatch(batch, manager.dalc.GetClientType(), &daResultSubmitBatch) + err = manager.settlementClient.SubmitBatch(batch, manager.dalc.GetClientType(), &daResultSubmitBatch) + require.NoError(t, err) nextBatchStartHeight = batch.EndHeight + 1 // Wait until daHeight is updated time.Sleep(time.Millisecond * 500) @@ -143,7 +141,14 @@ func TestProduceOnlyAfterSynced(t *testing.T) { //enough time to sync and produce blocks ctx, cancel := context.WithTimeout(context.Background(), time.Second*4) defer cancel() - go manager.Start(ctx, true) + // Capture the error returned by manager.Start. + errChan := make(chan error, 1) + go func() { + errChan <- manager.Start(ctx, true) + err := <-errChan + // Check for error from manager.Start. + assert.NoError(t, err, "Manager start should not produce an error") + }() <-ctx.Done() assert.True(t, manager.syncTarget == batch.EndHeight) //validate that we produced blocks @@ -271,7 +276,8 @@ func TestBlockProductionNodeHealth(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { - manager.pubsub.PublishWithEvents(context.Background(), c.healthStatusEventData, c.healthStatusEvent) + err := manager.pubsub.PublishWithEvents(context.Background(), c.healthStatusEventData, c.healthStatusEvent) + assert.NoError(err, "PublishWithEvents should not produce an error") time.Sleep(500 * time.Millisecond) blockHeight := manager.store.Height() time.Sleep(500 * time.Millisecond) @@ -425,7 +431,8 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Produce blocks for i := 0; i < tc.blocksToProduce; i++ { - manager.produceBlock(ctx, true) + err := manager.produceBlock(ctx, true) + assert.NoError(err) } // Call createNextDABatch function diff --git a/block/production_test.go b/block/production_test.go index 78de797e9..f66d905a6 100644 --- a/block/production_test.go +++ b/block/production_test.go @@ -114,7 +114,14 @@ func TestCreateEmptyBlocksNew(t *testing.T) { require.NoError(err) require.NotNil(abciClient) require.NoError(abciClient.Start()) - defer abciClient.Stop() + + defer func() { + // Capture the error returned by abciClient.Stop and handle it. + err := abciClient.Stop() + if err != nil { + t.Logf("Error stopping ABCI client: %v", err) + } + }() mempoolCfg := tmcfg.DefaultMempoolConfig() mempoolCfg.KeepInvalidTxsInCache = false diff --git a/conv/config_test.go b/conv/config_test.go index 7f822e41d..c0b6ef5ef 100644 --- a/conv/config_test.go +++ b/conv/config_test.go @@ -16,22 +16,29 @@ func TestGetNodeConfig(t *testing.T) { validDymint := "/ip4/127.0.0.1/tcp/1234" cases := []struct { - name string - input *tmcfg.Config - expected config.NodeConfig + name string + input *tmcfg.Config + expected config.NodeConfig + expectError bool }{ - {"empty", nil, config.NodeConfig{}}, - {"Seeds", &tmcfg.Config{P2P: &tmcfg.P2PConfig{Seeds: "seeds"}}, config.NodeConfig{P2P: config.P2PConfig{Seeds: "seeds"}}}, + {"empty", nil, config.NodeConfig{}, true}, + {"Seeds", &tmcfg.Config{P2P: &tmcfg.P2PConfig{Seeds: validCosmos + "," + validCosmos}}, config.NodeConfig{P2P: config.P2PConfig{Seeds: validDymint + "," + validDymint}}, false}, //GetNodeConfig translates the listen address, so we expect the translated address - {"ListenAddress", &tmcfg.Config{P2P: &tmcfg.P2PConfig{ListenAddress: validCosmos}}, config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validDymint}}}, - {"RootDir", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{RootDir: "~/root"}}, config.NodeConfig{RootDir: "~/root"}}, - {"DBPath", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{DBPath: "./database"}}, config.NodeConfig{DBPath: "./database"}}, + {"ListenAddress", &tmcfg.Config{P2P: &tmcfg.P2PConfig{ListenAddress: validCosmos}}, config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validDymint}}, false}, + {"RootDir", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{RootDir: "~/root"}}, config.NodeConfig{RootDir: "~/root"}, false}, + {"DBPath", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{DBPath: "./database"}}, config.NodeConfig{DBPath: "./database"}, false}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { var actual config.NodeConfig - GetNodeConfig(&actual, c.input) + err := GetNodeConfig(&actual, c.input) + if c.expectError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, c.expected, actual) + } assert.Equal(t, c.expected, actual) }) } diff --git a/da/avail/avail_test.go b/da/avail/avail_test.go index b10573ffe..c5f71d260 100644 --- a/da/avail/avail_test.go +++ b/da/avail/avail_test.go @@ -129,7 +129,7 @@ func TestRetriveBatches(t *testing.T) { avail.WithClient(mockSubstrateApiClient), } pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() assert.NoError(err) // Start the DALC dalc := avail.DataAvailabilityLayerClient{} diff --git a/da/celestia/celestia_test.go b/da/celestia/celestia_test.go index a98962671..0bd74d149 100644 --- a/da/celestia/celestia_test.go +++ b/da/celestia/celestia_test.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "math/rand" + cryptoRand "crypto/rand" "testing" "time" @@ -294,9 +295,14 @@ func TestRetrievalWrongCommitment(t *testing.T) { } func setDAandMock(t *testing.T) (*mocks.CelestiaRPCClient, da.DataAvailabilityLayerClient, []byte, *header.ExtendedHeader) { + var err error pubsubServer := pubsub.NewServer() - pubsubServer.Start() - defer pubsubServer.Stop() + err = pubsubServer.Start() + require.NoError(t, err) + defer func() { + err = pubsubServer.Stop() + require.NoError(t, err) + }() require := require.New(t) @@ -309,7 +315,7 @@ func setDAandMock(t *testing.T) (*mocks.CelestiaRPCClient, da.DataAvailabilityLa GasLimit: 3000000, Fee: 200000000, } - err := config.InitNamespaceID() + err = config.InitNamespaceID() require.NoError(err) conf, err := json.Marshal(config) require.NoError(err) @@ -392,6 +398,6 @@ func getRandomTx() types.Tx { func getRandomBytes(n int) []byte { data := make([]byte, n) - _, _ = rand.Read(data) + _, _ = cryptoRand.Read(data) return data } diff --git a/da/celestia/rpc_test.go b/da/celestia/rpc_test.go index 2b1e2c5ce..fefa4082d 100644 --- a/da/celestia/rpc_test.go +++ b/da/celestia/rpc_test.go @@ -63,6 +63,7 @@ func TestSubmitBatch(t *testing.T) { // build a proof for an NID that is within the namespace range of the tree nID := []byte{1} proof, err := tree.ProveNamespace(nID) + require.NoError(err) blobProof := blob.Proof([]*nmt.Proof{&proof}) cases := []struct { @@ -110,7 +111,8 @@ func TestSubmitBatch(t *testing.T) { } // Subscribe to the health status event pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() + require.NoError(err, tc.name) HealthSubscription, err := pubsubServer.Subscribe(context.Background(), "testSubmitBatch", da.EventQueryDAHealthStatus) assert.NoError(err, tc.name) // Start the DALC diff --git a/da/da_test.go b/da/da_test.go index 11f7b6352..e61f0db03 100644 --- a/da/da_test.go +++ b/da/da_test.go @@ -1,8 +1,9 @@ package da_test import ( + cryptoRand "crypto/rand" "encoding/json" - "math/rand" + "math/rand" //#gosec "testing" "time" @@ -32,7 +33,8 @@ func doTestLifecycle(t *testing.T, daType string) { var err error require := require.New(t) pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() + require.NoError(err) dacfg := []byte{} dalc := registry.GetClient(daType) @@ -54,6 +56,7 @@ func TestDALC(t *testing.T) { func doTestDALC(t *testing.T, mockDalc da.DataAvailabilityLayerClient) { require := require.New(t) assert := assert.New(t) + var err error // mock DALC will advance block height every 100ms if _, ok := mockDalc.(*mock.DataAvailabilityLayerClient); !ok { @@ -63,8 +66,9 @@ func doTestDALC(t *testing.T, mockDalc da.DataAvailabilityLayerClient) { dalc := mockDalc.(*mock.DataAvailabilityLayerClient) pubsubServer := pubsub.NewServer() - pubsubServer.Start() - err := dalc.Init(conf, pubsubServer, store.NewDefaultInMemoryKVStore(), log.TestingLogger()) + err = pubsubServer.Start() + require.NoError(err) + err = dalc.Init(conf, pubsubServer, store.NewDefaultInMemoryKVStore(), log.TestingLogger()) require.NoError(err) err = dalc.Start() @@ -124,6 +128,7 @@ func TestRetrieve(t *testing.T) { func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) { require := require.New(t) assert := assert.New(t) + var err error // mock DALC will advance block height every 100ms conf := []byte{} @@ -143,8 +148,9 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) { } pubsubServer := pubsub.NewServer() - pubsubServer.Start() - err := dalc.Init(conf, pubsubServer, store.NewDefaultInMemoryKVStore(), log.TestingLogger()) + err = pubsubServer.Start() + require.NoError(err) + err = dalc.Init(conf, pubsubServer, store.NewDefaultInMemoryKVStore(), log.TestingLogger()) require.NoError(err) err = dalc.Start() @@ -234,12 +240,13 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { } func getRandomTx() types.Tx { - size := rand.Int()%100 + 100 + NuM := rand.Int() + size := NuM%100 + 100 return types.Tx(getRandomBytes(size)) } func getRandomBytes(n int) []byte { data := make([]byte, n) - _, _ = rand.Read(data) + _, _ = cryptoRand.Read(data) return data } diff --git a/mempool/v1/mempool_test.go b/mempool/v1/mempool_test.go index 886d90c12..f1ed1e2b7 100644 --- a/mempool/v1/mempool_test.go +++ b/mempool/v1/mempool_test.go @@ -87,7 +87,10 @@ func setup(t testing.TB, cacheSize int, options ...TxMempoolOption) *TxMempool { require.NoError(t, appConnMem.Start()) t.Cleanup(func() { - os.RemoveAll(cfg.RootDir) + err := os.RemoveAll(cfg.RootDir) + if err != nil { + t.Log("failed to remove temporary directory", err) + } require.NoError(t, appConnMem.Stop()) }) diff --git a/node/node_test.go b/node/node_test.go index 6a1480391..8feb3b3ef 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -201,5 +201,6 @@ func TestHealthStatusEventHandler(t *testing.T) { <-done }) } - node.Stop() + err = node.Stop() + assert.NoError(err) } diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index 0ad91e2b1..8def07273 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -795,7 +795,7 @@ func getRandomTx() types.Tx { func getRandomBytes(n int) []byte { data := make([]byte, n) - _, _ = rand.Read(data) + _, _ = crand.Read(data) return data } diff --git a/rpc/rpc_test.go b/rpc/rpc_test.go index e16cab553..7d166eb61 100644 --- a/rpc/rpc_test.go +++ b/rpc/rpc_test.go @@ -14,9 +14,12 @@ import ( ) func TestNodeHealthRPCPropogation(t *testing.T) { - + var err error server, listener := rpctestutils.CreateLocalServer(t) - defer server.Stop() + defer func() { + err = server.Stop() + require.NoError(t, err) + }() // Wait for some blocks to be produced time.Sleep(1 * time.Second) @@ -58,7 +61,10 @@ func TestNodeHealthRPCPropogation(t *testing.T) { // Make the request res, err := httpGetWithTimeout(fmt.Sprintf("http://%s", listener.Addr().String())+tc.endpoint, 5*time.Second) require.NoError(t, err) - defer res.Body.Close() + defer func() { + err = res.Body.Close() + require.NoError(t, err) + }() // Check the response assert.Equal(t, tc.expectedStatusCode, res.StatusCode) diff --git a/settlement/dymension/dymension_test.go b/settlement/dymension/dymension_test.go index a18f57af5..9ad19ee11 100644 --- a/settlement/dymension/dymension_test.go +++ b/settlement/dymension/dymension_test.go @@ -36,6 +36,7 @@ import ( ) func TestGetSequencers(t *testing.T) { + var err error require := require.New(t) cosmosClientMock := mocks.NewCosmosClient(t) @@ -52,7 +53,8 @@ func TestGetSequencers(t *testing.T) { } pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() + require.NoError(err) hubClient, err := newDymensionHubClient(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) require.NoError(err) @@ -68,10 +70,12 @@ func TestGetSequencers(t *testing.T) { // 3. Batch is submitted successfully, hub event not emitted, but checking for inclusion succeeds // 4. Batch is submitted successfully and accepted by catching hub event func TestPostBatch(t *testing.T) { + var err error require := require.New(t) pubsubServer := pubsub.NewServer() - pubsubServer.Start() + err = pubsubServer.Start() + require.NoError(err) // Create a mock cosmos client cosmosClientMock := mocks.NewCosmosClient(t) @@ -186,7 +190,8 @@ func TestPostBatch(t *testing.T) { } hubClient, err := newDymensionHubClient(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) require.NoError(err) - hubClient.Start() + err = hubClient.Start() + require.NoError(err) // Handle the various events that are emitted and timeout if we don't get them var eventsReceivedCount int64 go func() { @@ -205,8 +210,21 @@ func TestPostBatch(t *testing.T) { resultSubmitBatch := &da.ResultSubmitBatch{} resultSubmitBatch.SubmitMetaData = &da.DASubmitMetaData{} - // Post the batch - go hubClient.PostBatch(batch, da.Mock, resultSubmitBatch) + errChan := make(chan error, 1) // Create a channel to receive an error from the goroutine + // Post the batch in a goroutine and capture any error. + go func() { + err := hubClient.PostBatch(batch, da.Mock, resultSubmitBatch) + errChan <- err // Send any error to the errChan + }() + + // Use a select statement to wait for a potential error or a timeout. + select { + case err := <-errChan: + // Check for error from PostBatch. + assert.NoError(t, err, "PostBatch should not produce an error") + case <-time.After(50 * time.Millisecond): + // Timeout case to avoid blocking forever if PostBatch doesn't return. + } // Wait for the batch to be submitted and submit an event notifying that the batch was accepted time.Sleep(50 * time.Millisecond) if c.isBatchAcceptedHubEvent { @@ -222,7 +240,8 @@ func TestPostBatch(t *testing.T) { wg.Wait() assert.Equal(t, eventsCount, int(eventsReceivedCount)) // Stop the hub client and wait for it to stop - hubClient.Stop() + err = hubClient.Stop() + require.NoError(err) time.Sleep(1 * time.Second) }) } diff --git a/settlement/settlement_test.go b/settlement/settlement_test.go index 3de2f15de..87f919173 100644 --- a/settlement/settlement_test.go +++ b/settlement/settlement_test.go @@ -24,12 +24,14 @@ import ( const batchSize = 5 func TestLifecycle(t *testing.T) { + var err error client := registry.GetClient(registry.Mock) require := require.New(t) pubsubServer := pubsub.NewServer() - pubsubServer.Start() - err := client.Init(settlement.Config{}, pubsubServer, log.TestingLogger()) + err = pubsubServer.Start() + require.NoError(err) + err = client.Init(settlement.Config{}, pubsubServer, log.TestingLogger()) require.NoError(err) err = client.Start() @@ -75,7 +77,8 @@ func TestSubmitAndRetrieve(t *testing.T) { Height: batch.EndHeight, }, } - settlementClient.SubmitBatch(batch, da.Mock, daResult) + err = settlementClient.SubmitBatch(batch, da.Mock, daResult) + require.NoError(err) // sleep for 500 ms to make sure batch got accepted by the settlement layer time.Sleep(500 * time.Millisecond) } @@ -95,6 +98,7 @@ func TestSubmitAndRetrieve(t *testing.T) { } func TestGetSequencersEmptyList(t *testing.T) { + var err error settlementClient := registry.GetClient(registry.Mock) hubClientMock := mocks.NewHubClient(t) hubClientMock.On("GetSequencers", tsmock.Anything, tsmock.Anything).Return(nil, settlement.ErrNoSequencerForRollapp) @@ -103,8 +107,9 @@ func TestGetSequencersEmptyList(t *testing.T) { } pubsubServer := pubsub.NewServer() - pubsubServer.Start() - err := settlementClient.Init(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) + err = pubsubServer.Start() + require.NoError(t, err) + err = settlementClient.Init(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) assert.Error(t, err, "empty sequencer list should return an error") } @@ -149,10 +154,12 @@ func TestGetSequencers(t *testing.T) { func initClient(t *testing.T, settlementlc settlement.LayerI, options ...settlement.Option) { require := require.New(t) + var err error pubsubServer := pubsub.NewServer() - pubsubServer.Start() - err := settlementlc.Init(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) + err = pubsubServer.Start() + require.NoError(err) + err = settlementlc.Init(settlement.Config{}, pubsubServer, log.TestingLogger(), options...) require.NoError(err) err = settlementlc.Start() diff --git a/state/txindex/kv/kv_bench_test.go b/state/txindex/kv/kv_bench_test.go index eebd6b538..e9ad22b40 100644 --- a/state/txindex/kv/kv_bench_test.go +++ b/state/txindex/kv/kv_bench_test.go @@ -4,7 +4,7 @@ import ( "context" "crypto/rand" "fmt" - "io/ioutil" + "os" "testing" abci "github.com/tendermint/tendermint/abci/types" @@ -15,7 +15,7 @@ import ( ) func BenchmarkTxSearch(b *testing.B) { - dbDir, err := ioutil.TempDir("", "benchmark_tx_search_test") + dbDir, err := os.MkdirTemp("", "benchmark_tx_search_test") if err != nil { b.Errorf("failed to create temporary directory: %s", err) } diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index 69b67f285..ae8d18853 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -3,7 +3,6 @@ package kv import ( "context" "fmt" - "io/ioutil" "os" "testing" @@ -329,9 +328,12 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult { } func benchmarkTxIndex(txsCount int64, b *testing.B) { - dir, err := ioutil.TempDir("", "tx_index_db") + dir, err := os.MkdirTemp("", "tx_index_db") require.NoError(b, err) - defer os.RemoveAll(dir) + defer func() { + err := os.RemoveAll(dir) + require.NoError(b, err) + }() store := store.NewDefaultKVStore(dir, "db", "tx_index") require.NoError(b, err)