Skip to content

Commit aa63a34

Browse files
committed
update test stuffs
1 parent 7fdc5a6 commit aa63a34

File tree

15 files changed

+304
-33
lines changed

15 files changed

+304
-33
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"math/big"
7+
8+
"github.com/scroll-tech/da-codec/encoding"
9+
"github.com/scroll-tech/go-ethereum/common"
10+
"github.com/scroll-tech/go-ethereum/core/types"
11+
"github.com/scroll-tech/go-ethereum/ethclient"
12+
"github.com/scroll-tech/go-ethereum/log"
13+
"github.com/scroll-tech/go-ethereum/rpc"
14+
)
15+
16+
func fetchAndStoreBlocks(ctx context.Context, from, to uint64) ([]*encoding.Block, error) {
17+
validiumMode := cfg.ValidiumMode
18+
cfg := cfg.FetchConfig
19+
client, err := rpc.Dial(cfg.Endpoint)
20+
if err != nil {
21+
return nil, fmt.Errorf("failed to connect l2 geth, endpoint %s, err %v", cfg.Endpoint, err)
22+
}
23+
24+
ethCli := ethclient.NewClient(client)
25+
var blocks []*encoding.Block
26+
for number := from; number <= to; number++ {
27+
log.Debug("retrieving block", "height", number)
28+
block, err := ethCli.BlockByNumber(ctx, new(big.Int).SetUint64(number))
29+
if err != nil {
30+
return nil, fmt.Errorf("failed to BlockByNumber: %v. number: %v", err, number)
31+
}
32+
33+
blockTxs := block.Transactions()
34+
35+
var count int
36+
for _, tx := range blockTxs {
37+
if tx.IsL1MessageTx() {
38+
count++
39+
}
40+
}
41+
log.Info("retrieved block", "height", block.Header().Number, "hash", block.Header().Hash().String(), "L1 message count", count)
42+
43+
// use original (encrypted) L1 message txs in validium mode
44+
if validiumMode {
45+
var txs []*types.Transaction
46+
47+
if count > 0 {
48+
log.Info("Fetching encrypted messages in validium mode")
49+
err = client.CallContext(ctx, &txs, "scroll_getL1MessagesInBlock", block.Hash(), "synced")
50+
if err != nil {
51+
return nil, fmt.Errorf("failed to get L1 messages: %v, block hash: %v", err, block.Hash().Hex())
52+
}
53+
}
54+
55+
// sanity check
56+
if len(txs) != count {
57+
return nil, fmt.Errorf("L1 message count mismatch: expected %d, got %d", count, len(txs))
58+
}
59+
60+
for ii := 0; ii < count; ii++ {
61+
// sanity check
62+
if blockTxs[ii].AsL1MessageTx().QueueIndex != txs[ii].AsL1MessageTx().QueueIndex {
63+
return nil, fmt.Errorf("L1 message queue index mismatch at index %d: expected %d, got %d", ii, blockTxs[ii].AsL1MessageTx().QueueIndex, txs[ii].AsL1MessageTx().QueueIndex)
64+
}
65+
66+
log.Info("Replacing L1 message tx in validium mode", "index", ii, "queueIndex", txs[ii].AsL1MessageTx().QueueIndex, "decryptedTxHash", blockTxs[ii].Hash().Hex(), "originalTxHash", txs[ii].Hash().Hex())
67+
blockTxs[ii] = txs[ii]
68+
}
69+
}
70+
71+
withdrawRoot, err3 := ethCli.StorageAt(ctx, cfg.L2MessageQueueAddress, cfg.WithdrawTrieRootSlot, big.NewInt(int64(number)))
72+
if err3 != nil {
73+
return nil, fmt.Errorf("failed to get withdrawRoot: %v. number: %v", err3, number)
74+
}
75+
blocks = append(blocks, &encoding.Block{
76+
Header: block.Header(),
77+
Transactions: encoding.TxsToTxsData(blockTxs),
78+
WithdrawRoot: common.BytesToHash(withdrawRoot),
79+
})
80+
}
81+
82+
return blocks, nil
83+
}

rollup/tests/integration_tool/imports.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ func randomPickKfromN(n, k int, rng *rand.Rand) []int {
4242
return ret
4343
}
4444

45-
func importData(ctx context.Context, beginBlk, endBlk uint64, chkNum, batchNum, bundleNum int, seed int64) (*importRecord, error) {
45+
func importData(ctx context.Context, beginBlk, endBlk uint64, blocks []*encoding.Block, chkNum, batchNum, bundleNum int, seed int64) (*importRecord, error) {
4646

4747
db, err := database.InitDB(cfg.DBConfig)
4848
if err != nil {
4949
return nil, err
5050
}
5151

52+
if len(blocks) > 0 {
53+
log.Info("import block")
54+
blockOrm := orm.NewL2Block(db)
55+
if err := blockOrm.InsertL2Blocks(ctx, blocks); err != nil {
56+
return nil, err
57+
}
58+
}
59+
5260
ret := &importRecord{}
5361
// Create a new random source with the provided seed
5462
source := rand.NewSource(seed)

rollup/tests/integration_tool/main.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/scroll-tech/da-codec/encoding"
13+
"github.com/scroll-tech/go-ethereum/common"
1314
"github.com/scroll-tech/go-ethereum/log"
1415
"github.com/urfave/cli/v2"
1516

@@ -40,12 +41,6 @@ var seedFlag = cli.Int64Flag{
4041
Value: 0,
4142
}
4243

43-
var codecFlag = cli.IntFlag{
44-
Name: "codec",
45-
Usage: "codec version, valid from 6, default(auto) is 0",
46-
Value: 0,
47-
}
48-
4944
func parseThreeIntegers(value string) (int, int, int, error) {
5045
// Split the input string by comma
5146
parts := strings.Split(value, ",")
@@ -84,10 +79,21 @@ func parseThreeIntegers(value string) (int, int, int, error) {
8479
return values[0], values[1], values[2], nil
8580
}
8681

82+
type fetchConfig struct {
83+
// node url.
84+
Endpoint string `json:"endpoint"`
85+
// The L2MessageQueue contract address deployed on layer 2 chain.
86+
L2MessageQueueAddress common.Address `json:"l2_message_queue_address"`
87+
// The WithdrawTrieRootSlot in L2MessageQueue contract.
88+
WithdrawTrieRootSlot common.Hash `json:"withdraw_trie_root_slot,omitempty"`
89+
}
90+
8791
// load a comptabile type of config for rollup
8892
type config struct {
8993
DBConfig *database.Config `json:"db_config"`
94+
FetchConfig *fetchConfig `json:"fetch_config,omitempty"`
9095
ValidiumMode bool `json:"validium_mode"`
96+
CodecVersion int `json:"codec_version"`
9197
}
9298

9399
func init() {
@@ -97,7 +103,7 @@ func init() {
97103
app.Name = "integration-test-tool"
98104
app.Usage = "The Scroll L2 Integration Test Tool"
99105
app.Version = version.Version
100-
app.Flags = append(app.Flags, &codecFlag, &seedFlag, &outputNumFlag, &outputPathFlag)
106+
app.Flags = append(app.Flags, &seedFlag, &outputNumFlag, &outputPathFlag)
101107
app.Flags = append(app.Flags, utils.CommonFlags...)
102108
app.Before = func(ctx *cli.Context) error {
103109
if err := utils.LogSetup(ctx); err != nil {
@@ -135,9 +141,8 @@ func action(ctx *cli.Context) error {
135141
return fmt.Errorf("specify begin and end block number")
136142
}
137143

138-
codecFl := ctx.Int(codecFlag.Name)
139-
if codecFl != 0 {
140-
switch codecFl {
144+
if cfg.CodecVersion != 0 {
145+
switch cfg.CodecVersion {
141146
case 6:
142147
codecCfg = encoding.CodecV6
143148
case 7:
@@ -147,7 +152,7 @@ func action(ctx *cli.Context) error {
147152
case 9:
148153
codecCfg = encoding.CodecV9
149154
default:
150-
return fmt.Errorf("invalid codec version %d", codecFl)
155+
return fmt.Errorf("invalid codec version %d", cfg.CodecVersion)
151156
}
152157
log.Info("set codec", "version", codecCfg)
153158
}
@@ -161,6 +166,14 @@ func action(ctx *cli.Context) error {
161166
return fmt.Errorf("invalid begin block number: %w", err)
162167
}
163168

169+
var import_blocks []*encoding.Block
170+
if cfg.FetchConfig != nil {
171+
import_blocks, err = fetchAndStoreBlocks(ctx.Context, beginBlk, endBlk)
172+
if err != nil {
173+
return err
174+
}
175+
}
176+
164177
chkNum, batchNum, bundleNum, err := parseThreeIntegers(ctx.String(outputNumFlag.Name))
165178
if err != nil {
166179
return err
@@ -174,7 +187,7 @@ func action(ctx *cli.Context) error {
174187

175188
outputPath := ctx.String(outputPathFlag.Name)
176189
log.Info("output", "Seed", seed, "file", outputPath)
177-
ret, err := importData(ctx.Context, beginBlk, endBlk, chkNum, batchNum, bundleNum, seed)
190+
ret, err := importData(ctx.Context, beginBlk, endBlk, import_blocks, chkNum, batchNum, bundleNum, seed)
178191
if err != nil {
179192
return err
180193
}

tests/prover-e2e/Makefile

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ifndef END_BLOCK
99
$(error END_BLOCK is not set. Define it in .make.env or pass END_BLOCK=<end_block>)
1010
endif
1111

12+
BLOCK_PRE_MIGRATIONS := $(wildcard conf/*.sql)
13+
.OPTIONAL: $(BLOCK_PRE_MIGRATIONS)
14+
1215
all: setup_db test_tool import_data
1316

1417
clean:
@@ -25,6 +28,11 @@ check_vars: | conf
2528
exit 1; \
2629
fi
2730

31+
migration_blocks: $(BLOCK_PRE_MIGRATIONS)
32+
ifneq ($(strip $(BLOCK_PRE_MIGRATIONS)),)
33+
GOOSE_MIGRATION_DIR=conf ${GOOSE_CMD} up-to 100
34+
endif
35+
2836
setup_db: clean
2937
docker compose up --detach
3038
@echo "Waiting for PostgreSQL to be ready..."
@@ -42,30 +50,18 @@ setup_db: clean
4250
fi; \
4351
done
4452
${GOOSE_CMD} up
45-
GOOSE_MIGRATION_DIR=conf ${GOOSE_CMD} up-to 100
4653

4754
reset_db:
48-
GOOSE_MIGRATION_DIR=conf ${GOOSE_CMD} down
4955
${GOOSE_CMD} down-to 0
5056
${GOOSE_CMD} up
51-
GOOSE_MIGRATION_DIR=conf ${GOOSE_CMD} up-to 100
5257

5358
test_tool:
5459
go build -o $(PWD)/build/bin/e2e_tool ../../rollup/tests/integration_tool
5560

5661
build/bin/e2e_tool: test_tool
5762

58-
import_data_euclid: build/bin/e2e_tool check_vars
59-
build/bin/e2e_tool --config conf/config.json --codec 7 ${BEGIN_BLOCK} ${END_BLOCK}
60-
61-
import_data_feynman: build/bin/e2e_tool check_vars
62-
build/bin/e2e_tool --config conf/config.json --codec 8 ${BEGIN_BLOCK} ${END_BLOCK}
63-
64-
import_data_galileo: build/bin/e2e_tool check_vars
65-
build/bin/e2e_tool --config conf/config.json --codec 9 ${BEGIN_BLOCK} ${END_BLOCK}
66-
67-
import_data: build/bin/e2e_tool check_vars
68-
build/bin/e2e_tool --config conf/config.json --codec ${CODEC_VERSION} ${BEGIN_BLOCK} ${END_BLOCK}
63+
import_data: build/bin/e2e_tool check_vars migration_blocks
64+
build/bin/e2e_tool --config conf/config.json ${BEGIN_BLOCK} ${END_BLOCK}
6965

7066
reimport_data: reset_db import_data
7167

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
BEGIN_BLOCK?=35
22
END_BLOCK?=49
3-
CODEC_VERSION?=8
43
SCROLL_FORK_NAME=feynman

tests/prover-e2e/cloak-xen/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"maxOpenNum": 5,
66
"maxIdleNum": 1
77
},
8-
"validium_mode": true
8+
"validium_mode": true,
9+
"codec_version": 8
910
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
BEGIN_BLOCK?=10973711
22
END_BLOCK?=10973721
3-
CODEC_VERSION?=8
43
SCROLL_FORK_NAME=feynman

tests/prover-e2e/sepolia-feynman/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"maxOpenNum": 5,
66
"maxIdleNum": 1
77
},
8-
"validium_mode": false
8+
"validium_mode": false,
9+
"codec_version": 8
910
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
BEGIN_BLOCK?=20278022
22
END_BLOCK?=20278025
3-
CODEC_VERSION?=9
43
SCROLL_FORK_NAME=galileo

tests/prover-e2e/sepolia-galileo/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"maxOpenNum": 5,
66
"maxIdleNum": 1
77
},
8-
"validium_mode": false
8+
"validium_mode": false,
9+
"codec_version": 9
910
}

0 commit comments

Comments
 (0)