Skip to content

Commit

Permalink
fix tests and linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Dec 12, 2024
1 parent 8d18b5e commit 0327451
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 60 deletions.
41 changes: 13 additions & 28 deletions rollup/da_syncer/da/calldata_blob_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,27 @@ import (
"github.com/scroll-tech/da-codec/encoding"

"github.com/scroll-tech/go-ethereum/accounts/abi"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/blob_client"
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/serrors"
"github.com/scroll-tech/go-ethereum/rollup/l1"
)

const (
callDataBlobSourceFetchBlockRange uint64 = 500
commitBatchEventName = "CommitBatch"
revertBatchEventName = "RevertBatch"
finalizeBatchEventName = "FinalizeBatch"
commitBatchMethodName = "commitBatch"
commitBatchWithBlobProofMethodName = "commitBatchWithBlobProof"

// the length of method ID at the beginning of transaction data
methodIDLength = 4
callDataBlobSourceFetchBlockRange uint64 = 500
)

var (
ErrSourceExhausted = errors.New("data source has been exhausted")
)

type CalldataBlobSource struct {
ctx context.Context
l1Reader *l1.Reader
blobClient blob_client.BlobClient
l1height uint64
scrollChainABI *abi.ABI
l1CommitBatchEventSignature common.Hash
l1RevertBatchEventSignature common.Hash
l1FinalizeBatchEventSignature common.Hash
db ethdb.Database
ctx context.Context
l1Reader *l1.Reader
blobClient blob_client.BlobClient
l1height uint64
scrollChainABI *abi.ABI
db ethdb.Database

l1Finalized uint64
}
Expand All @@ -51,15 +39,12 @@ func NewCalldataBlobSource(ctx context.Context, l1height uint64, l1Reader *l1.Re
return nil, fmt.Errorf("failed to get scroll chain abi: %w", err)
}
return &CalldataBlobSource{
ctx: ctx,
l1Reader: l1Reader,
blobClient: blobClient,
l1height: l1height,
scrollChainABI: scrollChainABI,
l1CommitBatchEventSignature: scrollChainABI.Events[commitBatchEventName].ID,
l1RevertBatchEventSignature: scrollChainABI.Events[revertBatchEventName].ID,
l1FinalizeBatchEventSignature: scrollChainABI.Events[finalizeBatchEventName].ID,
db: db,
ctx: ctx,
l1Reader: l1Reader,
blobClient: blobClient,
l1height: l1height,
scrollChainABI: scrollChainABI,
db: db,
}, nil
}

Expand Down
59 changes: 28 additions & 31 deletions rollup/l1/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,19 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/crypto"
)

func TestEventSignatures(t *testing.T) {
scrollChainABI, err := ScrollChainMetaData.GetAbi()
if err != nil {
t.Fatal("failed to get scroll chain abi", "err", err)
}

assert.Equal(t, crypto.Keccak256Hash([]byte("CommitBatch(uint256,bytes32)")), scrollChainABI.Events["CommitBatch"].ID)
assert.Equal(t, crypto.Keccak256Hash([]byte("RevertBatch(uint256,bytes32)")), scrollChainABI.Events["RevertBatch"].ID)
assert.Equal(t, crypto.Keccak256Hash([]byte("FinalizeBatch(uint256,bytes32,bytes32,bytes32)")), scrollChainABI.Events["FinalizeBatch"].ID)
assert.Equal(t, crypto.Keccak256Hash([]byte("CommitBatch(uint256,bytes32)")), ScrollChainABI.Events["CommitBatch"].ID)
assert.Equal(t, crypto.Keccak256Hash([]byte("RevertBatch(uint256,bytes32)")), ScrollChainABI.Events["RevertBatch"].ID)
assert.Equal(t, crypto.Keccak256Hash([]byte("FinalizeBatch(uint256,bytes32,bytes32,bytes32)")), ScrollChainABI.Events["FinalizeBatch"].ID)
}

func TestUnpackLog(t *testing.T) {
scrollChainABI, err := ScrollChainMetaData.GetAbi()
require.NoError(t, err)

mockBatchIndex := big.NewInt(123)
mockBatchHash := crypto.Keccak256Hash([]byte("mockBatch"))
mockStateRoot := crypto.Keccak256Hash([]byte("mockStateRoot"))
Expand All @@ -39,42 +30,48 @@ func TestUnpackLog(t *testing.T) {
out interface{}
}{
{
"CommitBatch",
commitBatchEventName,
types.Log{
Data: []byte{},
Topics: []common.Hash{scrollChainABI.Events["CommitBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
Data: nil,
Topics: []common.Hash{ScrollChainABI.Events[commitBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
},
&CommitBatchEvent{batchIndex: mockBatchIndex, batchHash: mockBatchHash},
&CommitBatchEvent{},
&CommitBatchEventUnpacked{
BatchIndex: mockBatchIndex,
BatchHash: mockBatchHash,
},
&CommitBatchEventUnpacked{},
},
{
"RevertBatch",
revertBatchEventName,
types.Log{
Data: []byte{},
Topics: []common.Hash{scrollChainABI.Events["RevertBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
Data: nil,
Topics: []common.Hash{ScrollChainABI.Events[revertBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
},
&RevertBatchEventUnpacked{
BatchIndex: mockBatchIndex,
BatchHash: mockBatchHash,
},
&RevertBatchEvent{batchIndex: mockBatchIndex, batchHash: mockBatchHash},
&RevertBatchEvent{},
&RevertBatchEventUnpacked{},
},
{
"FinalizeBatch",
finalizeBatchEventName,
types.Log{
Data: append(mockStateRoot.Bytes(), mockWithdrawRoot.Bytes()...),
Topics: []common.Hash{scrollChainABI.Events["FinalizeBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
Topics: []common.Hash{ScrollChainABI.Events[finalizeBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
},
&FinalizeBatchEvent{
batchIndex: mockBatchIndex,
batchHash: mockBatchHash,
stateRoot: mockStateRoot,
withdrawRoot: mockWithdrawRoot,
&FinalizeBatchEventUnpacked{
BatchIndex: mockBatchIndex,
BatchHash: mockBatchHash,
StateRoot: mockStateRoot,
WithdrawRoot: mockWithdrawRoot,
},
&FinalizeBatchEvent{},
&FinalizeBatchEventUnpacked{},
},
}

for _, tt := range tests {
t.Run(tt.eventName, func(t *testing.T) {
err := UnpackLog(scrollChainABI, tt.out, tt.eventName, tt.mockLog)
err := UnpackLog(ScrollChainABI, tt.out, tt.eventName, tt.mockLog)
assert.NoError(t, err)
assert.Equal(t, tt.expected, tt.out)
})
Expand Down
1 change: 0 additions & 1 deletion rollup/l1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
nextUnfinalizedQueueIndex = "nextUnfinalizedQueueIndex"
lastFinalizedBatchIndex = "lastFinalizedBatchIndex"

defaultL1MsgFetchBlockRange = 500
defaultRollupEventsFetchBlockRange = 100
)

Expand Down

0 comments on commit 0327451

Please sign in to comment.