hermez-node/test/til/txs_test.go
test/til/txs_test.goRaw
1package til
2
3import (
4 "math/big"
5 "testing"
6
7 "github.com/hermeznetwork/hermez-node/common"
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10)
11
12func TestGenerateBlocksNoBatches(t *testing.T) {
13 set := `
14 Type: Blockchain
15 AddToken(1)
16 AddToken(2)
17
18 CreateAccountDeposit(1) A: 11
19 CreateAccountDeposit(2) B: 22
20
21 > block
22 `
23 tc := NewContext(common.RollupConstMaxL1UserTx)
24 blocks, err := tc.GenerateBlocks(set)
25 require.NoError(t, err)
26 assert.Equal(t, 1, len(blocks))
27 assert.Equal(t, 0, len(blocks[0].Rollup.Batches))
28 assert.Equal(t, 2, len(blocks[0].Rollup.AddedTokens))
29 assert.Equal(t, 2, len(blocks[0].Rollup.L1UserTxs))
30}
31
32func TestGenerateBlocks(t *testing.T) {
33 set := `
34 Type: Blockchain
35 AddToken(1)
36 AddToken(2)
37 AddToken(3)
38
39 CreateAccountDeposit(1) A: 10
40 CreateAccountDeposit(2) A: 20
41 CreateAccountDeposit(1) B: 5
42 CreateAccountDeposit(1) C: 5
43 CreateAccountDeposit(1) D: 5
44
45 > batchL1 // batchNum = 1
46 > batchL1 // batchNum = 2
47
48 CreateAccountDepositTransfer(1) F-A: 15, 10
49
50 Transfer(1) A-B: 6 (1)
51 Transfer(1) B-D: 3 (1)
52 Transfer(1) A-D: 1 (1)
53
54 // set new batch
55 > batch // batchNum = 3
56 CreateAccountCoordinator(1) E
57 CreateAccountCoordinator(2) B
58
59 DepositTransfer(1) A-B: 15, 10
60 Transfer(1) C-A : 3 (1)
61 Transfer(2) A-B: 15 (1)
62 Transfer(1) A-E: 1 (1)
63
64 CreateAccountDeposit(1) User0: 20
65 CreateAccountDeposit(3) User1: 20
66 CreateAccountCoordinator(1) User1
67 CreateAccountCoordinator(3) User0
68 > batchL1 // batchNum = 4
69 Transfer(1) User0-User1: 15 (1)
70 Transfer(3) User1-User0: 15 (1)
71 Transfer(1) A-C: 1 (1)
72
73 > batchL1 // batchNum = 5
74
75 Transfer(1) User1-User0: 1 (1)
76
77 > block
78
79 // Exits
80 Transfer(1) A-B: 1 (1)
81 Exit(1) A: 5 (1)
82
83 > batch // batchNum = 6
84 > block
85
86 // this transaction should not be generated, as it's after last
87 // batch and last block
88 Transfer(1) User1-User0: 1 (1)
89 `
90 tc := NewContext(common.RollupConstMaxL1UserTx)
91 blocks, err := tc.GenerateBlocks(set)
92 require.NoError(t, err)
93 assert.Equal(t, 2, len(blocks))
94 assert.Equal(t, 5, len(blocks[0].Rollup.Batches))
95 assert.Equal(t, 1, len(blocks[1].Rollup.Batches))
96 assert.Equal(t, 9, len(blocks[0].Rollup.L1UserTxs))
97 assert.Equal(t, 4, len(blocks[0].Rollup.Batches[3].L1CoordinatorTxs))
98 assert.Equal(t, 0, len(blocks[1].Rollup.L1UserTxs))
99
100 // Check expected values generated by each line
101 // #0: Deposit(1) A: 10
102 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[0], common.TxTypeCreateAccountDeposit, 1, "A", "", big.NewInt(10), nil)
103 // #1: Deposit(2) A: 20
104 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[1], common.TxTypeCreateAccountDeposit, 2, "A", "", big.NewInt(20), nil)
105 // // #2: Deposit(1) A: 20
106 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[2], common.TxTypeCreateAccountDeposit, 1, "B", "", big.NewInt(5), nil)
107 // // #3: CreateAccountDeposit(1) C: 5
108 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[3], common.TxTypeCreateAccountDeposit, 1, "C", "", big.NewInt(5), nil)
109 // // #4: CreateAccountDeposit(1) D: 5
110 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[4], common.TxTypeCreateAccountDeposit, 1, "D", "", big.NewInt(5), nil)
111 // #5: Transfer(1) A-B: 6 (1)
112 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3))
113 // #6: Transfer(1) B-D: 3 (1)
114 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3))
115 // #7: Transfer(1) A-D: 1 (1)
116 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[2], common.TxTypeTransfer, 1, "A", "D", big.NewInt(1), common.BatchNum(3))
117 // change of Batch
118 // #8: CreateAccountDepositTransfer(1) F-A: 15, 10 (3)
119 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[5], common.TxTypeCreateAccountDepositTransfer, 1, "F", "A", big.NewInt(15), big.NewInt(10))
120 // #9: DepositTransfer(1) A-B: 15, 10 (1)
121 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[6], common.TxTypeDepositTransfer, 1, "A", "B", big.NewInt(15), big.NewInt(10))
122 // #11: Transfer(1) C-A : 3 (1)
123 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4))
124 // #12: Transfer(2) A-B: 15 (1)
125 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4))
126 // #13: Deposit(1) User0: 20
127 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[7], common.TxTypeCreateAccountDeposit, 1, "User0", "", big.NewInt(20), nil)
128 // // #14: Deposit(3) User1: 20
129 tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[8], common.TxTypeCreateAccountDeposit, 3, "User1", "", big.NewInt(20), nil)
130 // #15: Transfer(1) User0-User1: 15 (1)
131 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5))
132 // #16: Transfer(3) User1-User0: 15 (1)
133 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5))
134 // #17: Transfer(1) A-C: 1 (1)
135 tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[2], common.TxTypeTransfer, 1, "A", "C", big.NewInt(1), common.BatchNum(5))
136 // change of Batch
137 // #18: Transfer(1) User1-User0: 1 (1)
138 tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[0], common.TxTypeTransfer, 1, "User1", "User0", big.NewInt(1), common.BatchNum(6))
139 // change of Block (implies also a change of batch)
140 // #19: Transfer(1) A-B: 1 (1)
141 tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
142}
143
144func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
145 assert.Equal(t, typ, tx.Type)
146 if tx.FromIdx != common.Idx(0) {
147 assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
148 }
149 assert.Equal(t, tc.Users[from].Addr.Hex(), tx.FromEthAddr.Hex())
150 assert.Equal(t, tc.Users[from].BJJ.Public().Compress(), tx.FromBJJ)
151 if tx.ToIdx != common.Idx(0) {
152 assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
153 }
154 if depositAmount != nil {
155 assert.Equal(t, depositAmount, tx.DepositAmount)
156 }
157 if amount != nil {
158 assert.Equal(t, amount, tx.Amount)
159 }
160}
161
162func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxType, tokenID common.TokenID, from, to string, amount *big.Int, batchNum common.BatchNum) {
163 assert.Equal(t, typ, tx.Type)
164 assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
165 if tx.Type != common.TxTypeExit {
166 assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
167 }
168 if amount != nil {
169 assert.Equal(t, amount, tx.Amount)
170 }
171 assert.Equal(t, batchNum, tx.BatchNum)
172}
173
174func TestGeneratePoolL2Txs(t *testing.T) {
175 set := `
176 Type: Blockchain
177 AddToken(1)
178 AddToken(2)
179 AddToken(3)
180
181 CreateAccountDeposit(1) A: 10
182 CreateAccountDeposit(2) A: 20
183 CreateAccountDeposit(1) B: 5
184 CreateAccountDeposit(1) C: 5
185 CreateAccountDeposit(1) User0: 5
186 CreateAccountDeposit(1) User1: 0
187 CreateAccountDeposit(3) User0: 0
188 CreateAccountDeposit(3) User1: 5
189 CreateAccountDeposit(2) B: 5
190 CreateAccountDeposit(2) D: 0
191 > batchL1
192 > batchL1
193 `
194 tc := NewContext(common.RollupConstMaxL1UserTx)
195 _, err := tc.GenerateBlocks(set)
196 require.NoError(t, err)
197 set = `
198 Type: PoolL2
199 PoolTransfer(1) A-B: 6 (1)
200 PoolTransfer(1) B-C: 3 (1)
201 PoolTransfer(1) C-A: 3 (1)
202 PoolTransfer(1) A-B: 1 (1)
203 PoolTransfer(2) A-B: 15 (1)
204 PoolTransfer(1) User0-User1: 15 (1)
205 PoolTransfer(3) User1-User0: 15 (1)
206 PoolTransfer(2) B-D: 3 (1)
207 PoolExit(1) A: 3 (1)
208 PoolTransferToEthAddr(1) A-B: 1 (1)
209 PoolTransferToBJJ(1) A-B: 1 (1)
210 `
211 poolL2Txs, err := tc.GeneratePoolL2Txs(set)
212 require.NoError(t, err)
213 assert.Equal(t, 11, len(poolL2Txs))
214 assert.Equal(t, common.TxTypeTransfer, poolL2Txs[0].Type)
215 assert.Equal(t, common.TxTypeExit, poolL2Txs[8].Type)
216 assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[0].ToEthAddr.Hex())
217 assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[0].ToBJJ.String())
218 assert.Equal(t, tc.Users["User1"].Addr.Hex(), poolL2Txs[5].ToEthAddr.Hex())
219 assert.Equal(t, tc.Users["User1"].BJJ.Public().String(), poolL2Txs[5].ToBJJ.String())
220
221 assert.Equal(t, common.Nonce(1), poolL2Txs[0].Nonce)
222 assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce)
223 assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
224
225 assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[9].ToEthAddr.Hex())
226 assert.Equal(t, common.EmptyBJJComp, poolL2Txs[9].ToBJJ)
227 assert.Equal(t, common.TxTypeTransferToEthAddr, poolL2Txs[9].Type)
228 assert.Equal(t, common.FFAddr, poolL2Txs[10].ToEthAddr)
229 assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[10].ToBJJ.String())
230 assert.Equal(t, common.TxTypeTransferToBJJ, poolL2Txs[10].Type)
231
232 // load another set in the same Context
233 set = `
234 Type: PoolL2
235 PoolTransfer(1) A-B: 6 (1)
236 PoolTransfer(1) B-C: 3 (1)
237 PoolTransfer(1) A-C: 3 (1)
238 `
239 poolL2Txs, err = tc.GeneratePoolL2Txs(set)
240 require.NoError(t, err)
241 assert.Equal(t, common.Nonce(6), poolL2Txs[0].Nonce)
242 assert.Equal(t, common.Nonce(2), poolL2Txs[1].Nonce)
243 assert.Equal(t, common.Nonce(7), poolL2Txs[2].Nonce)
244
245 // check that a PoolL2Tx can be done to a non existing ToIdx
246 set = `
247 Type: Blockchain
248 AddToken(1)
249 CreateAccountDeposit(1) A: 10
250 > batchL1
251 > batchL1
252 > block
253 `
254 tc = NewContext(common.RollupConstMaxL1UserTx)
255 _, err = tc.GenerateBlocks(set)
256 require.NoError(t, err)
257 set = `
258 Type: PoolL2
259 PoolTransferToEthAddr(1) A-B: 3 (1)
260 PoolTransferToBJJ(1) A-C: 3 (1)
261 `
262 _, err = tc.GeneratePoolL2Txs(set)
263 require.NoError(t, err)
264 // expect error, as FromIdx=B is still not created for TokenID=1
265 set = `
266 Type: PoolL2
267 PoolTransferToEthAddr(1) B-A: 3 (1)
268 PoolTransferToBJJ(1) B-A: 3 (1)
269 `
270 _, err = tc.GeneratePoolL2Txs(set)
271 require.NotNil(t, err)
272}
273
274func TestGeneratePoolL2TxsFromInstructions(t *testing.T) {
275 // Generate necessary L1 data
276 set := `
277 Type: Blockchain
278 AddToken(1)
279
280 CreateAccountCoordinator(1) A
281 CreateAccountDeposit(1) B: 7
282 > batchL1
283 > batchL1
284 `
285 tc := NewContext(common.RollupConstMaxL1UserTx)
286 _, err := tc.GenerateBlocks(set)
287 require.NoError(t, err)
288
289 // Generate Pool txs using instructions
290 instructionSet := []Instruction{}
291 i := 0
292 a := big.NewInt(3)
293 instructionSet = append(instructionSet, Instruction{
294 LineNum: i,
295 // Literal: "PoolTransferToEthAddr(1) B-A: 3 (1)",
296 Typ: common.TxTypeTransferToEthAddr,
297 From: "B",
298 To: "A",
299 TokenID: 1,
300 Amount: a,
301 Fee: 1,
302 })
303 i++
304 instructionSet = append(instructionSet, Instruction{
305 LineNum: i,
306 // Literal: "PoolTransferToBJJ(1) B-A: 3 (1)",
307 Typ: common.TxTypeTransferToBJJ,
308 From: "B",
309 To: "A",
310 TokenID: 1,
311 Amount: a,
312 Fee: 1,
313 })
314 txsFromInstructions, err := tc.GeneratePoolL2TxsFromInstructions(instructionSet)
315 require.NoError(t, err)
316 // Generate Pool txs using string
317 tc = NewContext(common.RollupConstMaxL1UserTx)
318 _, err = tc.GenerateBlocks(set)
319 require.NoError(t, err)
320 stringSet := `
321 Type: PoolL2
322 PoolTransferToEthAddr(1) B-A: 3 (1)
323 PoolTransferToBJJ(1) B-A: 3 (1)
324 `
325 txsFromString, err := tc.GeneratePoolL2Txs(stringSet)
326 require.NoError(t, err)
327 // Compare generated txs from instructions and string
328 // timestamps will be different
329 for i := 0; i < len(txsFromString); i++ {
330 txsFromInstructions[i].Timestamp = txsFromString[i].Timestamp
331 }
332 assert.Equal(t, txsFromString, txsFromInstructions)
333}
334
335func TestGenerateErrors(t *testing.T) {
336 // unregistered token
337 set := `Type: Blockchain
338 CreateAccountDeposit(1) A: 5
339 > batchL1
340 `
341 tc := NewContext(common.RollupConstMaxL1UserTx)
342 _, err := tc.GenerateBlocks(set)
343 assert.Equal(t, "Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, last registered TokenID: 0", err.Error())
344
345 // ensure AddToken sequentiality and not using 0
346 set = `
347 Type: Blockchain
348 AddToken(0)
349 `
350 tc = NewContext(common.RollupConstMaxL1UserTx)
351 _, err = tc.GenerateBlocks(set)
352 require.Equal(t, "Line 2: AddToken can not register TokenID 0", err.Error())
353
354 set = `
355 Type: Blockchain
356 AddToken(2)
357 `
358 tc = NewContext(common.RollupConstMaxL1UserTx)
359 _, err = tc.GenerateBlocks(set)
360 require.Equal(t, "Line 2: AddToken TokenID should be sequential, expected TokenID: 1, defined TokenID: 2", err.Error())
361
362 set = `
363 Type: Blockchain
364 AddToken(1)
365 AddToken(2)
366 AddToken(3)
367 AddToken(5)
368 `
369 tc = NewContext(common.RollupConstMaxL1UserTx)
370 _, err = tc.GenerateBlocks(set)
371 require.Equal(t, "Line 5: AddToken TokenID should be sequential, expected TokenID: 4, defined TokenID: 5", err.Error())
372
373 // check transactions when account is not created yet
374 set = `
375 Type: Blockchain
376 AddToken(1)
377 CreateAccountDeposit(1) A: 10
378 > batchL1
379 CreateAccountDeposit(1) B
380 Transfer(1) A-B: 6 (1)
381 > batch
382 `
383 tc = NewContext(common.RollupConstMaxL1UserTx)
384 _, err = tc.GenerateBlocks(set)
385 require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: Expected ':', found 'Transfer'", err.Error())
386 set = `
387 Type: Blockchain
388 AddToken(1)
389 CreateAccountDeposit(1) A: 10
390 > batchL1
391 CreateAccountCoordinator(1) B
392 > batchL1
393 > batch
394 Transfer(1) A-B: 6 (1)
395 > batch
396 `
397 tc = NewContext(common.RollupConstMaxL1UserTx)
398 _, err = tc.GenerateBlocks(set)
399 require.NoError(t, err)
400
401 // check nonces
402 set = `
403 Type: Blockchain
404 AddToken(1)
405 CreateAccountDeposit(1) A: 10
406 > batchL1
407 CreateAccountCoordinator(1) B
408 > batchL1
409 Transfer(1) A-B: 6 (1)
410 Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
411 Transfer(1) B-A: 6 (1)
412 Exit(1) A: 3 (1)
413 > batch
414 `
415 tc = NewContext(common.RollupConstMaxL1UserTx)
416 _, err = tc.GenerateBlocks(set)
417 require.NoError(t, err)
418 assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce)
419 assert.Equal(t, common.Idx(256), tc.Users["A"].Accounts[common.TokenID(1)].Idx)
420 assert.Equal(t, common.Nonce(1), tc.Users["B"].Accounts[common.TokenID(1)].Nonce)
421 assert.Equal(t, common.Idx(257), tc.Users["B"].Accounts[common.TokenID(1)].Idx)
422}
423
424func TestGenerateFromInstructions(t *testing.T) {
425 // Generate block from instructions
426 setInst := []Instruction{}
427 i := 0
428 setInst = append(setInst, Instruction{
429 LineNum: i,
430 // Literal: "AddToken(1)",
431 Typ: TypeAddToken,
432 TokenID: 1,
433 })
434 i++
435 da := big.NewInt(10)
436 setInst = append(setInst, Instruction{
437 LineNum: i,
438 // Literal: "CreateAccountDeposit(1) A: 10",
439 Typ: common.TxTypeCreateAccountDeposit,
440 From: "A",
441 TokenID: 1,
442 DepositAmount: da,
443 })
444 i++
445 setInst = append(setInst, Instruction{
446 LineNum: i,
447 // Literal: "> batchL1",
448 Typ: TypeNewBatchL1,
449 })
450 i++
451 setInst = append(setInst, Instruction{
452 LineNum: i,
453 // Literal: "CreateAccountCoordinator(1) B",
454 Typ: TxTypeCreateAccountDepositCoordinator,
455 From: "B",
456 TokenID: 1,
457 })
458 i++
459 setInst = append(setInst, Instruction{
460 LineNum: i,
461 // Literal: "> batchL1",
462 Typ: TypeNewBatchL1,
463 })
464 i++
465 a := big.NewInt(6)
466 setInst = append(setInst, Instruction{
467 LineNum: i, // 5
468 // Literal: "Transfer(1) A-B: 6 (1)",
469 Typ: common.TxTypeTransfer,
470 From: "A",
471 To: "B",
472 TokenID: 1,
473 Amount: a,
474 Fee: 1,
475 })
476 i++
477 setInst = append(setInst, Instruction{
478 LineNum: i,
479 // Literal: "Transfer(1) A-B: 6 (1)",
480 Typ: common.TxTypeTransfer,
481 From: "A",
482 To: "B",
483 TokenID: 1,
484 Amount: a,
485 Fee: 1,
486 })
487 i++
488 setInst = append(setInst, Instruction{
489 LineNum: i,
490 // Literal: "Transfer(1) B-A: 6 (1)",
491 Typ: common.TxTypeTransfer,
492 From: "B",
493 To: "A",
494 TokenID: 1,
495 Amount: a,
496 Fee: 1,
497 })
498 i++
499 a = big.NewInt(3)
500 setInst = append(setInst, Instruction{
501 LineNum: i,
502 // Literal: "Exit(1) A: 3 (1)",
503 Typ: common.TxTypeExit,
504 From: "A",
505 TokenID: 1,
506 Amount: a,
507 Fee: 1,
508 })
509 i++
510 setInst = append(setInst, Instruction{
511 LineNum: i,
512 // Literal: "> batch",
513 Typ: TypeNewBatch,
514 })
515 setInst = append(setInst, Instruction{
516 LineNum: i,
517 // Literal: "> block",
518 Typ: TypeNewBlock,
519 })
520
521 tc := NewContext(common.RollupConstMaxL1UserTx)
522 blockFromInstructions, err := tc.GenerateBlocksFromInstructions(setInst)
523 require.NoError(t, err)
524
525 // Generate block from string
526 setString := `
527 Type: Blockchain
528 AddToken(1)
529 CreateAccountDeposit(1) A: 10
530 > batchL1
531 CreateAccountCoordinator(1) B
532 > batchL1
533 Transfer(1) A-B: 6 (1)
534 Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
535 Transfer(1) B-A: 6 (1)
536 Exit(1) A: 3 (1)
537 > batch
538 > block
539 `
540 tc = NewContext(common.RollupConstMaxL1UserTx)
541 blockFromString, err := tc.GenerateBlocks(setString)
542 require.NoError(t, err)
543
544 // Generated data should be equivalent, except for Eth Addrs and BJJs
545 for i, strBatch := range blockFromString[0].Rollup.Batches {
546 // instBatch := blockFromInstructions[0].Rollup.Batches[i]
547 for j := 0; j < len(strBatch.L1CoordinatorTxs); j++ {
548 blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr =
549 blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr
550 blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ =
551 blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ
552 }
553 for j := 0; j < len(strBatch.L1UserTxs); j++ {
554 blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr =
555 blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr
556 blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ =
557 blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ
558 }
559 }
560 for i := 0; i < len(blockFromString[0].Rollup.L1UserTxs); i++ {
561 blockFromInstructions[0].Rollup.L1UserTxs[i].FromEthAddr =
562 blockFromString[0].Rollup.L1UserTxs[i].FromEthAddr
563 blockFromInstructions[0].Rollup.L1UserTxs[i].FromBJJ =
564 blockFromString[0].Rollup.L1UserTxs[i].FromBJJ
565 }
566 assert.Equal(t, blockFromString, blockFromInstructions)
567}