@@ -89,6 +89,74 @@ func TestIncrementalProcessUpdateBatchL2DataOnCache(t *testing.T) {
89
89
require .Equal (t , false , res .ClearCache )
90
90
}
91
91
92
+ // This test check that if you process incrementally a batch that need to be close
93
+ // the GER is update because we call UpdateWIPBatch
94
+ // NOTE: CloseBatch() doesnt update GER
95
+ func TestIncrementalProcessUpdateBatchL2DataAndGER (t * testing.T ) {
96
+ // Arrange
97
+ stateMock := mock_l2_sync_etrog .NewStateInterface (t )
98
+ syncMock := mock_syncinterfaces .NewSynchronizerFlushIDManager (t )
99
+
100
+ sut := SyncTrustedBatchExecutorForEtrog {
101
+ state : stateMock ,
102
+ sync : syncMock ,
103
+ }
104
+ ctx := context .Background ()
105
+
106
+ stateBatchL2Data , _ := hex .DecodeString (codedL2BlockHeader + codedRLP2Txs1 )
107
+ trustedBatchL2Data , _ := hex .DecodeString (codedL2BlockHeader + codedRLP2Txs1 + codedL2BlockHeader + codedRLP2Txs1 )
108
+ expectedStateRoot := common .HexToHash ("0x723e5c4c7ee7890e1e66c2e391d553ee792d2204ecb4fe921830f12f8dcd1a92" )
109
+ //deltaBatchL2Data := []byte{4}
110
+ batchNumber := uint64 (123 )
111
+ data := l2_shared.ProcessData {
112
+ BatchNumber : batchNumber ,
113
+ OldStateRoot : common.Hash {},
114
+ BatchMustBeClosed : true ,
115
+ TrustedBatch : & types.Batch {
116
+ Number : 123 ,
117
+ BatchL2Data : trustedBatchL2Data ,
118
+ StateRoot : expectedStateRoot ,
119
+ Closed : true ,
120
+ },
121
+ StateBatch : & state.Batch {
122
+ BatchNumber : batchNumber ,
123
+ BatchL2Data : stateBatchL2Data ,
124
+ GlobalExitRoot : common .HexToHash ("0x9c8fa7ce2e197f9f1b3c30de9f93de3c1cb290e6c118a18446f47a9e1364c3ab" ),
125
+ },
126
+ }
127
+ expectedUpdate := state.ProcessingReceipt {
128
+ BatchNumber : 123 ,
129
+ StateRoot : expectedStateRoot ,
130
+ LocalExitRoot : data .TrustedBatch .LocalExitRoot ,
131
+ GlobalExitRoot : data .TrustedBatch .GlobalExitRoot ,
132
+ AccInputHash : data .TrustedBatch .AccInputHash ,
133
+ BatchL2Data : trustedBatchL2Data ,
134
+ }
135
+
136
+ stateMock .EXPECT ().UpdateWIPBatch (ctx , expectedUpdate , mock .Anything ).Return (nil ).Once ()
137
+ stateMock .EXPECT ().GetL1InfoTreeDataFromBatchL2Data (ctx , mock .Anything , mock .Anything ).Return (map [uint32 ]state.L1DataV2 {}, expectedStateRoot , common.Hash {}, nil ).Once ()
138
+ stateMock .EXPECT ().GetForkIDByBatchNumber (batchNumber ).Return (uint64 (7 )).Once ()
139
+
140
+ processBatchResp := & state.ProcessBatchResponse {
141
+ NewStateRoot : expectedStateRoot ,
142
+ }
143
+ stateMock .EXPECT ().ProcessBatchV2 (ctx , mock .Anything , true ).Return (processBatchResp , nil ).Once ()
144
+
145
+ syncMock .EXPECT ().PendingFlushID (mock .Anything , mock .Anything ).Once ()
146
+ syncMock .EXPECT ().CheckFlushID (mock .Anything ).Return (nil ).Maybe ()
147
+ expectedUpdateClosed := expectedUpdate
148
+ expectedUpdateClosed .GlobalExitRoot = common.Hash {}
149
+ expectedUpdateClosed .ClosingReason = state .SyncL2TrustedBatchClosingReason
150
+ stateMock .EXPECT ().CloseBatch (ctx , expectedUpdateClosed , mock .Anything ).Return (nil ).Once ()
151
+ // Act
152
+ res , err := sut .IncrementalProcess (ctx , & data , nil )
153
+ // Assert
154
+ log .Info (res )
155
+ require .NoError (t , err )
156
+ require .Equal (t , trustedBatchL2Data , res .UpdateBatch .BatchL2Data )
157
+ require .Equal (t , false , res .ClearCache )
158
+ }
159
+
92
160
func newTestData (t * testing.T ) testDataForBathExecutor {
93
161
stateMock := mock_l2_sync_etrog .NewStateInterface (t )
94
162
syncMock := mock_syncinterfaces .NewSynchronizerFlushIDManager (t )
0 commit comments