@@ -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
1514func 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
2620func 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 })
0 commit comments