hermez-node/db/l2db/l2db_test.go
db/l2db/l2db_test.goRaw
1package l2db
2
3import (
4 "math"
5 "math/big"
6 "os"
7 "testing"
8 "time"
9
10 ethCommon "github.com/ethereum/go-ethereum/common"
11 "github.com/hermeznetwork/hermez-node/common"
12 dbUtils "github.com/hermeznetwork/hermez-node/db"
13 "github.com/hermeznetwork/hermez-node/db/historydb"
14 "github.com/hermeznetwork/hermez-node/log"
15 "github.com/hermeznetwork/hermez-node/test"
16 "github.com/hermeznetwork/hermez-node/test/til"
17 "github.com/stretchr/testify/assert"
18)
19
20var l2DB *L2DB
21var historyDB *historydb.HistoryDB
22var tc *til.Context
23var tokens map[common.TokenID]historydb.TokenWithUSD
24var tokensValue map[common.TokenID]float64
25var accs map[common.Idx]common.Account
26
27func TestMain(m *testing.M) {
28 // init DB
29 pass := os.Getenv("POSTGRES_PASS")
30 db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
31 if err != nil {
32 panic(err)
33 }
34 l2DB = NewL2DB(db, 10, 100, 24*time.Hour)
35 test.WipeDB(l2DB.DB())
36 historyDB = historydb.NewHistoryDB(db)
37 // Run tests
38 result := m.Run()
39 // Close DB
40 if err := db.Close(); err != nil {
41 log.Error("Error closing the history DB:", err)
42 }
43 os.Exit(result)
44}
45
46func prepareHistoryDB(historyDB *historydb.HistoryDB) error {
47 // Reset DB
48 test.WipeDB(l2DB.DB())
49 // Generate pool txs using til
50 setBlockchain := `
51 Type: Blockchain
52
53 AddToken(1)
54 AddToken(2)
55 CreateAccountDeposit(1) A: 2000
56 CreateAccountDeposit(2) A: 2000
57 CreateAccountDeposit(1) B: 1000
58 CreateAccountDeposit(2) B: 1000
59 > batchL1
60 > batchL1
61 > block
62 > block
63 `
64
65 tc = til.NewContext(common.RollupConstMaxL1UserTx)
66 tilCfgExtra := til.ConfigExtra{
67 BootCoordAddr: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
68 CoordUser: "A",
69 }
70 blocks, err := tc.GenerateBlocks(setBlockchain)
71 if err != nil {
72 return err
73 }
74
75 err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
76 if err != nil {
77 return err
78 }
79 tokens = make(map[common.TokenID]historydb.TokenWithUSD)
80 tokensValue = make(map[common.TokenID]float64)
81 accs = make(map[common.Idx]common.Account)
82 value := 5 * 5.389329
83 now := time.Now().UTC()
84 // Add all blocks except for the last one
85 for i := range blocks[:len(blocks)-1] {
86 err = historyDB.AddBlockSCData(&blocks[i])
87 if err != nil {
88 return err
89 }
90 for _, batch := range blocks[i].Rollup.Batches {
91 for _, account := range batch.CreatedAccounts {
92 accs[account.Idx] = account
93 }
94 }
95 for _, token := range blocks[i].Rollup.AddedTokens {
96 readToken := historydb.TokenWithUSD{
97 TokenID: token.TokenID,
98 EthBlockNum: token.EthBlockNum,
99 EthAddr: token.EthAddr,
100 Name: token.Name,
101 Symbol: token.Symbol,
102 Decimals: token.Decimals,
103 }
104 tokensValue[token.TokenID] = value / math.Pow(10, float64(token.Decimals))
105 readToken.USDUpdate = &now
106 readToken.USD = &value
107 tokens[token.TokenID] = readToken
108 }
109 // Set value to the tokens (tokens have no symbol)
110 tokenSymbol := ""
111 err := historyDB.UpdateTokenValue(tokenSymbol, value)
112 if err != nil {
113 return err
114 }
115 }
116 return nil
117}
118
119func generatePoolL2Txs() ([]common.PoolL2Tx, error) {
120 setPool := `
121 Type: PoolL2
122 PoolTransfer(1) A-B: 6 (4)
123 PoolTransfer(2) A-B: 3 (1)
124 PoolTransfer(1) B-A: 5 (2)
125 PoolTransfer(2) B-A: 10 (3)
126 PoolTransfer(1) A-B: 7 (2)
127 PoolTransfer(2) A-B: 2 (1)
128 PoolTransfer(1) B-A: 8 (2)
129 PoolTransfer(2) B-A: 1 (1)
130 PoolTransfer(1) A-B: 3 (1)
131 PoolTransfer(2) B-A: 5 (2)
132
133 PoolExit(1) A: 5 (2)
134 PoolExit(2) B: 3 (1)
135 `
136 poolL2Txs, err := tc.GeneratePoolL2Txs(setPool)
137 if err != nil {
138 return nil, err
139 }
140 return poolL2Txs, nil
141}
142
143func TestAddTxTest(t *testing.T) {
144 err := prepareHistoryDB(historyDB)
145 if err != nil {
146 log.Error("Error prepare historyDB", err)
147 }
148 poolL2Txs, err := generatePoolL2Txs()
149 assert.NoError(t, err)
150 for i := range poolL2Txs {
151 err := l2DB.AddTxTest(&poolL2Txs[i])
152 assert.NoError(t, err)
153 fetchedTx, err := l2DB.GetTx(poolL2Txs[i].TxID)
154 assert.NoError(t, err)
155 assertTx(t, &poolL2Txs[i], fetchedTx)
156 nameZone, offset := fetchedTx.Timestamp.Zone()
157 assert.Equal(t, "UTC", nameZone)
158 assert.Equal(t, 0, offset)
159 }
160}
161
162func assertTx(t *testing.T, expected, actual *common.PoolL2Tx) {
163 // Check that timestamp has been set within the last 3 seconds
164 assert.Less(t, time.Now().UTC().Unix()-3, actual.Timestamp.Unix())
165 assert.GreaterOrEqual(t, time.Now().UTC().Unix(), actual.Timestamp.Unix())
166 expected.Timestamp = actual.Timestamp
167 // Check absolute fee
168 // find token
169 token := tokens[expected.TokenID]
170 // If the token has value in USD setted
171 if token.USDUpdate != nil {
172 assert.Equal(t, token.USDUpdate.Unix(), actual.AbsoluteFeeUpdate.Unix())
173 expected.AbsoluteFeeUpdate = actual.AbsoluteFeeUpdate
174 // Set expected fee
175 f := new(big.Float).SetInt(expected.Amount)
176 amountF, _ := f.Float64()
177 expected.AbsoluteFee = *token.USD * amountF * expected.Fee.Percentage()
178 test.AssertUSD(t, &expected.AbsoluteFee, &actual.AbsoluteFee)
179 }
180 assert.Equal(t, expected, actual)
181}
182
183// NO UPDATE: benchmarks will be done after impl is finished
184// func BenchmarkAddTxTest(b *testing.B) {
185// const nInserts = 20
186// test.WipeDB(l2DB.DB())
187// txs := test.GenPoolTxs(nInserts, tokens)
188// now := time.Now()
189// for _, tx := range txs {
190// _ = l2DB.AddTxTest(tx)
191// }
192// elapsedTime := time.Since(now)
193// log.Info("Time to insert 2048 txs:", elapsedTime)
194// }
195
196func TestGetPending(t *testing.T) {
197 err := prepareHistoryDB(historyDB)
198 if err != nil {
199 log.Error("Error prepare historyDB", err)
200 }
201 poolL2Txs, err := generatePoolL2Txs()
202 assert.NoError(t, err)
203 var pendingTxs []*common.PoolL2Tx
204 for i := range poolL2Txs {
205 err := l2DB.AddTxTest(&poolL2Txs[i])
206 assert.NoError(t, err)
207 pendingTxs = append(pendingTxs, &poolL2Txs[i])
208 }
209 fetchedTxs, err := l2DB.GetPendingTxs()
210 assert.NoError(t, err)
211 assert.Equal(t, len(pendingTxs), len(fetchedTxs))
212 for i := range fetchedTxs {
213 assertTx(t, pendingTxs[i], &fetchedTxs[i])
214 }
215}
216
217func TestStartForging(t *testing.T) {
218 // Generate txs
219 const fakeBatchNum common.BatchNum = 33
220 err := prepareHistoryDB(historyDB)
221 if err != nil {
222 log.Error("Error prepare historyDB", err)
223 }
224 poolL2Txs, err := generatePoolL2Txs()
225 assert.NoError(t, err)
226 var startForgingTxIDs []common.TxID
227 randomizer := 0
228 // Add txs to DB
229 for i := range poolL2Txs {
230 err := l2DB.AddTxTest(&poolL2Txs[i])
231 assert.NoError(t, err)
232 if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%2 == 0 {
233 startForgingTxIDs = append(startForgingTxIDs, poolL2Txs[i].TxID)
234 }
235 randomizer++
236 }
237 // Start forging txs
238 err = l2DB.StartForging(startForgingTxIDs, fakeBatchNum)
239 assert.NoError(t, err)
240 // Fetch txs and check that they've been updated correctly
241 for _, id := range startForgingTxIDs {
242 fetchedTx, err := l2DB.GetTxAPI(id)
243 assert.NoError(t, err)
244 assert.Equal(t, common.PoolL2TxStateForging, fetchedTx.State)
245 assert.Equal(t, fakeBatchNum, *fetchedTx.BatchNum)
246 }
247}
248
249func TestDoneForging(t *testing.T) {
250 // Generate txs
251 const fakeBatchNum common.BatchNum = 33
252 err := prepareHistoryDB(historyDB)
253 if err != nil {
254 log.Error("Error prepare historyDB", err)
255 }
256 poolL2Txs, err := generatePoolL2Txs()
257 assert.NoError(t, err)
258 var startForgingTxIDs []common.TxID
259 randomizer := 0
260 // Add txs to DB
261 for i := range poolL2Txs {
262 err := l2DB.AddTxTest(&poolL2Txs[i])
263 assert.NoError(t, err)
264 if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%2 == 0 {
265 startForgingTxIDs = append(startForgingTxIDs, poolL2Txs[i].TxID)
266 }
267 randomizer++
268 }
269 // Start forging txs
270 err = l2DB.StartForging(startForgingTxIDs, fakeBatchNum)
271 assert.NoError(t, err)
272
273 var doneForgingTxIDs []common.TxID
274 randomizer = 0
275 for _, txID := range startForgingTxIDs {
276 if randomizer%2 == 0 {
277 doneForgingTxIDs = append(doneForgingTxIDs, txID)
278 }
279 randomizer++
280 }
281 // Done forging txs
282 err = l2DB.DoneForging(doneForgingTxIDs, fakeBatchNum)
283 assert.NoError(t, err)
284
285 // Fetch txs and check that they've been updated correctly
286 for _, id := range doneForgingTxIDs {
287 fetchedTx, err := l2DB.GetTxAPI(id)
288 assert.NoError(t, err)
289 assert.Equal(t, common.PoolL2TxStateForged, fetchedTx.State)
290 assert.Equal(t, fakeBatchNum, *fetchedTx.BatchNum)
291 }
292}
293
294func TestInvalidate(t *testing.T) {
295 // Generate txs
296 const fakeBatchNum common.BatchNum = 33
297 err := prepareHistoryDB(historyDB)
298 if err != nil {
299 log.Error("Error prepare historyDB", err)
300 }
301 poolL2Txs, err := generatePoolL2Txs()
302 assert.NoError(t, err)
303 var invalidTxIDs []common.TxID
304 randomizer := 0
305 // Add txs to DB
306 for i := range poolL2Txs {
307 err := l2DB.AddTxTest(&poolL2Txs[i])
308 assert.NoError(t, err)
309 if poolL2Txs[i].State != common.PoolL2TxStateInvalid && randomizer%2 == 0 {
310 randomizer++
311 invalidTxIDs = append(invalidTxIDs, poolL2Txs[i].TxID)
312 }
313 }
314 // Invalidate txs
315 err = l2DB.InvalidateTxs(invalidTxIDs, fakeBatchNum)
316 assert.NoError(t, err)
317 // Fetch txs and check that they've been updated correctly
318 for _, id := range invalidTxIDs {
319 fetchedTx, err := l2DB.GetTxAPI(id)
320 assert.NoError(t, err)
321 assert.Equal(t, common.PoolL2TxStateInvalid, fetchedTx.State)
322 assert.Equal(t, fakeBatchNum, *fetchedTx.BatchNum)
323 }
324}
325
326func TestCheckNonces(t *testing.T) {
327 // Generate txs
328 const fakeBatchNum common.BatchNum = 33
329 err := prepareHistoryDB(historyDB)
330 if err != nil {
331 log.Error("Error prepare historyDB", err)
332 }
333 poolL2Txs, err := generatePoolL2Txs()
334 assert.NoError(t, err)
335 // Update Accounts currentNonce
336 var updateAccounts []common.Account
337 const currentNonce = common.Nonce(1)
338 for i := range accs {
339 account := accs[i]
340 account.Nonce = common.Nonce(currentNonce)
341 updateAccounts = append(updateAccounts, account)
342 }
343 // Add txs to DB
344 var invalidTxIDs []common.TxID
345 for i := range poolL2Txs {
346 if poolL2Txs[i].Nonce <= currentNonce {
347 invalidTxIDs = append(invalidTxIDs, poolL2Txs[i].TxID)
348 }
349 err := l2DB.AddTxTest(&poolL2Txs[i])
350 assert.NoError(t, err)
351 }
352
353 err = l2DB.CheckNonces(updateAccounts, fakeBatchNum)
354 assert.NoError(t, err)
355 // Fetch txs and check that they've been updated correctly
356 for _, id := range invalidTxIDs {
357 fetchedTx, err := l2DB.GetTxAPI(id)
358 assert.NoError(t, err)
359 assert.Equal(t, common.PoolL2TxStateInvalid, fetchedTx.State)
360 assert.Equal(t, fakeBatchNum, *fetchedTx.BatchNum)
361 }
362}
363
364// TestReorg: first part of the test with reorg
365// With invalidated transactions BEFORE reorgBatch
366// And forged transactions in reorgBatch
367func TestReorg(t *testing.T) {
368 // Generate txs
369 const lastValidBatch common.BatchNum = 20
370 const reorgBatch common.BatchNum = lastValidBatch + 1
371 err := prepareHistoryDB(historyDB)
372 if err != nil {
373 log.Error("Error prepare historyDB", err)
374 }
375 poolL2Txs, err := generatePoolL2Txs()
376 assert.NoError(t, err)
377
378 reorgedTxIDs := []common.TxID{}
379 nonReorgedTxIDs := []common.TxID{}
380 var startForgingTxIDs []common.TxID
381 var invalidTxIDs []common.TxID
382 var allTxRandomize []common.TxID
383 randomizer := 0
384 // Add txs to DB
385 for i := range poolL2Txs {
386 err := l2DB.AddTxTest(&poolL2Txs[i])
387 assert.NoError(t, err)
388 if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%2 == 0 {
389 startForgingTxIDs = append(startForgingTxIDs, poolL2Txs[i].TxID)
390 allTxRandomize = append(allTxRandomize, poolL2Txs[i].TxID)
391 } else if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%3 == 0 {
392 invalidTxIDs = append(invalidTxIDs, poolL2Txs[i].TxID)
393 allTxRandomize = append(allTxRandomize, poolL2Txs[i].TxID)
394 }
395 randomizer++
396 }
397 // Start forging txs
398 err = l2DB.StartForging(startForgingTxIDs, lastValidBatch)
399 assert.NoError(t, err)
400
401 var doneForgingTxIDs []common.TxID
402 randomizer = 0
403 for _, txID := range allTxRandomize {
404 invalidTx := false
405 for i := range invalidTxIDs {
406 if invalidTxIDs[i] == txID {
407 invalidTx = true
408 nonReorgedTxIDs = append(nonReorgedTxIDs, txID)
409 }
410 }
411 if !invalidTx {
412 if randomizer%2 == 0 {
413 doneForgingTxIDs = append(doneForgingTxIDs, txID)
414 reorgedTxIDs = append(reorgedTxIDs, txID)
415 } else {
416 nonReorgedTxIDs = append(nonReorgedTxIDs, txID)
417 }
418 randomizer++
419 }
420 }
421
422 // Invalidate txs BEFORE reorgBatch --> nonReorg
423 err = l2DB.InvalidateTxs(invalidTxIDs, lastValidBatch)
424 assert.NoError(t, err)
425 // Done forging txs in reorgBatch --> Reorg
426 err = l2DB.DoneForging(doneForgingTxIDs, reorgBatch)
427 assert.NoError(t, err)
428
429 err = l2DB.Reorg(lastValidBatch)
430 assert.NoError(t, err)
431 for _, id := range reorgedTxIDs {
432 tx, err := l2DB.GetTxAPI(id)
433 assert.NoError(t, err)
434 assert.Nil(t, tx.BatchNum)
435 assert.Equal(t, common.PoolL2TxStatePending, tx.State)
436 }
437 for _, id := range nonReorgedTxIDs {
438 fetchedTx, err := l2DB.GetTxAPI(id)
439 assert.NoError(t, err)
440 assert.Equal(t, lastValidBatch, *fetchedTx.BatchNum)
441 }
442}
443
444// TestReorg: second part of test with reorg
445// With invalidated transactions in reorgBatch
446// And forged transactions BEFORE reorgBatch
447func TestReorg2(t *testing.T) {
448 // Generate txs
449 const lastValidBatch common.BatchNum = 20
450 const reorgBatch common.BatchNum = lastValidBatch + 1
451 err := prepareHistoryDB(historyDB)
452 if err != nil {
453 log.Error("Error prepare historyDB", err)
454 }
455 poolL2Txs, err := generatePoolL2Txs()
456 assert.NoError(t, err)
457
458 reorgedTxIDs := []common.TxID{}
459 nonReorgedTxIDs := []common.TxID{}
460 var startForgingTxIDs []common.TxID
461 var invalidTxIDs []common.TxID
462 var allTxRandomize []common.TxID
463 randomizer := 0
464 // Add txs to DB
465 for i := range poolL2Txs {
466 err := l2DB.AddTxTest(&poolL2Txs[i])
467 assert.NoError(t, err)
468 if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%2 == 0 {
469 startForgingTxIDs = append(startForgingTxIDs, poolL2Txs[i].TxID)
470 allTxRandomize = append(allTxRandomize, poolL2Txs[i].TxID)
471 } else if poolL2Txs[i].State == common.PoolL2TxStatePending && randomizer%3 == 0 {
472 invalidTxIDs = append(invalidTxIDs, poolL2Txs[i].TxID)
473 allTxRandomize = append(allTxRandomize, poolL2Txs[i].TxID)
474 }
475 randomizer++
476 }
477 // Start forging txs
478 err = l2DB.StartForging(startForgingTxIDs, lastValidBatch)
479 assert.NoError(t, err)
480
481 var doneForgingTxIDs []common.TxID
482 randomizer = 0
483 for _, txID := range allTxRandomize {
484 invalidTx := false
485 for i := range invalidTxIDs {
486 if invalidTxIDs[i] == txID {
487 invalidTx = true
488 reorgedTxIDs = append(reorgedTxIDs, txID)
489 }
490 }
491 if !invalidTx {
492 if randomizer%2 == 0 {
493 doneForgingTxIDs = append(doneForgingTxIDs, txID)
494 }
495 nonReorgedTxIDs = append(nonReorgedTxIDs, txID)
496 randomizer++
497 }
498 }
499 // Done forging txs BEFORE reorgBatch --> nonReorg
500 err = l2DB.DoneForging(doneForgingTxIDs, lastValidBatch)
501 assert.NoError(t, err)
502 // Invalidate txs in reorgBatch --> Reorg
503 err = l2DB.InvalidateTxs(invalidTxIDs, reorgBatch)
504 assert.NoError(t, err)
505
506 err = l2DB.Reorg(lastValidBatch)
507 assert.NoError(t, err)
508 for _, id := range reorgedTxIDs {
509 tx, err := l2DB.GetTxAPI(id)
510 assert.NoError(t, err)
511 assert.Nil(t, tx.BatchNum)
512 assert.Equal(t, common.PoolL2TxStatePending, tx.State)
513 }
514 for _, id := range nonReorgedTxIDs {
515 fetchedTx, err := l2DB.GetTxAPI(id)
516 assert.NoError(t, err)
517 assert.Equal(t, lastValidBatch, *fetchedTx.BatchNum)
518 }
519}
520
521func TestPurge(t *testing.T) {
522 // Generate txs
523 err := prepareHistoryDB(historyDB)
524 if err != nil {
525 log.Error("Error prepare historyDB", err)
526 }
527 // generatePoolL2Txs generate 10 txs
528 generateTx := int(l2DB.maxTxs/10 + 1)
529 var poolL2Tx []common.PoolL2Tx
530 for i := 0; i < generateTx; i++ {
531 poolL2TxAux, err := generatePoolL2Txs()
532 assert.NoError(t, err)
533 poolL2Tx = append(poolL2Tx, poolL2TxAux...)
534 }
535
536 deletedIDs := []common.TxID{}
537 keepedIDs := []common.TxID{}
538 var invalidTxIDs []common.TxID
539 var doneForgingTxIDs []common.TxID
540 const toDeleteBatchNum common.BatchNum = 30
541 safeBatchNum := toDeleteBatchNum + l2DB.safetyPeriod + 1
542 // Add txs to the DB
543 for i := 0; i < int(l2DB.maxTxs); i++ {
544 tx := poolL2Tx[i]
545 if i%2 == 0 { // keep tx
546 keepedIDs = append(keepedIDs, tx.TxID)
547 } else { // delete after safety period
548 if i%3 == 0 {
549 doneForgingTxIDs = append(doneForgingTxIDs, tx.TxID)
550 } else {
551 invalidTxIDs = append(invalidTxIDs, tx.TxID)
552 }
553 deletedIDs = append(deletedIDs, tx.TxID)
554 }
555 err := l2DB.AddTxTest(&tx)
556 assert.NoError(t, err)
557 }
558 // Set batchNum keeped txs
559 for i := range keepedIDs {
560 _, err = l2DB.db.Exec(
561 "UPDATE tx_pool SET batch_num = $1 WHERE tx_id = $2;",
562 safeBatchNum, keepedIDs[i],
563 )
564 assert.NoError(t, err)
565 }
566 // Start forging txs and set batchNum
567 err = l2DB.StartForging(doneForgingTxIDs, toDeleteBatchNum)
568 assert.NoError(t, err)
569 // Done forging txs and set batchNum
570 err = l2DB.DoneForging(doneForgingTxIDs, toDeleteBatchNum)
571 assert.NoError(t, err)
572 // Invalidate txs and set batchNum
573 err = l2DB.InvalidateTxs(invalidTxIDs, toDeleteBatchNum)
574 assert.NoError(t, err)
575 for i := int(l2DB.maxTxs); i < len(poolL2Tx); i++ {
576 // Delete after TTL
577 deletedIDs = append(deletedIDs, poolL2Tx[i].TxID)
578 err := l2DB.AddTxTest(&poolL2Tx[i])
579 assert.NoError(t, err)
580 // Set timestamp
581 deleteTimestamp := time.Unix(time.Now().UTC().Unix()-int64(l2DB.ttl.Seconds()+float64(4*time.Second)), 0)
582 _, err = l2DB.db.Exec(
583 "UPDATE tx_pool SET timestamp = $1 WHERE tx_id = $2;",
584 deleteTimestamp, poolL2Tx[i].TxID,
585 )
586 assert.NoError(t, err)
587 }
588
589 // Purge txs
590 err = l2DB.Purge(safeBatchNum)
591 assert.NoError(t, err)
592 // Check results
593 for _, id := range deletedIDs {
594 tx, err := l2DB.GetTx(id)
595 if err == nil {
596 log.Debug(tx)
597 }
598 assert.Error(t, err)
599 }
600 for _, id := range keepedIDs {
601 _, err := l2DB.GetTx(id)
602 assert.NoError(t, err)
603 }
604}
605
606func TestAuth(t *testing.T) {
607 test.WipeDB(l2DB.DB())
608 const nAuths = 5
609 // Generate authorizations
610 auths := test.GenAuths(nAuths)
611 for i := 0; i < len(auths); i++ {
612 // Add to the DB
613 err := l2DB.AddAccountCreationAuth(auths[i])
614 assert.NoError(t, err)
615 // Fetch from DB
616 auth, err := l2DB.GetAccountCreationAuth(auths[i].EthAddr)
617 assert.NoError(t, err)
618 // Check fetched vs generated
619 assert.Equal(t, auths[i].EthAddr, auth.EthAddr)
620 assert.Equal(t, auths[i].BJJ, auth.BJJ)
621 assert.Equal(t, auths[i].Signature, auth.Signature)
622 assert.Equal(t, auths[i].Timestamp.Unix(), auths[i].Timestamp.Unix())
623 nameZone, offset := auths[i].Timestamp.Zone()
624 assert.Equal(t, "UTC", nameZone)
625 assert.Equal(t, 0, offset)
626 }
627}