Compare commits

..

11 Commits

Author SHA1 Message Date
vincent
7732b0c3f8 test 1.4 2023-02-28 22:14:34 +08:00
vincent
c9c849a56e try and try 2023-02-28 22:03:26 +08:00
vincent
257bc88a87 make variable 2023-02-28 21:45:16 +08:00
vincent
04552240e3 try to fix 2023-02-28 21:35:07 +08:00
vincent
2aff8a1ad1 test 2023-02-28 21:24:51 +08:00
vincent
f75f4afb60 fix 2023-02-28 21:23:25 +08:00
vincent
f979964d04 fix 2023-02-28 21:11:50 +08:00
vincent
3507c419b4 fix 2023-02-28 21:00:19 +08:00
vincent
8d55e83239 fix 2023-02-28 20:50:44 +08:00
vincent
2d20ee639f fix 2023-02-28 20:42:26 +08:00
vincent
08bf938e19 test 2023-02-28 20:26:38 +08:00
47 changed files with 496 additions and 984 deletions

View File

@@ -24,7 +24,6 @@
"min_gas_price": 0,
"gas_price_diff": 50000
},
"finalize_batch_interval_sec": 0,
"message_sender_private_keys": [
"1212121212121212121212121212121212121212121212121212121212121212"
],
@@ -57,7 +56,6 @@
"min_gas_price": 0,
"gas_price_diff": 50000
},
"finalize_batch_interval_sec": 0,
"message_sender_private_keys": [
"1212121212121212121212121212121212121212121212121212121212121212"
],

View File

@@ -47,8 +47,6 @@ type RelayerConfig struct {
SenderConfig *SenderConfig `json:"sender_config"`
// gas oracle config
GasOracleConfig *GasOracleConfig `json:"gas_oracle_config"`
// The interval in which we send finalize batch transactions.
FinalizeBatchIntervalSec uint64 `json:"finalize_batch_interval_sec"`
// The private key of the relayer
MessageSenderPrivateKeys []*ecdsa.PrivateKey `json:"-"`
GasOracleSenderPrivateKeys []*ecdsa.PrivateKey `json:"-"`

View File

@@ -15,27 +15,42 @@ var (
cfg *config.Config
// docker consider handler.
base *docker.App
l1gethImg docker.ImgInstance
l2gethImg docker.ImgInstance
dbImg docker.ImgInstance
)
func TestMain(m *testing.M) {
base = docker.NewDockerApp()
m.Run()
base.Free()
}
func setupEnv(t *testing.T) {
// Load config.
var err error
cfg, err = config.NewConfig("../config.json")
assert.NoError(t, err)
base.RunImages(t)
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1GethEndpoint()
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2GethEndpoint()
cfg.DBConfig.DSN = base.DBEndpoint()
// 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()
}
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 TestL1(t *testing.T) {
@@ -43,4 +58,8 @@ func TestL1(t *testing.T) {
t.Run("testCreateNewL1Relayer", testCreateNewL1Relayer)
t.Run("testStartWatcher", testStartWatcher)
t.Cleanup(func() {
free(t)
})
}

View File

@@ -18,7 +18,7 @@ func testStartWatcher(t *testing.T) {
assert.NoError(t, migrate.ResetDB(db.GetDB().DB))
defer db.Close()
client, err := ethclient.Dial(base.L1GethEndpoint())
client, err := ethclient.Dial(l1gethImg.Endpoint())
assert.NoError(t, err)
l1Cfg := cfg.L1Config

View File

@@ -20,7 +20,10 @@ var (
// config
cfg *config.Config
base *docker.App
// docker consider handler.
l1gethImg docker.ImgInstance
l2gethImg docker.ImgInstance
dbImg docker.ImgInstance
// l2geth client
l2Cli *ethclient.Client
@@ -39,14 +42,22 @@ func setupEnv(t *testing.T) (err error) {
cfg, err = config.NewConfig("../config.json")
assert.NoError(t, err)
base.RunImages(t)
// Create l1geth container.
l1gethImg = docker.NewTestL1Docker(t)
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = l1gethImg.Endpoint()
cfg.L1Config.Endpoint = l1gethImg.Endpoint()
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1GethEndpoint()
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2GethEndpoint()
cfg.DBConfig.DSN = base.DBEndpoint()
// 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 = base.L2Client()
l2Cli, err = ethclient.Dial(cfg.L2Config.Endpoint)
assert.NoError(t, err)
templateBlockTrace1, err := os.ReadFile("../../common/testdata/blockTrace_02.json")
@@ -86,12 +97,16 @@ func setupEnv(t *testing.T) (err error) {
return err
}
func TestMain(m *testing.M) {
base = docker.NewDockerApp()
m.Run()
base.Free()
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) {
@@ -114,4 +129,7 @@ func TestFunction(t *testing.T) {
t.Run("TestBatchProposerProposeBatch", testBatchProposerProposeBatch)
t.Run("TestBatchProposerGracefulRestart", testBatchProposerGracefulRestart)
t.Cleanup(func() {
free(t)
})
}

View File

@@ -354,29 +354,22 @@ func (r *Layer2Relayer) ProcessCommittedBatches() {
}
// batches are sorted by batch index in increasing order
batchHashes, err := r.db.GetCommittedBatches(1)
batches, err := r.db.GetCommittedBatches(1)
if err != nil {
log.Error("Failed to fetch committed L2 batches", "err", err)
return
}
if len(batchHashes) == 0 {
if len(batches) == 0 {
return
}
hash := batchHashes[0]
hash := batches[0]
// @todo add support to relay multiple batches
batches, err := r.db.GetBlockBatches(map[string]interface{}{"hash": hash}, "LIMIT 1")
status, err := r.db.GetProvingStatusByHash(hash)
if err != nil {
log.Error("Failed to fetch committed L2 batch", "hash", hash, "err", err)
log.Error("GetProvingStatusByHash failed", "hash", hash, "err", err)
return
}
if len(batches) == 0 {
log.Error("Unexpected result for GetBlockBatches", "hash", hash, "len", 0)
return
}
batch := batches[0]
status := batch.ProvingStatus
switch status {
case types.ProvingTaskUnassigned, types.ProvingTaskAssigned:
@@ -399,34 +392,6 @@ func (r *Layer2Relayer) ProcessCommittedBatches() {
log.Info("Start to roll up zk proof", "hash", hash)
success := false
previousBatch, err := r.db.GetLatestFinalizingOrFinalizedBatch()
// skip submitting proof
if err == nil && uint64(batch.CreatedAt.Sub(*previousBatch.CreatedAt).Seconds()) < r.cfg.FinalizeBatchIntervalSec {
log.Info(
"Not enough time passed, skipping",
"hash", hash,
"createdAt", batch.CreatedAt,
"lastFinalizingHash", previousBatch.Hash,
"lastFinalizingStatus", previousBatch.RollupStatus,
"lastFinalizingCreatedAt", previousBatch.CreatedAt,
)
if err = r.db.UpdateRollupStatus(r.ctx, hash, types.RollupFinalizationSkipped); err != nil {
log.Warn("UpdateRollupStatus failed", "hash", hash, "err", err)
} else {
success = true
}
return
}
// handle unexpected db error
if err != nil && err.Error() != "sql: no rows in result set" {
log.Error("Failed to get latest finalized batch", "err", err)
return
}
defer func() {
// TODO: need to revisit this and have a more fine-grained error handling
if !success {

View File

@@ -1,69 +0,0 @@
package sender
import (
"math/big"
"sync/atomic"
"github.com/scroll-tech/go-ethereum"
"github.com/scroll-tech/go-ethereum/accounts/abi/bind"
"github.com/scroll-tech/go-ethereum/common"
)
func (s *Sender) estimateLegacyGas(auth *bind.TransactOpts, contract *common.Address, value *big.Int, input []byte) (*FeeData, error) {
gasPrice, err := s.client.SuggestGasPrice(s.ctx)
if err != nil {
return nil, err
}
gasLimit, err := s.estimateGasLimit(auth, contract, input, gasPrice, nil, nil, value)
if err != nil {
return nil, err
}
return &FeeData{
gasPrice: gasPrice,
gasLimit: gasLimit,
}, nil
}
func (s *Sender) estimateDynamicGas(auth *bind.TransactOpts, contract *common.Address, value *big.Int, input []byte) (*FeeData, error) {
gasTipCap, err := s.client.SuggestGasTipCap(s.ctx)
if err != nil {
return nil, err
}
baseFee := big.NewInt(0)
if feeGas := atomic.LoadUint64(&s.baseFeePerGas); feeGas != 0 {
baseFee.SetUint64(feeGas)
}
gasFeeCap := new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(baseFee, big.NewInt(2)),
)
gasLimit, err := s.estimateGasLimit(auth, contract, input, nil, gasTipCap, gasFeeCap, value)
if err != nil {
return nil, err
}
return &FeeData{
gasLimit: gasLimit,
gasTipCap: gasTipCap,
gasFeeCap: gasFeeCap,
}, nil
}
func (s *Sender) estimateGasLimit(opts *bind.TransactOpts, contract *common.Address, input []byte, gasPrice, gasTipCap, gasFeeCap, value *big.Int) (uint64, error) {
msg := ethereum.CallMsg{
From: opts.From,
To: contract,
GasPrice: gasPrice,
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Value: value,
Data: input,
}
gasLimit, err := s.client.EstimateGas(s.ctx, msg)
if err != nil {
return 0, err
}
gasLimit = gasLimit * 15 / 10 // 50% extra gas to void out of gas error
return gasLimit, nil
}

View File

@@ -12,8 +12,10 @@ import (
"sync/atomic"
"time"
geth "github.com/scroll-tech/go-ethereum"
"github.com/scroll-tech/go-ethereum/accounts/abi/bind"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/math"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/scroll-tech/go-ethereum/log"
@@ -151,10 +153,37 @@ func (s *Sender) NumberOfAccounts() int {
}
func (s *Sender) getFeeData(auth *bind.TransactOpts, target *common.Address, value *big.Int, data []byte) (*FeeData, error) {
if s.config.TxType == DynamicFeeTxType {
return s.estimateDynamicGas(auth, target, value, data)
// estimate gas limit
gasLimit, err := s.client.EstimateGas(s.ctx, geth.CallMsg{From: auth.From, To: target, Value: value, Data: data})
if err != nil {
return nil, err
}
return s.estimateLegacyGas(auth, target, value, data)
gasLimit = gasLimit * 15 / 10 // 50% extra gas to void out of gas error
// @todo change it when Scroll enable EIP1559
if s.config.TxType != DynamicFeeTxType {
// estimate gas price
var gasPrice *big.Int
gasPrice, err = s.client.SuggestGasPrice(s.ctx)
if err != nil {
return nil, err
}
return &FeeData{
gasPrice: gasPrice,
gasLimit: gasLimit,
}, nil
}
gasTipCap, err := s.client.SuggestGasTipCap(s.ctx)
if err != nil {
return nil, err
}
// Make sure feeCap is bigger than txpool's gas price. 1000000000 is l2geth's default pool.gas value.
baseFee := atomic.LoadUint64(&s.baseFeePerGas)
maxFeePerGas := math.BigMax(big.NewInt(int64(baseFee)), big.NewInt(1000000000))
return &FeeData{
gasFeeCap: math.BigMax(maxFeePerGas, gasTipCap),
gasTipCap: math.BigMin(maxFeePerGas, gasTipCap),
gasLimit: gasLimit,
}, nil
}
// SendTransaction send a signed L2tL1 transaction.

View File

@@ -28,28 +28,21 @@ const TXBatch = 50
var (
privateKeys []*ecdsa.PrivateKey
cfg *config.Config
base *docker.App
l2gethImg docker.ImgInstance
)
func TestMain(m *testing.M) {
base = docker.NewDockerApp()
m.Run()
base.Free()
}
func setupEnv(t *testing.T) {
var err error
cfg, err = config.NewConfig("../config.json")
assert.NoError(t, err)
base.RunImages(t)
priv, err := crypto.HexToECDSA("1212121212121212121212121212121212121212121212121212121212121212")
assert.NoError(t, err)
// Load default private key.
privateKeys = []*ecdsa.PrivateKey{priv}
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2GethEndpoint()
l2gethImg = docker.NewTestL2Docker(t)
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = l2gethImg.Endpoint()
}
func TestSender(t *testing.T) {
@@ -59,6 +52,11 @@ func TestSender(t *testing.T) {
t.Run("test 1 account sender", func(t *testing.T) { testBatchSender(t, 1) })
t.Run("test 3 account sender", func(t *testing.T) { testBatchSender(t, 3) })
t.Run("test 8 account sender", func(t *testing.T) { testBatchSender(t, 8) })
// Teardown
t.Cleanup(func() {
assert.NoError(t, l2gethImg.Stop())
})
}
func testBatchSender(t *testing.T, batchSize int) {

View File

@@ -26,7 +26,11 @@ var (
// private key
privateKey *ecdsa.PrivateKey
base *docker.App
// docker consider handler.
l1gethImg docker.ImgInstance
l2gethImg docker.ImgInstance
dbImg docker.ImgInstance
// clients
l1Client *ethclient.Client
@@ -49,14 +53,6 @@ var (
l2MessengerAddress common.Address
)
func TestMain(m *testing.M) {
base = docker.NewDockerApp()
m.Run()
base.Free()
}
func setupEnv(t *testing.T) {
var err error
privateKey, err = crypto.ToECDSA(common.FromHex("1212121212121212121212121212121212121212121212121212121212121212"))
@@ -79,18 +75,20 @@ func setupEnv(t *testing.T) {
cfg.L2Config.RelayerConfig.MessageSenderPrivateKeys = []*ecdsa.PrivateKey{messagePrivateKey}
cfg.L2Config.RelayerConfig.RollupSenderPrivateKeys = []*ecdsa.PrivateKey{rollupPrivateKey}
cfg.L2Config.RelayerConfig.GasOracleSenderPrivateKeys = []*ecdsa.PrivateKey{gasOraclePrivateKey}
base.RunImages(t)
// Create l1geth container.
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1GethEndpoint()
cfg.L1Config.Endpoint = base.L1GethEndpoint()
l1gethImg = docker.NewTestL1Docker(t)
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = l1gethImg.Endpoint()
cfg.L1Config.Endpoint = l1gethImg.Endpoint()
// Create l2geth container.
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2GethEndpoint()
cfg.L2Config.Endpoint = base.L2GethEndpoint()
l2gethImg = docker.NewTestL2Docker(t)
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = l2gethImg.Endpoint()
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
// Create db container.
cfg.DBConfig.DSN = base.DBEndpoint()
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
cfg.DBConfig.DSN = dbImg.Endpoint()
// Create l1geth and l2geth client.
l1Client, err = ethclient.Dial(cfg.L1Config.Endpoint)
@@ -146,6 +144,18 @@ func transferEther(t *testing.T, auth *bind.TransactOpts, client *ethclient.Clie
}
}
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 prepareContracts(t *testing.T) {
var err error
var tx *types.Transaction
@@ -207,4 +217,7 @@ func TestFunction(t *testing.T) {
t.Run("TestImportL1GasPrice", testImportL1GasPrice)
t.Run("TestImportL2GasPrice", testImportL2GasPrice)
t.Cleanup(func() {
free(t)
})
}

View File

@@ -41,38 +41,21 @@ pipeline {
if (TAGNAME == ""){
return;
}
def brigeImageName = "scrolltech/bridge:$TAGNAME"
sh "docker login --username=$dockerUser --password=$dockerPassword"
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
script {
try {
sh "docker manifest inspect scrolltech/bridge:$TAGNAME > /dev/null"
} catch (e) {
// only build if the tag non existed
//sh "docker login --username=${dockerUser} --password=${dockerPassword}"
sh "make -C bridge docker"
sh "docker tag scrolltech/bridge:latest scrolltech/bridge:${TAGNAME}"
sh "docker push scrolltech/bridge:${TAGNAME}"
throw e
}
}
}
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
script {
try {
sh "docker manifest inspect scrolltech/coordinator:$TAGNAME > /dev/null"
} catch (e) {
// only build if the tag non existed
//sh "docker login --username=${dockerUser} --password=${dockerPassword}"
sh "make -C coordinator docker"
sh "docker tag scrolltech/coordinator:latest scrolltech/coordinator:${TAGNAME}"
sh "docker push scrolltech/coordinator:${TAGNAME}"
throw e
}
}
}
sh "echo $brigeImageName"
sh "docker manifest inspect scrolltech/bridge:$TAGNAME > /dev/null"
sh "echo $?"
// sh "docker login --username=${dockerUser} --password=${dockerPassword}"
// sh "make -C bridge docker"
// sh "make -C coordinator docker"
// sh "docker tag scrolltech/bridge:latest scrolltech/bridge:${TAGNAME}"
// sh "docker tag scrolltech/coordinator:latest scrolltech/coordinator:${TAGNAME}"
// sh "docker push scrolltech/bridge:${TAGNAME}"
// sh "docker push scrolltech/coordinator:${TAGNAME}"
}
}
}
}
}
}
}

View File

@@ -45,7 +45,6 @@ func (t *Cmd) WaitExit() {
// Send interrupt signal.
t.mu.Lock()
_ = t.cmd.Process.Signal(os.Interrupt)
_, _ = t.cmd.Process.Wait()
t.mu.Unlock()
}

View File

@@ -1,234 +0,0 @@
package docker
import (
"context"
"crypto/rand"
"encoding/json"
"fmt"
"math/big"
"os"
"testing"
"time"
"github.com/jmoiron/sqlx"
"github.com/modern-go/reflect2"
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"scroll-tech/database"
"scroll-tech/common/cmd"
"scroll-tech/common/utils"
)
var (
l1StartPort = 10000
l2StartPort = 20000
dbStartPort = 30000
)
// App is collection struct of runtime docker images
type App struct {
l1gethImg ImgInstance
l2gethImg ImgInstance
dbImg ImgInstance
dbConfig *database.DBConfig
dbFile string
// common time stamp.
timestamp int
}
// NewDockerApp returns new instance of dokerApp struct
func NewDockerApp() *App {
timestamp := time.Now().Nanosecond()
return &App{
timestamp: timestamp,
dbFile: fmt.Sprintf("/tmp/%d_db-config.json", timestamp),
}
}
// RunImages runs all images togather
func (b *App) RunImages(t *testing.T) {
b.runDBImage(t)
b.runL1Geth(t)
b.runL2Geth(t)
}
func (b *App) runDBImage(t *testing.T) {
if b.dbImg != nil {
return
}
b.dbImg = newTestDBDocker(t, "postgres")
if err := b.mockDBConfig(); err != nil {
_ = b.dbImg.Stop()
b.dbImg = nil
_ = os.Remove(b.dbFile)
t.Fatal(err)
}
}
// RunDBApp runs DB app with command
func (b *App) RunDBApp(t *testing.T, option, keyword string) {
args := []string{option, "--config", b.dbFile}
app := cmd.NewCmd(t, "db_cli-test", args...)
defer app.WaitExit()
// Wait expect result.
app.ExpectWithTimeout(true, time.Second*3, keyword)
app.RunApp(nil)
}
// Free clear all running images
func (b *App) Free() {
if b.l1gethImg != nil {
_ = b.l1gethImg.Stop()
b.l1gethImg = nil
}
if b.l2gethImg != nil {
_ = b.l2gethImg.Stop()
b.l2gethImg = nil
}
if b.dbImg != nil {
_ = b.dbImg.Stop()
b.dbImg = nil
_ = os.Remove(b.dbFile)
}
}
// L1GethEndpoint returns l1gethimg endpoint
func (b *App) L1GethEndpoint() string {
if b.l1gethImg != nil {
return b.l1gethImg.Endpoint()
}
return ""
}
// L2GethEndpoint returns l2gethimg endpoint
func (b *App) L2GethEndpoint() string {
if b.l2gethImg != nil {
return b.l2gethImg.Endpoint()
}
return ""
}
// DBEndpoint returns the endpoint of the dbimg
func (b *App) DBEndpoint() string {
return b.dbImg.Endpoint()
}
func (b *App) runL1Geth(t *testing.T) {
if b.l1gethImg != nil {
return
}
b.l1gethImg = newTestL1Docker(t)
}
// L1Client returns a ethclient by dialing running l1geth
func (b *App) L1Client() (*ethclient.Client, error) {
if b.l1gethImg == nil || reflect2.IsNil(b.l1gethImg) {
return nil, fmt.Errorf("l1 geth is not running")
}
client, err := ethclient.Dial(b.l1gethImg.Endpoint())
if err != nil {
return nil, err
}
return client, nil
}
func (b *App) runL2Geth(t *testing.T) {
if b.l2gethImg != nil {
return
}
b.l2gethImg = newTestL2Docker(t)
}
// L2Client returns a ethclient by dialing running l2geth
func (b *App) L2Client() (*ethclient.Client, error) {
if b.l2gethImg == nil || reflect2.IsNil(b.l2gethImg) {
return nil, fmt.Errorf("l2 geth is not running")
}
client, err := ethclient.Dial(b.l2gethImg.Endpoint())
if err != nil {
return nil, err
}
return client, nil
}
func (b *App) mockDBConfig() error {
if b.dbConfig == nil {
b.dbConfig = &database.DBConfig{
DSN: "",
DriverName: "postgres",
MaxOpenNum: 200,
MaxIdleNum: 20,
}
}
if b.dbImg != nil {
b.dbConfig.DSN = b.dbImg.Endpoint()
}
data, err := json.Marshal(b.dbConfig)
if err != nil {
return err
}
return os.WriteFile(b.dbFile, data, 0644) //nolint:gosec
}
func newTestL1Docker(t *testing.T) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgL1geth := NewImgGeth(t, "scroll_l1geth", "", "", 0, l1StartPort+int(id.Int64()))
assert.NoError(t, imgL1geth.Start())
// try 3 times to get chainID until is ok.
utils.TryTimes(3, func() bool {
client, _ := ethclient.Dial(imgL1geth.Endpoint())
if client != nil {
if _, err := client.ChainID(context.Background()); err == nil {
return true
}
}
return false
})
return imgL1geth
}
func newTestL2Docker(t *testing.T) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgL2geth := NewImgGeth(t, "scroll_l2geth", "", "", 0, l2StartPort+int(id.Int64()))
assert.NoError(t, imgL2geth.Start())
// try 3 times to get chainID until is ok.
utils.TryTimes(3, func() bool {
client, _ := ethclient.Dial(imgL2geth.Endpoint())
if client != nil {
if _, err := client.ChainID(context.Background()); err == nil {
return true
}
}
return false
})
return imgL2geth
}
func newTestDBDocker(t *testing.T, driverName string) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgDB := NewImgDB(t, driverName, "123456", "test_db", dbStartPort+int(id.Int64()))
assert.NoError(t, imgDB.Start())
// try 5 times until the db is ready.
utils.TryTimes(5, func() bool {
db, _ := sqlx.Open(driverName, imgDB.Endpoint())
if db != nil {
return db.Ping() == nil
}
return false
})
return imgDB
}

View File

@@ -1,4 +1,4 @@
package docker_test
package docker
import (
"context"
@@ -6,36 +6,13 @@ import (
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" //nolint:golint
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
_ "scroll-tech/database/cmd/app"
"scroll-tech/common/docker"
)
var (
base *docker.App
)
func TestMain(m *testing.M) {
base = docker.NewDockerApp()
m.Run()
base.Free()
}
func TestStartProcess(t *testing.T) {
base.RunImages(t)
// migrate db.
base.RunDBApp(t, "reset", "successful to reset")
base.RunDBApp(t, "migrate", "current version:")
}
func TestDocker(t *testing.T) {
base.RunImages(t)
t.Parallel()
t.Run("testL1Geth", testL1Geth)
t.Run("testL2Geth", testL2Geth)
t.Run("testDB", testDB)
@@ -45,7 +22,10 @@ func testL1Geth(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := base.L1Client()
img := NewTestL1Docker(t)
defer img.Stop()
client, err := ethclient.Dial(img.Endpoint())
assert.NoError(t, err)
chainID, err := client.ChainID(ctx)
@@ -57,7 +37,10 @@ func testL2Geth(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := base.L2Client()
img := NewTestL2Docker(t)
defer img.Stop()
client, err := ethclient.Dial(img.Endpoint())
assert.NoError(t, err)
chainID, err := client.ChainID(ctx)
@@ -67,8 +50,10 @@ func testL2Geth(t *testing.T) {
func testDB(t *testing.T) {
driverName := "postgres"
dbImg := NewTestDBDocker(t, driverName)
defer dbImg.Stop()
db, err := sqlx.Open(driverName, base.DBEndpoint())
db, err := sqlx.Open(driverName, dbImg.Endpoint())
assert.NoError(t, err)
assert.NoError(t, db.Ping())
}

78
common/docker/mock.go Normal file
View File

@@ -0,0 +1,78 @@
package docker
import (
"context"
"crypto/rand"
"math/big"
"testing"
"github.com/jmoiron/sqlx"
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"scroll-tech/common/utils"
)
var (
l1StartPort = 10000
l2StartPort = 20000
dbStartPort = 30000
)
// NewTestL1Docker starts and returns l1geth docker
func NewTestL1Docker(t *testing.T) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgL1geth := NewImgGeth(t, "scroll_l1geth", "", "", 0, l1StartPort+int(id.Int64()))
assert.NoError(t, imgL1geth.Start())
// try 3 times to get chainID until is ok.
utils.TryTimes(3, func() bool {
client, _ := ethclient.Dial(imgL1geth.Endpoint())
if client != nil {
if _, err := client.ChainID(context.Background()); err == nil {
return true
}
}
return false
})
return imgL1geth
}
// NewTestL2Docker starts and returns l2geth docker
func NewTestL2Docker(t *testing.T) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgL2geth := NewImgGeth(t, "scroll_l2geth", "", "", 0, l2StartPort+int(id.Int64()))
assert.NoError(t, imgL2geth.Start())
// try 3 times to get chainID until is ok.
utils.TryTimes(3, func() bool {
client, _ := ethclient.Dial(imgL2geth.Endpoint())
if client != nil {
if _, err := client.ChainID(context.Background()); err == nil {
return true
}
}
return false
})
return imgL2geth
}
// NewTestDBDocker starts and returns database docker
func NewTestDBDocker(t *testing.T, driverName string) ImgInstance {
id, _ := rand.Int(rand.Reader, big.NewInt(2000))
imgDB := NewImgDB(t, driverName, "123456", "test_db", dbStartPort+int(id.Int64()))
assert.NoError(t, imgDB.Start())
// try 5 times until the db is ready.
utils.TryTimes(5, func() bool {
db, _ := sqlx.Open(driverName, imgDB.Endpoint())
if db != nil {
return db.Ping() == nil
}
return false
})
return imgDB
}

View File

@@ -8,7 +8,6 @@ require (
github.com/lib/pq v1.10.6
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.16
github.com/modern-go/reflect2 v1.0.1
github.com/orcaman/concurrent-map v1.0.0
github.com/scroll-tech/go-ethereum v1.10.14-0.20230220082843-ec9254b0b1c6
github.com/stretchr/testify v1.8.0
@@ -56,7 +55,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect

View File

@@ -335,9 +335,7 @@ github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjU
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI=
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=

View File

@@ -368,9 +368,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae"
[[package]]
name = "bounded-collections"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de2aff4807e40f478132150d80b031f2461d88f061851afcab537d7600c24120"
checksum = "a071c348a5ef6da1d3a87166b408170b46002382b1dda83992b5c2208cefb370"
dependencies = [
"log",
"parity-scale-codec",
@@ -2902,9 +2902,9 @@ dependencies = [
[[package]]
name = "parity-scale-codec"
version = "3.3.0"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed"
checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac"
dependencies = [
"arrayvec 0.7.2",
"bitvec 1.0.1",
@@ -5014,7 +5014,7 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "types"
version = "0.1.0"
source = "git+https://github.com/scroll-tech/scroll-zkevm?branch=goerli-0215#1f7a3c7da2370860087555a11346bd5d96f609fd"
source = "git+https://github.com/scroll-tech/scroll-zkevm?branch=goerli-0215#d0d3338663a0b3eee51e9d044ab96a7899d70252"
dependencies = [
"base64 0.13.0",
"blake2",
@@ -5682,7 +5682,7 @@ dependencies = [
[[package]]
name = "zkevm"
version = "0.1.0"
source = "git+https://github.com/scroll-tech/scroll-zkevm?branch=goerli-0215#1f7a3c7da2370860087555a11346bd5d96f609fd"
source = "git+https://github.com/scroll-tech/scroll-zkevm?branch=goerli-0215#d0d3338663a0b3eee51e9d044ab96a7899d70252"
dependencies = [
"anyhow",
"blake2",

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "alpha-v1.17"
var tag = "alpha-v1.11"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -1,30 +0,0 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { WETH9 } from "../../src/L2/predeploys/WETH9.sol";
contract DeployWeth is Script {
address L1_WETH_ADDR = vm.envAddress("L1_WETH_ADDR");
address L2_WETH_ADDR = vm.envAddress("L2_WETH_ADDR");
function run() external {
// deploy weth only if we're running a private L1 network
if (L1_WETH_ADDR == address(0)) {
uint256 L1_WETH_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_WETH_DEPLOYER_PRIVATE_KEY");
vm.startBroadcast(L1_WETH_DEPLOYER_PRIVATE_KEY);
WETH9 weth = new WETH9();
L1_WETH_ADDR = address(weth);
vm.stopBroadcast();
}
logAddress("L1_WETH_ADDR", L1_WETH_ADDR);
logAddress("L2_WETH_ADDR", L2_WETH_ADDR);
}
function logAddress(string memory name, address addr) internal view {
console.log(string(abi.encodePacked(name, "=", vm.toString(address(addr)))));
}
}

View File

@@ -105,21 +105,9 @@ contract L1ScrollMessenger is PausableUpgradeable, ScrollMessengerBase, IL1Scrol
// record the message hash for future use.
bytes32 _xDomainCalldataHash = keccak256(_xDomainCalldata);
// normally this won't happen, since each message has different nonce, but just in case.
require(!isL1MessageSent[_xDomainCalldataHash], "Duplicated message");
isL1MessageSent[_xDomainCalldataHash] = true;
emit SentMessage(msg.sender, _to, _value, _messageNonce, _gasLimit, _message);
// refund fee to tx.origin
unchecked {
uint256 _refund = msg.value - _fee - _value;
if (_refund > 0) {
(bool _success, ) = tx.origin.call{ value: _refund }("");
require(_success, "Failed to refund the fee");
}
}
}
/// @inheritdoc IL1ScrollMessenger

View File

@@ -175,29 +175,19 @@ contract L2ScrollMessenger is ScrollMessengerBase, PausableUpgradeable, IL2Scrol
uint256 _fee = _gasLimit * IL1GasPriceOracle(gasOracle).l1BaseFee();
require(msg.value >= _value + _fee, "Insufficient msg.value");
if (_fee > 0) {
(bool _success, ) = feeVault.call{ value: _fee }("");
(bool _success, ) = feeVault.call{ value: msg.value - _value }("");
require(_success, "Failed to deduct the fee");
}
uint256 _nonce = L2MessageQueue(messageQueue).nextMessageIndex();
bytes32 _xDomainCalldataHash = keccak256(_encodeXDomainCalldata(msg.sender, _to, _value, _nonce, _message));
// normally this won't happen, since each message has different nonce, but just in case.
require(!isL2MessageSent[_xDomainCalldataHash], "Duplicated message");
isL2MessageSent[_xDomainCalldataHash] = true;
L2MessageQueue(messageQueue).appendMessage(_xDomainCalldataHash);
emit SentMessage(msg.sender, _to, _value, _nonce, _gasLimit, _message);
// refund fee to tx.origin
unchecked {
uint256 _refund = msg.value - _fee - _value;
if (_refund > 0) {
(bool _success, ) = tx.origin.call{ value: _refund }("");
require(_success, "Failed to refund the fee");
}
}
}
/// @inheritdoc IL2ScrollMessenger
@@ -272,9 +262,7 @@ contract L2ScrollMessenger is ScrollMessengerBase, PausableUpgradeable, IL2Scrol
bytes memory _message,
bytes32 _xDomainCalldataHash
) internal {
// @todo check more `_to` address to avoid attack.
require(_to != messageQueue, "Forbid to call message queue");
require(_to != address(this), "Forbid to call self");
// @todo check `_to` address to avoid attack.
// @note This usually will never happen, just in case.
require(_from != xDomainMessageSender, "Invalid message sender");

View File

@@ -342,18 +342,18 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
hevm.expectRevert("no corresponding l2 token");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l1Token), address(l2Token));
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -377,9 +377,9 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -421,18 +421,18 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
hevm.expectRevert("no corresponding l2 token");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l1Token), address(l2Token));
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -456,9 +456,9 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -501,30 +501,18 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
hevm.expectRevert("no corresponding l2 token");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l1Token), address(l2Token));
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -548,21 +536,9 @@ contract L1CustomERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -623,7 +623,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
gateway.depositERC1155{ value: feeToPay + extraValue }(address(l1Token), tokenId, amount, gasLimit);
gateway.depositERC1155{ value: feeToPay }(address(l1Token), tokenId, amount, gasLimit);
} else {
hevm.expectRevert("token not supported");
gateway.depositERC1155(address(l1Token), tokenId, amount, gasLimit);
@@ -649,7 +649,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway), tokenId);
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.depositERC1155{ value: feeToPay + extraValue }(address(l1Token), tokenId, amount, gasLimit);
gateway.depositERC1155{ value: feeToPay }(address(l1Token), tokenId, amount, gasLimit);
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway), tokenId));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
assertBoolEq(true, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
@@ -691,7 +691,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
gateway.depositERC1155{ value: feeToPay + extraValue }(address(l1Token), recipient, tokenId, amount, gasLimit);
gateway.depositERC1155{ value: feeToPay }(address(l1Token), recipient, tokenId, amount, gasLimit);
} else {
hevm.expectRevert("token not supported");
gateway.depositERC1155(address(l1Token), tokenId, amount, gasLimit);
@@ -717,7 +717,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway), tokenId);
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.depositERC1155{ value: feeToPay + extraValue }(address(l1Token), recipient, tokenId, amount, gasLimit);
gateway.depositERC1155{ value: feeToPay }(address(l1Token), recipient, tokenId, amount, gasLimit);
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway), tokenId));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
assertBoolEq(true, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
@@ -800,7 +800,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
}
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.batchDepositERC1155{ value: feeToPay + extraValue }(address(l1Token), _tokenIds, _amounts, gasLimit);
gateway.batchDepositERC1155{ value: feeToPay }(address(l1Token), _tokenIds, _amounts, gasLimit);
for (uint256 i = 0; i < tokenCount; i++) {
assertEq(gatewayBalances[i] + amount, l1Token.balanceOf(address(gateway), i));
}
@@ -885,13 +885,7 @@ contract L1ERC1155GatewayTest is L1GatewayTestBase, ERC1155TokenReceiver {
}
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.batchDepositERC1155{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
_tokenIds,
_amounts,
gasLimit
);
gateway.batchDepositERC1155{ value: feeToPay }(address(l1Token), recipient, _tokenIds, _amounts, gasLimit);
for (uint256 i = 0; i < tokenCount; i++) {
assertEq(gatewayBalances[i] + amount, l1Token.balanceOf(address(gateway), i));
}

View File

@@ -602,7 +602,7 @@ contract L1ERC721GatewayTest is L1GatewayTestBase {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway));
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.depositERC721{ value: feeToPay + extraValue }(address(l1Token), tokenId, gasLimit);
gateway.depositERC721{ value: feeToPay }(address(l1Token), tokenId, gasLimit);
assertEq(address(gateway), l1Token.ownerOf(tokenId));
assertEq(1 + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -665,7 +665,7 @@ contract L1ERC721GatewayTest is L1GatewayTestBase {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway));
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.depositERC721{ value: feeToPay + extraValue }(address(l1Token), recipient, tokenId, gasLimit);
gateway.depositERC721{ value: feeToPay }(address(l1Token), recipient, tokenId, gasLimit);
assertEq(address(gateway), l1Token.ownerOf(tokenId));
assertEq(1 + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -737,7 +737,7 @@ contract L1ERC721GatewayTest is L1GatewayTestBase {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway));
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.batchDepositERC721{ value: feeToPay + extraValue }(address(l1Token), _tokenIds, gasLimit);
gateway.batchDepositERC721{ value: feeToPay }(address(l1Token), _tokenIds, gasLimit);
for (uint256 i = 0; i < tokenCount; i++) {
assertEq(l1Token.ownerOf(i), address(gateway));
}
@@ -812,7 +812,7 @@ contract L1ERC721GatewayTest is L1GatewayTestBase {
uint256 gatewayBalance = l1Token.balanceOf(address(gateway));
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
gateway.batchDepositERC721{ value: feeToPay + extraValue }(address(l1Token), recipient, _tokenIds, gasLimit);
gateway.batchDepositERC721{ value: feeToPay }(address(l1Token), recipient, _tokenIds, gasLimit);
for (uint256 i = 0; i < tokenCount; i++) {
assertEq(l1Token.ownerOf(i), address(gateway));
}

View File

@@ -192,8 +192,12 @@ contract L1ETHGatewayTest is L1GatewayTestBase {
uint256 amount,
bytes memory dataToCall
) public {
hevm.assume(recipient.code.length == 0);
hevm.assume(uint256(uint160(recipient)) > 100); // ignore some precompile contracts
uint256 size;
assembly {
size := extcodesize(recipient)
}
hevm.assume(size == 0);
hevm.assume(recipient != address(0));
amount = bound(amount, 1, address(this).balance / 2);
@@ -301,9 +305,9 @@ contract L1ETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositETH{ value: amount + feeToPay + extraValue }(amount, gasLimit);
router.depositETH{ value: amount + feeToPay }(amount, gasLimit);
} else {
gateway.depositETH{ value: amount + feeToPay + extraValue }(amount, gasLimit);
gateway.depositETH{ value: amount + feeToPay }(amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -370,9 +374,9 @@ contract L1ETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositETH{ value: amount + feeToPay + extraValue }(recipient, amount, gasLimit);
router.depositETH{ value: amount + feeToPay }(recipient, amount, gasLimit);
} else {
gateway.depositETH{ value: amount + feeToPay + extraValue }(recipient, amount, gasLimit);
gateway.depositETH{ value: amount + feeToPay }(recipient, amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -440,9 +444,9 @@ contract L1ETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositETHAndCall{ value: amount + feeToPay + extraValue }(recipient, amount, dataToCall, gasLimit);
router.depositETHAndCall{ value: amount + feeToPay }(recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositETHAndCall{ value: amount + feeToPay + extraValue }(recipient, amount, dataToCall, gasLimit);
gateway.depositETHAndCall{ value: amount + feeToPay }(recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -34,9 +34,6 @@ abstract contract L1GatewayTestBase is DSTestPlus {
event RelayedMessage(bytes32 indexed messageHash);
event FailedRelayedMessage(bytes32 indexed messageHash);
// pay 0.1 extra ETH to test refund
uint256 internal constant extraValue = 1e17;
L1ScrollMessenger internal l1Messenger;
L1MessageQueue internal messageQueue;
L2GasPriceOracle internal gasOracle;

View File

@@ -418,9 +418,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -444,9 +444,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -489,9 +489,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -515,9 +515,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -561,21 +561,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
}
} else {
// emit QueueTransaction from L1MessageQueue
@@ -599,21 +587,9 @@ contract L1StandardERC20GatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -369,9 +369,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1weth), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1weth), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1weth), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1weth), amount, gasLimit);
}
} else {
// token is not l1WETH
@@ -399,9 +399,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1weth), amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1weth), amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1weth), amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1weth), amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -444,9 +444,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1weth), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1weth), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1weth), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1weth), recipient, amount, gasLimit);
}
} else {
// token is not l1WETH
@@ -474,9 +474,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20{ value: feeToPay + extraValue }(address(l1weth), recipient, amount, gasLimit);
router.depositERC20{ value: feeToPay }(address(l1weth), recipient, amount, gasLimit);
} else {
gateway.depositERC20{ value: feeToPay + extraValue }(address(l1weth), recipient, amount, gasLimit);
gateway.depositERC20{ value: feeToPay }(address(l1weth), recipient, amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -520,21 +520,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("deposit zero amount");
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1weth),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1weth), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1weth),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1weth), recipient, amount, dataToCall, gasLimit);
}
} else {
// token is not l1WETH
@@ -562,21 +550,9 @@ contract L1WETHGatewayTest is L1GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1weth),
recipient,
amount,
dataToCall,
gasLimit
);
router.depositERC20AndCall{ value: feeToPay }(address(l1weth), recipient, amount, dataToCall, gasLimit);
} else {
gateway.depositERC20AndCall{ value: feeToPay + extraValue }(
address(l1weth),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.depositERC20AndCall{ value: feeToPay }(address(l1weth), recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + messengerBalance, address(l1Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -237,7 +237,6 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
) public {
// blacklist some addresses
hevm.assume(recipient != address(0));
hevm.assume(recipient != address(gateway));
gateway.updateTokenMapping(address(l2Token), address(l1Token));
@@ -316,18 +315,18 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l2Token), address(l1Token));
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
} else {
// emit AppendMessage from L2MessageQueue
@@ -350,9 +349,9 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
assertEq(gatewayBalance, l1Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -394,18 +393,18 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l2Token), address(l1Token));
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
}
} else {
// emit AppendMessage from L2MessageQueue
@@ -428,9 +427,9 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
}
assertEq(gatewayBalance, l2Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -473,30 +472,18 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
gateway.updateTokenMapping(address(l2Token), address(l1Token));
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
}
} else {
// emit AppendMessage from L2MessageQueue
@@ -519,21 +506,9 @@ contract L2CustomERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
}
assertEq(gatewayBalance, l2Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -178,8 +178,8 @@ contract L2ETHGatewayTest is L2GatewayTestBase {
uint256 amount,
bytes memory dataToCall
) public {
hevm.assume(recipient != address(0));
hevm.assume(recipient.code.length == 0);
hevm.assume(uint256(uint160(recipient)) > 100); // ignore some precompile contracts
amount = bound(amount, 1, address(this).balance / 2);
@@ -281,9 +281,9 @@ contract L2ETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawETH{ value: amount + feeToPay + extraValue }(amount, gasLimit);
router.withdrawETH{ value: amount + feeToPay }(amount, gasLimit);
} else {
gateway.withdrawETH{ value: amount + feeToPay + extraValue }(amount, gasLimit);
gateway.withdrawETH{ value: amount + feeToPay }(amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -349,9 +349,9 @@ contract L2ETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawETH{ value: amount + feeToPay + extraValue }(recipient, amount, gasLimit);
router.withdrawETH{ value: amount + feeToPay }(recipient, amount, gasLimit);
} else {
gateway.withdrawETH{ value: amount + feeToPay + extraValue }(recipient, amount, gasLimit);
gateway.withdrawETH{ value: amount + feeToPay }(recipient, amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -418,9 +418,9 @@ contract L2ETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawETHAndCall{ value: amount + feeToPay + extraValue }(recipient, amount, dataToCall, gasLimit);
router.withdrawETHAndCall{ value: amount + feeToPay }(recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawETHAndCall{ value: amount + feeToPay + extraValue }(recipient, amount, dataToCall, gasLimit);
gateway.withdrawETHAndCall{ value: amount + feeToPay }(recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -27,9 +27,6 @@ abstract contract L2GatewayTestBase is DSTestPlus {
event RelayedMessage(bytes32 indexed messageHash);
event FailedRelayedMessage(bytes32 indexed messageHash);
// pay 0.1 extra ETH to test refund
uint256 internal constant extraValue = 1e17;
L1ScrollMessenger internal l1Messenger;
address internal feeVault;

View File

@@ -1,50 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { DSTestPlus } from "solmate/test/utils/DSTestPlus.sol";
import { L1BlockContainer } from "../L2/predeploys/L1BlockContainer.sol";
import { L1GasPriceOracle } from "../L2/predeploys/L1GasPriceOracle.sol";
import { L2MessageQueue } from "../L2/predeploys/L2MessageQueue.sol";
import { Whitelist } from "../L2/predeploys/Whitelist.sol";
import { L1ScrollMessenger } from "../L1/L1ScrollMessenger.sol";
import { L2ScrollMessenger } from "../L2/L2ScrollMessenger.sol";
contract L2ScrollMessengerTest is DSTestPlus {
L1ScrollMessenger internal l1Messenger;
address internal feeVault;
Whitelist private whitelist;
L2ScrollMessenger internal l2Messenger;
L1BlockContainer internal l1BlockContainer;
L2MessageQueue internal l2MessageQueue;
L1GasPriceOracle internal l1GasOracle;
function setUp() public {
// Deploy L1 contracts
l1Messenger = new L1ScrollMessenger();
// Deploy L2 contracts
whitelist = new Whitelist(address(this));
l1BlockContainer = new L1BlockContainer(address(this));
l2MessageQueue = new L2MessageQueue(address(this));
l1GasOracle = new L1GasPriceOracle(address(this));
l2Messenger = new L2ScrollMessenger(address(l1BlockContainer), address(l1GasOracle), address(l2MessageQueue));
// Initialize L2 contracts
l2Messenger.initialize(address(l1Messenger), feeVault);
l2MessageQueue.initialize();
l2MessageQueue.updateMessenger(address(l2Messenger));
l1GasOracle.updateWhitelist(address(whitelist));
}
function testForbidCallFromL1() external {
hevm.expectRevert("Forbid to call message queue");
l2Messenger.relayMessage(address(this), address(l2MessageQueue), 0, 0, new bytes(0));
hevm.expectRevert("Forbid to call self");
l2Messenger.relayMessage(address(this), address(l2Messenger), 0, 0, new bytes(0));
}
}

View File

@@ -269,7 +269,6 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
) public {
// blacklist some addresses
hevm.assume(recipient != address(0));
hevm.assume(recipient != address(gateway));
amount = bound(amount, 1, l2Token.balanceOf(address(this)));
@@ -347,16 +346,16 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
} else {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l1Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l1Token), amount, gasLimit);
}
// emit AppendMessage from L2MessageQueue
@@ -379,9 +378,9 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), amount, gasLimit);
}
assertEq(gatewayBalance, l2Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -424,16 +423,16 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
}
} else {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l1Token), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l1Token), recipient, amount, gasLimit);
}
// emit AppendMessage from L2MessageQueue
@@ -456,9 +455,9 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2Token), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2Token), recipient, amount, gasLimit);
}
assertEq(gatewayBalance, l2Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -502,40 +501,16 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
}
} else {
hevm.expectRevert("no corresponding l1 token");
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l1Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l1Token), recipient, amount, dataToCall, gasLimit);
}
// emit AppendMessage from L2MessageQueue
@@ -558,21 +533,9 @@ contract L2StandardERC20GatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2Token),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2Token), recipient, amount, dataToCall, gasLimit);
}
assertEq(gatewayBalance, l2Token.balanceOf(address(gateway)));
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -223,7 +223,6 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
) public {
// blacklist some addresses
hevm.assume(recipient != address(0));
hevm.assume(recipient != address(gateway));
amount = bound(amount, 1, l2weth.balanceOf(address(this)));
@@ -351,9 +350,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2weth), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2weth), amount, gasLimit);
}
} else {
// token is not l2WETH
@@ -380,9 +379,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2weth), amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2weth), amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -425,9 +424,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2weth), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2weth), recipient, amount, gasLimit);
}
} else {
// token is not l1WETH
@@ -454,9 +453,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), recipient, amount, gasLimit);
router.withdrawERC20{ value: feeToPay }(address(l2weth), recipient, amount, gasLimit);
} else {
gateway.withdrawERC20{ value: feeToPay + extraValue }(address(l2weth), recipient, amount, gasLimit);
gateway.withdrawERC20{ value: feeToPay }(address(l2weth), recipient, amount, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
@@ -500,21 +499,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
if (amount == 0) {
hevm.expectRevert("withdraw zero amount");
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2weth),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2weth), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2weth),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2weth), recipient, amount, dataToCall, gasLimit);
}
} else {
// token is not l1WETH
@@ -541,21 +528,9 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
uint256 feeVaultBalance = address(feeVault).balance;
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
if (useRouter) {
router.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2weth),
recipient,
amount,
dataToCall,
gasLimit
);
router.withdrawERC20AndCall{ value: feeToPay }(address(l2weth), recipient, amount, dataToCall, gasLimit);
} else {
gateway.withdrawERC20AndCall{ value: feeToPay + extraValue }(
address(l2weth),
recipient,
amount,
dataToCall,
gasLimit
);
gateway.withdrawERC20AndCall{ value: feeToPay }(address(l2weth), recipient, amount, dataToCall, gasLimit);
}
assertEq(amount + messengerBalance, address(l2Messenger).balance);
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);

View File

@@ -325,38 +325,53 @@ func (m *Manager) handleZkProof(pk string, msg *message.ProofDetail) error {
// CollectProofs collects proofs corresponding to a proof generation session.
func (m *Manager) CollectProofs(sess *session) {
//Cleanup roller sessions before return.
defer func() {
// TODO: remove the clean-up, rollers report healthy status.
m.mu.Lock()
for pk := range sess.info.Rollers {
m.freeTaskIDForRoller(pk, sess.info.ID)
}
delete(m.sessions, sess.info.ID)
m.mu.Unlock()
}()
for {
select {
//Execute after timeout, set in config.json. Consider all rollers failed.
case <-time.After(time.Duration(m.cfg.CollectionTime) * time.Minute):
// record failed session.
errMsg := "proof generation session ended without receiving any valid proofs"
m.addFailedSession(sess, errMsg)
log.Warn(errMsg, "session id", sess.info.ID)
// Set status as skipped.
// Note that this is only a workaround for testnet here.
// TODO: In real cases we should reset to orm.ProvingTaskUnassigned
// so as to re-distribute the task in the future
if err := m.orm.UpdateProvingStatus(sess.info.ID, types.ProvingTaskFailed); err != nil {
log.Error("fail to reset task_status as Unassigned", "id", sess.info.ID, "err", err)
m.mu.Lock()
defer func() {
// TODO: remove the clean-up, rollers report healthy status.
for pk := range sess.info.Rollers {
m.freeTaskIDForRoller(pk, sess.info.ID)
}
delete(m.sessions, sess.info.ID)
m.mu.Unlock()
}()
// Pick a random winner.
// First, round up the keys that actually sent in a valid proof.
var participatingRollers []string
for pk, roller := range sess.info.Rollers {
if roller.Status == types.RollerProofValid {
participatingRollers = append(participatingRollers, pk)
}
}
// Ensure we got at least one proof before selecting a winner.
if len(participatingRollers) == 0 {
// record failed session.
errMsg := "proof generation session ended without receiving any valid proofs"
m.addFailedSession(sess, errMsg)
log.Warn(errMsg, "session id", sess.info.ID)
// Set status as skipped.
// Note that this is only a workaround for testnet here.
// TODO: In real cases we should reset to orm.ProvingTaskUnassigned
// so as to re-distribute the task in the future
if err := m.orm.UpdateProvingStatus(sess.info.ID, types.ProvingTaskFailed); err != nil {
log.Error("fail to reset task_status as Unassigned", "id", sess.info.ID, "err", err)
}
return
}
// Now, select a random index for this slice.
randIndex := mathrand.Intn(len(participatingRollers))
_ = participatingRollers[randIndex]
// TODO: reward winner
return
//Execute after one of the roller finishes sending proof, return early if all rollers had sent results.
case ret := <-sess.finishChan:
m.mu.Lock()
sess.info.Rollers[ret.pk].Status = ret.status
if sess.isSessionFailed() {
if m.isSessionFailed(sess.info) {
if err := m.orm.UpdateProvingStatus(ret.id, types.ProvingTaskFailed); err != nil {
log.Error("failed to update proving_status as failed", "msg.ID", ret.id, "error", err)
}
@@ -364,44 +379,13 @@ func (m *Manager) CollectProofs(sess *session) {
if err := m.orm.SetSessionInfo(sess.info); err != nil {
log.Error("db set session info fail", "pk", ret.pk, "error", err)
}
//Check if all rollers have finished their tasks, and rollers with valid results are indexed by public key.
finished, validRollers := sess.isRollersFinished()
//When all rollers have finished submitting their tasks, select a winner within rollers with valid proof, and return, terminate the for loop.
if finished {
//Select a random index for this slice.
randIndex := mathrand.Intn(len(validRollers))
_ = validRollers[randIndex]
// TODO: reward winner
m.mu.Unlock()
return
}
m.mu.Unlock()
}
}
}
// isRollersFinished checks if all rollers have finished submitting proofs, check their validity, and record rollers who produce valid proof.
// When rollersLeft reaches 0, it means all rollers have finished their tasks.
// validRollers also records the public keys of rollers who have finished their tasks correctly as index.
func (s *session) isRollersFinished() (bool, []string) {
var validRollers []string
for pk, roller := range s.info.Rollers {
if roller.Status == types.RollerProofValid {
validRollers = append(validRollers, pk)
continue
}
if roller.Status == types.RollerProofInvalid {
continue
}
// Some rollers are still proving.
return false, nil
}
return true, validRollers
}
func (s *session) isSessionFailed() bool {
for _, roller := range s.info.Rollers {
func (m *Manager) isSessionFailed(info *types.SessionInfo) bool {
for _, roller := range info.Rollers {
if roller.Status != types.RollerProofInvalid {
return false
}

View File

@@ -39,8 +39,8 @@ import (
)
var (
cfg *bridge_config.Config
base *docker.App
cfg *bridge_config.Config
dbImg docker.ImgInstance
batchData *types.BatchData
)
@@ -54,10 +54,10 @@ func setEnv(t *testing.T) (err error) {
// Load config.
cfg, err = bridge_config.NewConfig("../bridge/config.json")
assert.NoError(t, err)
base.RunImages(t)
// Create db container.
cfg.DBConfig.DSN = base.DBEndpoint()
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
cfg.DBConfig.DSN = dbImg.Endpoint()
templateBlockTrace, err := os.ReadFile("../common/testdata/blockTrace_02.json")
if err != nil {
@@ -80,7 +80,6 @@ func setEnv(t *testing.T) (err error) {
func TestApis(t *testing.T) {
// Set up the test environment.
base = docker.NewDockerApp()
assert.True(t, assert.NoError(t, setEnv(t)), "failed to setup the test environment.")
t.Run("TestHandshake", testHandshake)
@@ -95,7 +94,7 @@ func TestApis(t *testing.T) {
// Teardown
t.Cleanup(func() {
base.Free()
dbImg.Stop()
})
}

View File

@@ -10,10 +10,10 @@ import (
)
func TestRunDatabase(t *testing.T) {
dbcli := cmd.NewCmd(t, "db_cli-test", "--version")
defer dbcli.WaitExit()
bridge := cmd.NewCmd(t, "db_cli-test", "--version")
defer bridge.WaitExit()
// wait result
dbcli.ExpectWithTimeout(true, time.Second*3, fmt.Sprintf("db_cli version %s", version.Version))
dbcli.RunApp(nil)
bridge.ExpectWithTimeout(true, time.Second*3, fmt.Sprintf("db_cli version %s", version.Version))
bridge.RunApp(nil)
}

View File

@@ -13,18 +13,18 @@ import (
)
var (
base *docker.App
pgDB *sqlx.DB
pgDB *sqlx.DB
dbImg docker.ImgInstance
)
func initEnv(t *testing.T) error {
// Start db container.
base.RunImages(t)
dbImg = docker.NewTestDBDocker(t, "postgres")
// Create db orm handler.
factory, err := database.NewOrmFactory(&database.DBConfig{
DriverName: "postgres",
DSN: base.DBEndpoint(),
DSN: dbImg.Endpoint(),
})
if err != nil {
return err
@@ -34,7 +34,6 @@ func initEnv(t *testing.T) error {
}
func TestMigrate(t *testing.T) {
base = docker.NewDockerApp()
if err := initEnv(t); err != nil {
t.Fatal(err)
}
@@ -46,7 +45,9 @@ func TestMigrate(t *testing.T) {
t.Run("testRollback", testRollback)
t.Cleanup(func() {
base.Free()
if dbImg != nil {
assert.NoError(t, dbImg.Stop())
}
})
}

View File

@@ -194,15 +194,6 @@ func (o *blockBatchOrm) GetLatestFinalizedBatch() (*types.BlockBatch, error) {
return batch, nil
}
func (o *blockBatchOrm) GetLatestFinalizingOrFinalizedBatch() (*types.BlockBatch, error) {
row := o.db.QueryRowx(`select * from block_batch where index = (select max(index) from block_batch where rollup_status = $1 or rollup_status = $2);`, types.RollupFinalizing, types.RollupFinalized)
batch := &types.BlockBatch{}
if err := row.StructScan(batch); err != nil {
return nil, err
}
return batch, nil
}
func (o *blockBatchOrm) GetCommittedBatches(limit uint64) ([]string, error) {
rows, err := o.db.Queryx(`SELECT hash FROM block_batch WHERE rollup_status = $1 ORDER BY index ASC LIMIT $2`, types.RollupCommitted, limit)
if err != nil {

View File

@@ -63,7 +63,6 @@ type BlockBatchOrm interface {
GetLatestBatch() (*types.BlockBatch, error)
GetLatestCommittedBatch() (*types.BlockBatch, error)
GetLatestFinalizedBatch() (*types.BlockBatch, error)
GetLatestFinalizingOrFinalizedBatch() (*types.BlockBatch, error)
UpdateRollupStatus(ctx context.Context, hash string, status types.RollupStatus) error
UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash string, commitTxHash string, status types.RollupStatus) error
UpdateFinalizeTxHashAndRollupStatus(ctx context.Context, hash string, finalizeTxHash string, status types.RollupStatus) error

View File

@@ -77,7 +77,7 @@ var (
batchData2 *types.BatchData
dbConfig *database.DBConfig
base *docker.App
dbImg docker.ImgInstance
ormBlock orm.BlockTraceOrm
ormLayer1 orm.L1MessageOrm
ormLayer2 orm.L2MessageOrm
@@ -88,8 +88,8 @@ var (
func setupEnv(t *testing.T) error {
// Init db config and start db container.
dbConfig = &database.DBConfig{DriverName: "postgres"}
base.RunImages(t)
dbConfig.DSN = base.DBEndpoint()
dbImg = docker.NewTestDBDocker(t, dbConfig.DriverName)
dbConfig.DSN = dbImg.Endpoint()
// Create db handler and reset db.
factory, err := database.NewOrmFactory(dbConfig)
@@ -156,9 +156,10 @@ func setupEnv(t *testing.T) error {
// TestOrmFactory run several test cases.
func TestOrmFactory(t *testing.T) {
base = docker.NewDockerApp()
defer func() {
base.Free()
if dbImg != nil {
assert.NoError(t, dbImg.Stop())
}
}()
if err := setupEnv(t); err != nil {
t.Fatal(err)

View File

@@ -241,7 +241,7 @@ func (r *Roller) prove() error {
}
} else {
// when the roller has more than 3 times panic,
// it will omit to prove the task, submit StatusProofError and then Delete the task.
// it will omit to prove the task, submit StatusProofError and then Pop the task.
proofMsg = &message.ProofDetail{
Status: message.StatusProofError,
Error: "zk proving panic",
@@ -251,7 +251,7 @@ func (r *Roller) prove() error {
}
defer func() {
err = r.stack.Delete(task.Task.ID)
_, err = r.stack.Pop()
if err != nil {
log.Error("roller stack pop failed!", "err", err)
}

View File

@@ -81,12 +81,28 @@ func (s *Stack) Peek() (*ProvingTask, error) {
return traces, nil
}
// Delete pops the proving-task on the top of Stack.
func (s *Stack) Delete(taskID string) error {
return s.Update(func(tx *bbolt.Tx) error {
// Pop pops the proving-task on the top of Stack.
func (s *Stack) Pop() (*ProvingTask, error) {
var value []byte
if err := s.Update(func(tx *bbolt.Tx) error {
var key []byte
bu := tx.Bucket(bucket)
return bu.Delete([]byte(taskID))
})
c := bu.Cursor()
key, value = c.Last()
return bu.Delete(key)
}); err != nil {
return nil, err
}
if len(value) == 0 {
return nil, ErrEmpty
}
task := &ProvingTask{}
err := json.Unmarshal(value, task)
if err != nil {
return nil, err
}
return task, nil
}
// UpdateTimes udpates the roller prove times of the proving task.

View File

@@ -36,12 +36,10 @@ func TestStack(t *testing.T) {
}
for i := 2; i >= 0; i-- {
var peek *ProvingTask
peek, err = s.Peek()
assert.NoError(t, err)
assert.Equal(t, strconv.Itoa(i), peek.Task.ID)
err = s.Delete(strconv.Itoa(i))
var pop *ProvingTask
pop, err = s.Pop()
assert.NoError(t, err)
assert.Equal(t, strconv.Itoa(i), pop.Task.ID)
}
// test times
@@ -54,13 +52,18 @@ func TestStack(t *testing.T) {
}
err = s.Push(task)
assert.NoError(t, err)
peek, err := s.Peek()
pop, err := s.Pop()
assert.NoError(t, err)
assert.Equal(t, 0, peek.Times)
err = s.UpdateTimes(peek, 3)
err = s.Push(pop)
assert.NoError(t, err)
peek2, err := s.Peek()
peek, err := s.Peek()
assert.NoError(t, err)
assert.Equal(t, 3, peek2.Times)
pop2, err := s.Pop()
assert.NoError(t, err)
assert.Equal(t, peek, pop2)
s.UpdateTimes(pop2, 1)
assert.NoError(t, err)
assert.Equal(t, 1, pop2.Times)
}

View File

@@ -34,7 +34,9 @@ import (
)
var (
base *docker.App
l1gethImg docker.ImgInstance
l2gethImg docker.ImgInstance
dbImg docker.ImgInstance
timestamp int
wsPort int64
@@ -49,7 +51,9 @@ var (
func setupEnv(t *testing.T) {
// Start l1geth l2geth and postgres.
base.RunImages(t)
l1gethImg = docker.NewTestL1Docker(t)
l2gethImg = docker.NewTestL2Docker(t)
dbImg = docker.NewTestDBDocker(t, "postgres")
// Create a random ws port.
port, _ := rand.Int(rand.Reader, big.NewInt(2000))
@@ -64,7 +68,9 @@ func setupEnv(t *testing.T) {
}
func free(t *testing.T) {
base.Free()
assert.NoError(t, l1gethImg.Stop())
assert.NoError(t, l2gethImg.Stop())
assert.NoError(t, dbImg.Stop())
// Delete temporary files.
assert.NoError(t, os.Remove(bridgeFile))
@@ -128,11 +134,17 @@ func mockBridgeConfig(t *testing.T) string {
cfg, err := bridgeConfig.NewConfig("../../bridge/config.json")
assert.NoError(t, err)
cfg.L1Config.Endpoint = base.L1GethEndpoint()
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = base.L1GethEndpoint()
cfg.L2Config.Endpoint = base.L2GethEndpoint()
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = base.L2GethEndpoint()
cfg.DBConfig.DSN = base.DBEndpoint()
if l1gethImg != nil {
cfg.L1Config.Endpoint = l1gethImg.Endpoint()
cfg.L2Config.RelayerConfig.SenderConfig.Endpoint = l1gethImg.Endpoint()
}
if l2gethImg != nil {
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
cfg.L1Config.RelayerConfig.SenderConfig.Endpoint = l2gethImg.Endpoint()
}
if dbImg != nil {
cfg.DBConfig.DSN = dbImg.Endpoint()
}
// Store changed bridge config into a temp file.
data, err := json.Marshal(cfg)
@@ -149,10 +161,13 @@ func mockCoordinatorConfig(t *testing.T) string {
assert.NoError(t, err)
cfg.RollerManagerConfig.Verifier.MockMode = true
if dbImg != nil {
cfg.DBConfig.DSN = dbImg.Endpoint()
}
cfg.DBConfig.DSN = base.DBEndpoint()
cfg.L2Config.Endpoint = base.L2GethEndpoint()
if l2gethImg != nil {
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
}
data, err := json.Marshal(cfg)
assert.NoError(t, err)
@@ -167,8 +182,9 @@ func mockCoordinatorConfig(t *testing.T) string {
func mockDatabaseConfig(t *testing.T) string {
cfg, err := database.NewConfig("../../database/config.json")
assert.NoError(t, err)
cfg.DSN = base.DBEndpoint()
if dbImg != nil {
cfg.DSN = dbImg.Endpoint()
}
data, err := json.Marshal(cfg)
assert.NoError(t, err)

View File

@@ -11,12 +11,9 @@ import (
"time"
"github.com/stretchr/testify/assert"
"scroll-tech/common/docker"
)
func TestIntegration(t *testing.T) {
base = docker.NewDockerApp()
setupEnv(t)
// test db_cli migrate cmd.