mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +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 * port changes from #1018 * fix tests and linter errors * address review comments
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package l1
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"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) {
|
|
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) {
|
|
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{}
|
|
}{
|
|
{
|
|
commitBatchEventName,
|
|
types.Log{
|
|
Data: nil,
|
|
Topics: []common.Hash{ScrollChainABI.Events[commitBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&CommitBatchEventUnpacked{
|
|
BatchIndex: mockBatchIndex,
|
|
BatchHash: mockBatchHash,
|
|
},
|
|
&CommitBatchEventUnpacked{},
|
|
},
|
|
{
|
|
revertBatchEventName,
|
|
types.Log{
|
|
Data: nil,
|
|
Topics: []common.Hash{ScrollChainABI.Events[revertBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&RevertBatchEventUnpacked{
|
|
BatchIndex: mockBatchIndex,
|
|
BatchHash: mockBatchHash,
|
|
},
|
|
&RevertBatchEventUnpacked{},
|
|
},
|
|
{
|
|
finalizeBatchEventName,
|
|
types.Log{
|
|
Data: append(mockStateRoot.Bytes(), mockWithdrawRoot.Bytes()...),
|
|
Topics: []common.Hash{ScrollChainABI.Events[finalizeBatchEventName].ID, common.BigToHash(mockBatchIndex), mockBatchHash},
|
|
},
|
|
&FinalizeBatchEventUnpacked{
|
|
BatchIndex: mockBatchIndex,
|
|
BatchHash: mockBatchHash,
|
|
StateRoot: mockStateRoot,
|
|
WithdrawRoot: mockWithdrawRoot,
|
|
},
|
|
&FinalizeBatchEventUnpacked{},
|
|
},
|
|
}
|
|
|
|
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)
|
|
})
|
|
}
|
|
}
|