mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-05 11:33:47 +00:00
* port changes from #1013 * port changes from #1068 * go.mod tidy * fix compile error * fix goimports * fix log * address review comments * upgrade golang.org/x/net to 0.23.0 * bump version * remove unused flag * update da-codec commit --------- Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package rollup_sync_service
|
|
|
|
import (
|
|
"math/big"
|
|
"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)
|
|
}
|
|
|
|
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"))
|
|
mockWithdrawRoot := crypto.Keccak256Hash([]byte("mockWithdrawRoot"))
|
|
|
|
tests := []struct {
|
|
eventName string
|
|
mockLog types.Log
|
|
expected interface{}
|
|
out interface{}
|
|
}{
|
|
{
|
|
"CommitBatch",
|
|
types.Log{
|
|
Data: []byte{},
|
|
Topics: []common.Hash{scrollChainABI.Events["CommitBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&L1CommitBatchEvent{BatchIndex: mockBatchIndex, BatchHash: mockBatchHash},
|
|
&L1CommitBatchEvent{},
|
|
},
|
|
{
|
|
"RevertBatch",
|
|
types.Log{
|
|
Data: []byte{},
|
|
Topics: []common.Hash{scrollChainABI.Events["RevertBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&L1RevertBatchEvent{BatchIndex: mockBatchIndex, BatchHash: mockBatchHash},
|
|
&L1RevertBatchEvent{},
|
|
},
|
|
{
|
|
"FinalizeBatch",
|
|
types.Log{
|
|
Data: append(mockStateRoot.Bytes(), mockWithdrawRoot.Bytes()...),
|
|
Topics: []common.Hash{scrollChainABI.Events["FinalizeBatch"].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&L1FinalizeBatchEvent{
|
|
BatchIndex: mockBatchIndex,
|
|
BatchHash: mockBatchHash,
|
|
StateRoot: mockStateRoot,
|
|
WithdrawRoot: mockWithdrawRoot,
|
|
},
|
|
&L1FinalizeBatchEvent{},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.eventName, func(t *testing.T) {
|
|
err := UnpackLog(scrollChainABI, tt.out, tt.eventName, tt.mockLog)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tt.expected, tt.out)
|
|
})
|
|
}
|
|
}
|