Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdv2429 committed Mar 25, 2024
1 parent da9f88d commit 0e409ab
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ default: true
MD010:
code_blocks: false
MD013: false
MD024:
allow_different_nesting: true
MD024: true
MD033:
allowed_elements: ["img"]
23 changes: 18 additions & 5 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion block/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion conv/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
23 changes: 19 additions & 4 deletions settlement/dymension/dymension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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)
})
}
Expand Down
3 changes: 2 additions & 1 deletion settlement/settlement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0e409ab

Please sign in to comment.