From 0e409abb0d39585d4ee40bb749cf6ccce9d5e2ae Mon Sep 17 00:00:00 2001 From: hoangdv2429 Date: Mon, 25 Mar 2024 10:33:13 +0700 Subject: [PATCH] WIP --- .markdownlint.yaml | 3 +-- block/manager_test.go | 23 ++++++++++++++++++----- block/production_test.go | 9 ++++++++- conv/config_test.go | 3 ++- settlement/dymension/dymension_test.go | 23 +++++++++++++++++++---- settlement/settlement_test.go | 3 ++- 6 files changed, 50 insertions(+), 14 deletions(-) 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/manager_test.go b/block/manager_test.go index 9773fe660..3c2b1697f 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -127,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) @@ -140,8 +141,19 @@ 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) - <-ctx.Done() + // Capture the error returned by manager.Start. + errChan := make(chan error, 1) + go func() { + errChan <- manager.Start(ctx, true) // Assuming manager.Start is modified to return an error. + }() + + select { + case <-ctx.Done(): + // Context completed. + case err := <-errChan: + // Check for error from manager.Start. + assert.NoError(t, err, "Manager start should not produce an error") + } assert.True(t, manager.syncTarget == batch.EndHeight) //validate that we produced blocks assert.Greater(t, manager.store.Height(), batch.EndHeight) @@ -268,7 +280,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) @@ -422,7 +435,7 @@ 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) + _ = manager.produceBlock(ctx, true) } // 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..94e532a9d 100644 --- a/conv/config_test.go +++ b/conv/config_test.go @@ -31,7 +31,8 @@ func TestGetNodeConfig(t *testing.T) { 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) + assert.NoError(t, err) assert.Equal(t, c.expected, actual) }) } diff --git a/settlement/dymension/dymension_test.go b/settlement/dymension/dymension_test.go index 8e09c8000..9ad19ee11 100644 --- a/settlement/dymension/dymension_test.go +++ b/settlement/dymension/dymension_test.go @@ -190,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() { @@ -209,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 { @@ -226,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 a0bdebf7d..87f919173 100644 --- a/settlement/settlement_test.go +++ b/settlement/settlement_test.go @@ -77,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) }