From 0327451a5ae2b55c474e57d230c6317773cbc502 Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:51:08 +0800 Subject: [PATCH] fix tests and linter errors --- rollup/da_syncer/da/calldata_blob_source.go | 41 +++++--------- rollup/l1/abi_test.go | 59 ++++++++++----------- rollup/l1/reader.go | 1 - 3 files changed, 41 insertions(+), 60 deletions(-) diff --git a/rollup/da_syncer/da/calldata_blob_source.go b/rollup/da_syncer/da/calldata_blob_source.go index a7489c72c838..30ac5ca7f145 100644 --- a/rollup/da_syncer/da/calldata_blob_source.go +++ b/rollup/da_syncer/da/calldata_blob_source.go @@ -8,7 +8,6 @@ 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" @@ -16,15 +15,7 @@ import ( ) 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 ( @@ -32,15 +23,12 @@ var ( ) 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 } @@ -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 } diff --git a/rollup/l1/abi_test.go b/rollup/l1/abi_test.go index ab4c9d473a16..e50e8ccaa269 100644 --- a/rollup/l1/abi_test.go +++ b/rollup/l1/abi_test.go @@ -5,7 +5,6 @@ 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" @@ -13,20 +12,12 @@ import ( ) 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")) @@ -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) }) diff --git a/rollup/l1/reader.go b/rollup/l1/reader.go index cc06296b657e..eddc77d71350 100644 --- a/rollup/l1/reader.go +++ b/rollup/l1/reader.go @@ -21,7 +21,6 @@ const ( nextUnfinalizedQueueIndex = "nextUnfinalizedQueueIndex" lastFinalizedBatchIndex = "lastFinalizedBatchIndex" - defaultL1MsgFetchBlockRange = 500 defaultRollupEventsFetchBlockRange = 100 )