Skip to content

Commit e51182d

Browse files
committed
fix tests and linter errors
1 parent b918a2b commit e51182d

File tree

3 files changed

+41
-60
lines changed

3 files changed

+41
-60
lines changed

rollup/da_syncer/da/calldata_blob_source.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,27 @@ import (
88
"github.com/scroll-tech/da-codec/encoding"
99

1010
"github.com/scroll-tech/go-ethereum/accounts/abi"
11-
"github.com/scroll-tech/go-ethereum/common"
1211
"github.com/scroll-tech/go-ethereum/ethdb"
1312
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/blob_client"
1413
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/serrors"
1514
"github.com/scroll-tech/go-ethereum/rollup/l1"
1615
)
1716

1817
const (
19-
callDataBlobSourceFetchBlockRange uint64 = 500
20-
commitBatchEventName = "CommitBatch"
21-
revertBatchEventName = "RevertBatch"
22-
finalizeBatchEventName = "FinalizeBatch"
23-
commitBatchMethodName = "commitBatch"
24-
commitBatchWithBlobProofMethodName = "commitBatchWithBlobProof"
25-
26-
// the length of method ID at the beginning of transaction data
27-
methodIDLength = 4
18+
callDataBlobSourceFetchBlockRange uint64 = 500
2819
)
2920

3021
var (
3122
ErrSourceExhausted = errors.New("data source has been exhausted")
3223
)
3324

3425
type CalldataBlobSource struct {
35-
ctx context.Context
36-
l1Reader *l1.Reader
37-
blobClient blob_client.BlobClient
38-
l1height uint64
39-
scrollChainABI *abi.ABI
40-
l1CommitBatchEventSignature common.Hash
41-
l1RevertBatchEventSignature common.Hash
42-
l1FinalizeBatchEventSignature common.Hash
43-
db ethdb.Database
26+
ctx context.Context
27+
l1Reader *l1.Reader
28+
blobClient blob_client.BlobClient
29+
l1height uint64
30+
scrollChainABI *abi.ABI
31+
db ethdb.Database
4432

4533
l1Finalized uint64
4634
}
@@ -51,15 +39,12 @@ func NewCalldataBlobSource(ctx context.Context, l1height uint64, l1Reader *l1.Re
5139
return nil, fmt.Errorf("failed to get scroll chain abi: %w", err)
5240
}
5341
return &CalldataBlobSource{
54-
ctx: ctx,
55-
l1Reader: l1Reader,
56-
blobClient: blobClient,
57-
l1height: l1height,
58-
scrollChainABI: scrollChainABI,
59-
l1CommitBatchEventSignature: scrollChainABI.Events[commitBatchEventName].ID,
60-
l1RevertBatchEventSignature: scrollChainABI.Events[revertBatchEventName].ID,
61-
l1FinalizeBatchEventSignature: scrollChainABI.Events[finalizeBatchEventName].ID,
62-
db: db,
42+
ctx: ctx,
43+
l1Reader: l1Reader,
44+
blobClient: blobClient,
45+
l1height: l1height,
46+
scrollChainABI: scrollChainABI,
47+
db: db,
6348
}, nil
6449
}
6550

rollup/l1/abi_test.go

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,19 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8-
"github.com/stretchr/testify/require"
98

109
"github.com/scroll-tech/go-ethereum/common"
1110
"github.com/scroll-tech/go-ethereum/core/types"
1211
"github.com/scroll-tech/go-ethereum/crypto"
1312
)
1413

1514
func TestEventSignatures(t *testing.T) {
16-
scrollChainABI, err := ScrollChainMetaData.GetAbi()
17-
if err != nil {
18-
t.Fatal("failed to get scroll chain abi", "err", err)
19-
}
20-
21-
assert.Equal(t, crypto.Keccak256Hash([]byte("CommitBatch(uint256,bytes32)")), scrollChainABI.Events["CommitBatch"].ID)
22-
assert.Equal(t, crypto.Keccak256Hash([]byte("RevertBatch(uint256,bytes32)")), scrollChainABI.Events["RevertBatch"].ID)
23-
assert.Equal(t, crypto.Keccak256Hash([]byte("FinalizeBatch(uint256,bytes32,bytes32,bytes32)")), scrollChainABI.Events["FinalizeBatch"].ID)
15+
assert.Equal(t, crypto.Keccak256Hash([]byte("CommitBatch(uint256,bytes32)")), ScrollChainABI.Events["CommitBatch"].ID)
16+
assert.Equal(t, crypto.Keccak256Hash([]byte("RevertBatch(uint256,bytes32)")), ScrollChainABI.Events["RevertBatch"].ID)
17+
assert.Equal(t, crypto.Keccak256Hash([]byte("FinalizeBatch(uint256,bytes32,bytes32,bytes32)")), ScrollChainABI.Events["FinalizeBatch"].ID)
2418
}
2519

2620
func TestUnpackLog(t *testing.T) {
27-
scrollChainABI, err := ScrollChainMetaData.GetAbi()
28-
require.NoError(t, err)
29-
3021
mockBatchIndex := big.NewInt(123)
3122
mockBatchHash := crypto.Keccak256Hash([]byte("mockBatch"))
3223
mockStateRoot := crypto.Keccak256Hash([]byte("mockStateRoot"))
@@ -39,42 +30,48 @@ func TestUnpackLog(t *testing.T) {
3930
out interface{}
4031
}{
4132
{
42-
"CommitBatch",
33+
commitBatchEventName,
4334
types.Log{
44-
Data: []byte{},
45-
Topics: []common.Hash{scrollChainABI.Events["CommitBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
35+
Data: nil,
36+
Topics: []common.Hash{ScrollChainABI.Events[commitBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
4637
},
47-
&CommitBatchEvent{batchIndex: mockBatchIndex, batchHash: mockBatchHash},
48-
&CommitBatchEvent{},
38+
&CommitBatchEventUnpacked{
39+
BatchIndex: mockBatchIndex,
40+
BatchHash: mockBatchHash,
41+
},
42+
&CommitBatchEventUnpacked{},
4943
},
5044
{
51-
"RevertBatch",
45+
revertBatchEventName,
5246
types.Log{
53-
Data: []byte{},
54-
Topics: []common.Hash{scrollChainABI.Events["RevertBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
47+
Data: nil,
48+
Topics: []common.Hash{ScrollChainABI.Events[revertBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
49+
},
50+
&RevertBatchEventUnpacked{
51+
BatchIndex: mockBatchIndex,
52+
BatchHash: mockBatchHash,
5553
},
56-
&RevertBatchEvent{batchIndex: mockBatchIndex, batchHash: mockBatchHash},
57-
&RevertBatchEvent{},
54+
&RevertBatchEventUnpacked{},
5855
},
5956
{
60-
"FinalizeBatch",
57+
finalizeBatchEventName,
6158
types.Log{
6259
Data: append(mockStateRoot.Bytes(), mockWithdrawRoot.Bytes()...),
63-
Topics: []common.Hash{scrollChainABI.Events["FinalizeBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
60+
Topics: []common.Hash{ScrollChainABI.Events[finalizeBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
6461
},
65-
&FinalizeBatchEvent{
66-
batchIndex: mockBatchIndex,
67-
batchHash: mockBatchHash,
68-
stateRoot: mockStateRoot,
69-
withdrawRoot: mockWithdrawRoot,
62+
&FinalizeBatchEventUnpacked{
63+
BatchIndex: mockBatchIndex,
64+
BatchHash: mockBatchHash,
65+
StateRoot: mockStateRoot,
66+
WithdrawRoot: mockWithdrawRoot,
7067
},
71-
&FinalizeBatchEvent{},
68+
&FinalizeBatchEventUnpacked{},
7269
},
7370
}
7471

7572
for _, tt := range tests {
7673
t.Run(tt.eventName, func(t *testing.T) {
77-
err := UnpackLog(scrollChainABI, tt.out, tt.eventName, tt.mockLog)
74+
err := UnpackLog(ScrollChainABI, tt.out, tt.eventName, tt.mockLog)
7875
assert.NoError(t, err)
7976
assert.Equal(t, tt.expected, tt.out)
8077
})

rollup/l1/reader.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const (
2121
nextUnfinalizedQueueIndex = "nextUnfinalizedQueueIndex"
2222
lastFinalizedBatchIndex = "lastFinalizedBatchIndex"
2323

24-
defaultL1MsgFetchBlockRange = 500
2524
defaultRollupEventsFetchBlockRange = 100
2625
)
2726

0 commit comments

Comments
 (0)