From 95adcc378fb1b3e11c4bb6a628662db8b78d06c3 Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:03:02 +0800 Subject: [PATCH] fix tests --- .../watcher/bundle_proposer_test.go | 21 +++++++++++++++++++ rollup/internal/orm/orm_test.go | 2 ++ 2 files changed, 23 insertions(+) diff --git a/rollup/internal/controller/watcher/bundle_proposer_test.go b/rollup/internal/controller/watcher/bundle_proposer_test.go index 4a0a4219b..a7f69ca81 100644 --- a/rollup/internal/controller/watcher/bundle_proposer_test.go +++ b/rollup/internal/controller/watcher/bundle_proposer_test.go @@ -2,6 +2,7 @@ package watcher import ( "context" + "fmt" "math" "math/big" "testing" @@ -11,6 +12,8 @@ import ( gethTypes "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/params" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gorm.io/gorm" "scroll-tech/common/database" "scroll-tech/common/types" @@ -119,6 +122,24 @@ func testBundleProposerLimitsCodecV4(t *testing.T) { BundleTimeoutSec: tt.bundleTimeoutSec, }, encoding.CodecV4, chainConfig, db, nil) + batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + require.NoError(t, err) + require.Len(t, batches, 3) // genesis batch + batch1 + batch2 + batches = batches[1:] // remove genesis batch + + // simulate batches 1 and 2 being submitted in separate transactions -> need it to be able to propose bundles + err = db.Transaction(func(dbTX *gorm.DB) error { + if err = batchOrm.UpdateCommitTxHashAndRollupStatus(context.Background(), batches[0].Hash, "0xdefdef", types.RollupCommitted, dbTX); err != nil { + return fmt.Errorf("UpdateCommitTxHashAndRollupStatus failed for batch %d: %s, err %v", batches[0].Index, batches[0].Hash, err) + } + + if err = batchOrm.UpdateCommitTxHashAndRollupStatus(context.Background(), batches[1].Hash, "0xabcabc", types.RollupCommitted, dbTX); err != nil { + return fmt.Errorf("UpdateCommitTxHashAndRollupStatus failed for batch %d: %s, err %v", batches[1].Index, batches[1].Hash, err) + } + return nil + }) + require.NoError(t, err) + bup.TryProposeBundle() bundleOrm := orm.NewBundle(db) diff --git a/rollup/internal/orm/orm_test.go b/rollup/internal/orm/orm_test.go index 35f73619a..83a1df5f8 100644 --- a/rollup/internal/orm/orm_test.go +++ b/rollup/internal/orm/orm_test.go @@ -310,6 +310,8 @@ func TestBatchOrm(t *testing.T) { assert.Equal(t, types.GasOracleImported, types.GasOracleStatus(updatedBatch.OracleStatus)) assert.Equal(t, "oracleTxHash", updatedBatch.OracleTxHash) + err = batchOrm.UpdateCommitTxHashAndRollupStatus(context.Background(), batchHash1, "commitTxHash", types.RollupCommitted) + assert.NoError(t, err) err = batchOrm.UpdateCommitTxHashAndRollupStatus(context.Background(), batchHash2, "commitTxHash", types.RollupCommitted) assert.NoError(t, err) updatedBatch, err = batchOrm.GetLatestBatch(context.Background())