mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-14 16:37:56 -05:00
revert defer database close changes
This commit is contained in:
@@ -34,6 +34,7 @@ func setupL1RelayerDB(t *testing.T) *gorm.DB {
|
||||
// testCreateNewRelayer test create new relayer instance and stop
|
||||
func testCreateNewL1Relayer(t *testing.T) {
|
||||
db := setupL1RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
relayer, err := NewLayer1Relayer(context.Background(), db, cfg.L2Config.RelayerConfig, ServiceTypeL1GasOracle, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, relayer)
|
||||
@@ -41,6 +42,7 @@ func testCreateNewL1Relayer(t *testing.T) {
|
||||
|
||||
func testL1RelayerGasOracleConfirm(t *testing.T) {
|
||||
db := setupL1RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
l1BlockOrm := orm.NewL1Block(db)
|
||||
|
||||
l1Block := []orm.L1Block{
|
||||
@@ -81,6 +83,7 @@ func testL1RelayerGasOracleConfirm(t *testing.T) {
|
||||
|
||||
func testL1RelayerProcessGasPriceOracle(t *testing.T) {
|
||||
db := setupL1RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l1Cfg := cfg.L1Config
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -39,6 +39,7 @@ func setupL2RelayerDB(t *testing.T) *gorm.DB {
|
||||
|
||||
func testCreateNewRelayer(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, cfg.L2Config.RelayerConfig, false, ServiceTypeL2RollupRelayer, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, relayer)
|
||||
@@ -46,6 +47,7 @@ func testCreateNewRelayer(t *testing.T) {
|
||||
|
||||
func testL2RelayerProcessPendingBatches(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2Cfg := cfg.L2Config
|
||||
relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, false, ServiceTypeL2RollupRelayer, nil)
|
||||
@@ -85,6 +87,7 @@ func testL2RelayerProcessPendingBatches(t *testing.T) {
|
||||
|
||||
func testL2RelayerProcessCommittedBatches(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2Cfg := cfg.L2Config
|
||||
relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, false, ServiceTypeL2RollupRelayer, nil)
|
||||
@@ -134,6 +137,7 @@ func testL2RelayerProcessCommittedBatches(t *testing.T) {
|
||||
|
||||
func testL2RelayerFinalizeTimeoutBatches(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2Cfg := cfg.L2Config
|
||||
l2Cfg.RelayerConfig.EnableTestEnvBypassFeatures = true
|
||||
@@ -170,6 +174,7 @@ func testL2RelayerFinalizeTimeoutBatches(t *testing.T) {
|
||||
|
||||
func testL2RelayerCommitConfirm(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
// Create and set up the Layer2 Relayer.
|
||||
l2Cfg := cfg.L2Config
|
||||
@@ -228,6 +233,7 @@ func testL2RelayerCommitConfirm(t *testing.T) {
|
||||
|
||||
func testL2RelayerFinalizeConfirm(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
// Create and set up the Layer2 Relayer.
|
||||
l2Cfg := cfg.L2Config
|
||||
@@ -286,6 +292,7 @@ func testL2RelayerFinalizeConfirm(t *testing.T) {
|
||||
|
||||
func testL2RelayerGasOracleConfirm(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
batch1 := &encoding.Batch{
|
||||
Index: 0,
|
||||
@@ -357,6 +364,7 @@ func testL2RelayerGasOracleConfirm(t *testing.T) {
|
||||
|
||||
func testLayer2RelayerProcessGasPriceOracle(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, cfg.L2Config.RelayerConfig, false, ServiceTypeL2GasOracle, nil)
|
||||
assert.NoError(t, err)
|
||||
@@ -450,6 +458,7 @@ func mockChainMonitorServer(baseURL string) (*http.Server, error) {
|
||||
|
||||
func testGetBatchStatusByIndex(t *testing.T) {
|
||||
db := setupL2RelayerDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2BlockOrm := orm.NewL2Block(db)
|
||||
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2})
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types"
|
||||
"scroll-tech/common/types/encoding"
|
||||
|
||||
@@ -101,6 +102,7 @@ func testBatchProposerLimits(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2BlockOrm := orm.NewL2Block(db)
|
||||
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2})
|
||||
@@ -163,6 +165,7 @@ func testBatchProposerLimits(t *testing.T) {
|
||||
|
||||
func testBatchCommitGasAndCalldataSizeEstimation(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2BlockOrm := orm.NewL2Block(db)
|
||||
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2})
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types/encoding"
|
||||
|
||||
"scroll-tech/rollup/internal/config"
|
||||
@@ -160,6 +161,7 @@ func testChunkProposerLimits(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2BlockOrm := orm.NewL2Block(db)
|
||||
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2})
|
||||
|
||||
@@ -15,7 +15,9 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/rpc"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
commonTypes "scroll-tech/common/types"
|
||||
|
||||
bridgeAbi "scroll-tech/rollup/abi"
|
||||
@@ -23,23 +25,25 @@ import (
|
||||
"scroll-tech/rollup/internal/utils"
|
||||
)
|
||||
|
||||
func setupL1Watcher(t *testing.T) *L1WatcherClient {
|
||||
func setupL1Watcher(t *testing.T) (*L1WatcherClient, *gorm.DB) {
|
||||
db := setupDB(t)
|
||||
client, err := ethclient.Dial(base.L1gethImg.Endpoint())
|
||||
assert.NoError(t, err)
|
||||
l1Cfg := cfg.L1Config
|
||||
watcher := NewL1WatcherClient(context.Background(), client, l1Cfg.StartHeight, l1Cfg.Confirmations, l1Cfg.L1MessageQueueAddress, l1Cfg.RelayerConfig.RollupContractAddress, db, nil)
|
||||
assert.NoError(t, watcher.FetchContractEvent())
|
||||
return watcher
|
||||
return watcher, db
|
||||
}
|
||||
|
||||
func testFetchContractEvent(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
assert.NoError(t, watcher.FetchContractEvent())
|
||||
}
|
||||
|
||||
func testL1WatcherClientFetchBlockHeader(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
convey.Convey("test toBlock < fromBlock", t, func() {
|
||||
var blockHeight uint64
|
||||
if watcher.ProcessedBlockHeight() <= 0 {
|
||||
@@ -110,7 +114,8 @@ func testL1WatcherClientFetchBlockHeader(t *testing.T) {
|
||||
}
|
||||
|
||||
func testL1WatcherClientFetchContractEvent(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
watcher.SetConfirmations(rpc.SafeBlockNumber)
|
||||
convey.Convey("get latest confirmed block number failure", t, func() {
|
||||
@@ -254,7 +259,8 @@ func testL1WatcherClientFetchContractEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func testParseBridgeEventLogsL1QueueTransactionEventSignature(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
logs := []types.Log{
|
||||
{
|
||||
@@ -299,7 +305,8 @@ func testParseBridgeEventLogsL1QueueTransactionEventSignature(t *testing.T) {
|
||||
}
|
||||
|
||||
func testParseBridgeEventLogsL1CommitBatchEventSignature(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
logs := []types.Log{
|
||||
{
|
||||
Topics: []common.Hash{bridgeAbi.L1CommitBatchEventSignature},
|
||||
@@ -340,7 +347,8 @@ func testParseBridgeEventLogsL1CommitBatchEventSignature(t *testing.T) {
|
||||
}
|
||||
|
||||
func testParseBridgeEventLogsL1FinalizeBatchEventSignature(t *testing.T) {
|
||||
watcher := setupL1Watcher(t)
|
||||
watcher, db := setupL1Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
logs := []types.Log{
|
||||
{
|
||||
Topics: []common.Hash{bridgeAbi.L1FinalizeBatchEventSignature},
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/rpc"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
cutils "scroll-tech/common/utils"
|
||||
|
||||
"scroll-tech/rollup/internal/orm"
|
||||
@@ -25,6 +26,7 @@ func setupL2Watcher(t *testing.T) (*L2WatcherClient, *gorm.DB) {
|
||||
|
||||
func testFetchRunningMissingBlocks(t *testing.T) {
|
||||
_, db := setupL2Watcher(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
l2BlockOrm := orm.NewL2Block(db)
|
||||
ok := cutils.TryTimes(10, func() bool {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types"
|
||||
"scroll-tech/common/types/encoding"
|
||||
"scroll-tech/common/types/encoding/codecv0"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
|
||||
func testImportL1GasPrice(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
prepareContracts(t)
|
||||
|
||||
@@ -63,6 +65,7 @@ func testImportL1GasPrice(t *testing.T) {
|
||||
|
||||
func testImportL2GasPrice(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
prepareContracts(t)
|
||||
|
||||
l2Cfg := rollupApp.Config.L2Config
|
||||
|
||||
@@ -10,13 +10,15 @@ import (
|
||||
_ "scroll-tech/rollup/cmd/gas_oracle/app"
|
||||
_ "scroll-tech/rollup/cmd/rollup_relayer/app"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
cutils "scroll-tech/common/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func testProcessStart(t *testing.T) {
|
||||
setupDB(t)
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
rollupApp.RunApp(t, cutils.EventWatcherApp)
|
||||
rollupApp.RunApp(t, cutils.GasOracleApp)
|
||||
@@ -26,7 +28,8 @@ func testProcessStart(t *testing.T) {
|
||||
}
|
||||
|
||||
func testProcessStartEnableMetrics(t *testing.T) {
|
||||
setupDB(t)
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
port, err := rand.Int(rand.Reader, big.NewInt(10000))
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types"
|
||||
"scroll-tech/common/types/encoding"
|
||||
"scroll-tech/common/types/message"
|
||||
@@ -23,6 +24,7 @@ import (
|
||||
|
||||
func testCommitAndFinalizeGenesisBatch(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
prepareContracts(t)
|
||||
|
||||
@@ -50,6 +52,7 @@ func testCommitAndFinalizeGenesisBatch(t *testing.T) {
|
||||
|
||||
func testCommitBatchAndFinalizeBatch(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
prepareContracts(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user