Skip to content

Commit

Permalink
random container port (scroll-tech#47)
Browse files Browse the repository at this point in the history
Co-authored-by: colinlyguo <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2022
1 parent a648073 commit defe1f4
Show file tree
Hide file tree
Showing 30 changed files with 727 additions and 980 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
assets/params*
assets/seed
coverage.txt
14 changes: 4 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,10 @@ pipeline {
sh "docker container prune -f"
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh '''
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/database
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/database/migrate
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/database/docker
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/bridge/abi
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/bridge/l1
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/bridge/l2
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/bridge/sender
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/common/docker
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/coordinator
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/coordinator/verifier
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/database/...
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/bridge/...
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/common/...
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 scroll-tech/coordinator/...
cd ..
'''
script {
Expand Down
3 changes: 2 additions & 1 deletion bridge/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/scroll-tech/go-ethereum/rpc"
"github.com/urfave/cli/v2"

"scroll-tech/database"

"scroll-tech/common/utils"
"scroll-tech/common/version"
"scroll-tech/database"

"scroll-tech/bridge/config"
"scroll-tech/bridge/l1"
Expand Down
2 changes: 1 addition & 1 deletion bridge/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"max_gas_price": 10000000000,
"tx_type": "AccessListTx"
},
"private_key": "abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1"
"private_key": "1212121212121212121212121212121212121212121212121212121212121212"
}
},
"l2_config": {
Expand Down
4 changes: 2 additions & 2 deletions bridge/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module scroll-tech/bridge
go 1.18

require (
github.com/ethereum/go-ethereum v1.10.13
github.com/gorilla/websocket v1.4.2
github.com/jmoiron/sqlx v1.3.5
github.com/orcaman/concurrent-map v1.0.0
github.com/scroll-tech/go-ethereum v1.10.14-0.20221012120556-b3a7c9b6917d
Expand All @@ -18,9 +16,11 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect
github.com/ethereum/go-ethereum v1.10.13 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/iden3/go-iden3-crypto v0.0.12 // indirect
github.com/lib/pq v1.10.6 // indirect
Expand Down
41 changes: 15 additions & 26 deletions bridge/l1/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,41 @@ import (
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"

"scroll-tech/database"

"scroll-tech/bridge/mock"
"scroll-tech/database/migrate"

"scroll-tech/bridge/config"
"scroll-tech/bridge/l1"

"scroll-tech/common/utils"
)
"scroll-tech/database"

var TEST_CONFIG = &mock.TestConfig{
L1GethTestConfig: mock.L1GethTestConfig{
HPort: 0,
WPort: 8570,
},
DbTestconfig: mock.DbTestconfig{
DbName: "testl1relayer_db",
DbPort: 5440,
DB_CONFIG: &database.DBConfig{
DriverName: utils.GetEnvWithDefault("TEST_DB_DRIVER", "postgres"),
DSN: utils.GetEnvWithDefault("TEST_DB_DSN", "postgres://postgres:123456@localhost:5440/testl1relayer_db?sslmode=disable"),
},
},
}
"scroll-tech/common/docker"
)

// TestCreateNewRelayer test create new relayer instance and stop
func TestCreateNewL1Relayer(t *testing.T) {
cfg, err := config.NewConfig("../config.json")
assert.NoError(t, err)
l1docker := mock.NewTestL1Docker(t, TEST_CONFIG)
l1docker := docker.NewTestL1Docker(t)
defer l1docker.Stop()
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = l1docker.Endpoint()
cfg.L1Config.Endpoint = l1docker.Endpoint()

client, err := ethclient.Dial(l1docker.Endpoint())
assert.NoError(t, err)

dbImg := mock.GetDbDocker(t, TEST_CONFIG)
dbImg.Start()
dbImg := docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
defer dbImg.Stop()
db, err := database.NewOrmFactory(TEST_CONFIG.DB_CONFIG)
cfg.DBConfig.DSN = dbImg.Endpoint()

// Create db handler and reset db.
db, err := database.NewOrmFactory(cfg.DBConfig)
assert.NoError(t, err)
assert.NoError(t, migrate.ResetDB(db.GetDB().DB))
defer db.Close()

relayer, err := l1.NewLayer1Relayer(context.Background(), client, 1, db, cfg.L2Config.RelayerConfig)
assert.NoError(t, err)

relayer.Start()

defer relayer.Stop()

relayer.Start()
}
85 changes: 85 additions & 0 deletions bridge/l2/l2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package l2_test

import (
"testing"

"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"

"scroll-tech/common/docker"

"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
)

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)

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)
t.Run("TestTraceHasUnsupportedOpcodes", testTraceHasUnsupportedOpcodes)

// Run l2 relayer test cases.
t.Run("TestCreateNewRelayer", testCreateNewRelayer)
t.Run("TestL2RelayerProcessSaveEvents", testL2RelayerProcessSaveEvents)
t.Run("TestL2RelayerProcessPendingBlocks", testL2RelayerProcessPendingBlocks)
t.Run("TestL2RelayerProcessCommittedBlocks", testL2RelayerProcessCommittedBlocks)

t.Cleanup(func() {
free(t)
})
}
Loading

0 comments on commit defe1f4

Please sign in to comment.