diff --git a/block/submitter_test.go b/block/submitter_test.go index 7b3e75aa43..130a17f4b1 100644 --- a/block/submitter_test.go +++ b/block/submitter_test.go @@ -99,9 +99,11 @@ func TestSubmitDataToDA_Failure(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Reset mock expectations for each error scenario + var gasPriceHistory []float64 da.ExpectedCalls = nil da.On("GasMultiplier", mock.Anything).Return(2.0, nil) da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Run(func(args mock.Arguments) { gasPriceHistory = append(gasPriceHistory, args.Get(2).(float64)) }). //save the gas price to verify it later Return(nil, tc.daError) pubKey, err := m.signer.GetPublic() @@ -133,6 +135,76 @@ func TestSubmitDataToDA_Failure(t *testing.T) { // Expect an error from submitDataToDA err = m.submitDataToDA(context.Background(), &signedData) assert.Error(t, err, "expected error") + + // Validate that gas price increased according to gas multiplier + previousGasPrice := m.gasPrice + assert.Equal(t, gasPriceHistory[0], m.gasPrice) // verify that the first call is done with the right price + for _, gasPrice := range gasPriceHistory[1:] { + assert.Equal(t, gasPrice, previousGasPrice*m.gasMultiplier) + previousGasPrice = gasPrice + } + }) + } +} + +func TestSubmitHeadersToDA_Success(t *testing.T) { + da := &mocks.DA{} + m := newTestManagerWithDA(t, da) + // Prepare a mock PendingHeaders with test data + m.pendingHeaders = newPendingBlocks(t) + + // Fill the pending headers with mock block data + fillWithBlockData(context.Background(), t, m.pendingHeaders, "Test Submitting Headers") + + // Simulate DA layer successfully accepting the header submission + da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return([]coreda.ID{[]byte("id")}, nil) + + // Call submitHeadersToDA and expect no error + err := m.submitHeadersToDA(context.Background()) + assert.NoError(t, err) +} + +// TestSubmitHeadersToDA_Failure verifies that submitHeadersToDA returns an error for various DA failures. +func TestSubmitHeadersToDA_Failure(t *testing.T) { + da := &mocks.DA{} + m := newTestManagerWithDA(t, da) + // Prepare a mock PendingHeaders with test data + m.pendingHeaders = newPendingBlocks(t) + + // Table-driven test for different DA error scenarios + testCases := []struct { + name string + daError error + }{ + {"AlreadyInMempool", coreda.ErrTxAlreadyInMempool}, + {"TimedOut", coreda.ErrTxTimedOut}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Fill the pending headers with mock block data for each subtest + fillWithBlockData(context.Background(), t, m.pendingHeaders, "Test Submitting Headers") + // Reset mock expectations for each error scenario + da.ExpectedCalls = nil + // Simulate DA layer returning a specific error + var gasPriceHistory []float64 + da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Run(func(args mock.Arguments) { gasPriceHistory = append(gasPriceHistory, args.Get(2).(float64)) }). //save the gas price to verify it later + Return(nil, tc.daError) + + // Call submitHeadersToDA and expect an error + err := m.submitHeadersToDA(context.Background()) + assert.Error(t, err, "expected error for DA error: %v", tc.daError) + assert.Contains(t, err.Error(), "failed to submit all headers to DA layer") + + // Validate that gas price increased according to gas multiplier + previousGasPrice := m.gasPrice + assert.Equal(t, gasPriceHistory[0], m.gasPrice) // verify that the first call is done with the right price + for _, gasPrice := range gasPriceHistory[1:] { + assert.Equal(t, gasPrice, previousGasPrice*m.gasMultiplier) + previousGasPrice = gasPrice + } }) } } diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 63d02dd4b0..489ea24338 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -15,18 +15,10 @@ import ( // TestNewCache verifies that NewCache initializes correctly func TestNewCache(t *testing.T) { cache := NewCache[string]() - if cache == nil { - t.Fatal("NewCache returned nil") - } - if cache.items == nil { - t.Error("items map not initialized") - } - if cache.hashes == nil { - t.Error("hashes map not initialized") - } - if cache.daIncluded == nil { - t.Error("daIncluded map not initialized") - } + require.NotNil(t, cache, "NewCache returned nil") + assert.NotNil(t, cache.items, "items map not initialized") + assert.NotNil(t, cache.hashes, "hashes map not initialized") + assert.NotNil(t, cache.daIncluded, "daIncluded map not initialized") } // TestCacheItemOperations tests the item-related operations (Get, Set, Delete)