mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
Co-authored-by: colinlyguo <651734127@qq.com> Co-authored-by: zimpha <zimpha@gmail.com> Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
136 lines
3.5 KiB
Go
136 lines
3.5 KiB
Go
package l2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
geth_types "github.com/scroll-tech/go-ethereum/core/types"
|
|
"github.com/scroll-tech/go-ethereum/ethclient"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"scroll-tech/common/docker"
|
|
"scroll-tech/common/types"
|
|
|
|
"scroll-tech/bridge/config"
|
|
)
|
|
|
|
var (
|
|
// config
|
|
cfg *config.Config
|
|
|
|
// docker consider handler.
|
|
l1gethImg docker.ImgInstance
|
|
l2gethImg docker.ImgInstance
|
|
dbImg docker.ImgInstance
|
|
|
|
// l2geth client
|
|
l2Cli *ethclient.Client
|
|
|
|
// block trace
|
|
blockTrace1 *geth_types.BlockTrace
|
|
blockTrace2 *geth_types.BlockTrace
|
|
|
|
// batch data
|
|
batchData1 *types.BatchData
|
|
batchData2 *types.BatchData
|
|
)
|
|
|
|
func setupEnv(t *testing.T) (err error) {
|
|
// Load config.
|
|
cfg, err = config.NewConfig("../config.json")
|
|
assert.NoError(t, err)
|
|
|
|
// Create l1geth container.
|
|
l1gethImg = docker.NewTestL1Docker(t)
|
|
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = l1gethImg.Endpoint()
|
|
cfg.L1Config.Endpoint = l1gethImg.Endpoint()
|
|
|
|
// Create l2geth container.
|
|
l2gethImg = docker.NewTestL2Docker(t)
|
|
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = l2gethImg.Endpoint()
|
|
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
|
|
|
|
// Create db container.
|
|
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
|
|
cfg.DBConfig.DSN = dbImg.Endpoint()
|
|
|
|
// Create l2geth client.
|
|
l2Cli, err = ethclient.Dial(cfg.L2Config.Endpoint)
|
|
assert.NoError(t, err)
|
|
|
|
templateBlockTrace1, err := os.ReadFile("../../common/testdata/blockTrace_02.json")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// unmarshal blockTrace
|
|
blockTrace1 = &geth_types.BlockTrace{}
|
|
if err = json.Unmarshal(templateBlockTrace1, blockTrace1); err != nil {
|
|
return err
|
|
}
|
|
|
|
parentBatch1 := &types.BlockBatch{
|
|
Index: 1,
|
|
Hash: "0x0000000000000000000000000000000000000000",
|
|
}
|
|
batchData1 = types.NewBatchData(parentBatch1, []*geth_types.BlockTrace{blockTrace1}, nil)
|
|
|
|
templateBlockTrace2, err := os.ReadFile("../../common/testdata/blockTrace_03.json")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// unmarshal blockTrace
|
|
blockTrace2 = &geth_types.BlockTrace{}
|
|
if err = json.Unmarshal(templateBlockTrace2, blockTrace2); err != nil {
|
|
return err
|
|
}
|
|
parentBatch2 := &types.BlockBatch{
|
|
Index: batchData1.Batch.BatchIndex,
|
|
Hash: batchData1.Hash().Hex(),
|
|
}
|
|
batchData2 = types.NewBatchData(parentBatch2, []*geth_types.BlockTrace{blockTrace2}, nil)
|
|
|
|
fmt.Printf("batchhash1 = %x\n", batchData1.Hash())
|
|
fmt.Printf("batchhash2 = %x\n", batchData2.Hash())
|
|
|
|
return err
|
|
}
|
|
|
|
func free(t *testing.T) {
|
|
if dbImg != nil {
|
|
assert.NoError(t, dbImg.Stop())
|
|
}
|
|
if l1gethImg != nil {
|
|
assert.NoError(t, l1gethImg.Stop())
|
|
}
|
|
if l2gethImg != nil {
|
|
assert.NoError(t, l2gethImg.Stop())
|
|
}
|
|
}
|
|
|
|
func TestFunction(t *testing.T) {
|
|
if err := setupEnv(t); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Run l2 watcher test cases.
|
|
t.Run("TestCreateNewWatcherAndStop", testCreateNewWatcherAndStop)
|
|
t.Run("TestMonitorBridgeContract", testMonitorBridgeContract)
|
|
t.Run("TestFetchMultipleSentMessageInOneBlock", testFetchMultipleSentMessageInOneBlock)
|
|
|
|
// Run l2 relayer test cases.
|
|
t.Run("TestCreateNewRelayer", testCreateNewRelayer)
|
|
t.Run("TestL2RelayerProcessSaveEvents", testL2RelayerProcessSaveEvents)
|
|
t.Run("TestL2RelayerProcessCommittedBatches", testL2RelayerProcessCommittedBatches)
|
|
t.Run("TestL2RelayerSkipBatches", testL2RelayerSkipBatches)
|
|
|
|
// Run batch proposer test cases.
|
|
t.Run("TestBatchProposerProposeBatch", testBatchProposerProposeBatch)
|
|
t.Run("TestBatchProposerGracefulRestart", testBatchProposerGracefulRestart)
|
|
|
|
t.Cleanup(func() {
|
|
free(t)
|
|
})
|
|
}
|