Update Synchroinzer and tests

- Test L1UserTxs in Synchronizer
- Test Batches in Synchronizer
- Add last_idx in `TABLE batch` in HistoryDB
- Minor updates in til to satisfy blockchain constraints
This commit is contained in:
Eduard S
2020-10-22 18:51:42 +02:00
parent 2aa5598975
commit b5222303c2
8 changed files with 308 additions and 200 deletions

View File

@@ -1,12 +1,12 @@
package historydb
import (
"fmt"
"math"
"math/big"
"os"
"testing"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/hermeznetwork/hermez-node/common"
dbUtils "github.com/hermeznetwork/hermez-node/db"
"github.com/hermeznetwork/hermez-node/log"
@@ -406,25 +406,10 @@ func TestGetL1UserTxs(t *testing.T) {
require.Equal(t, 5, len(blocks[0].L1UserTxs))
// fmt.Printf("DBG Blocks: %+v\n", blocks)
// TODO: Move this logic to `func (tc *TestContext) GenerateBlocks(set string) ([]common.BlockData, error)`
toForgeL1TxsNum := int64(1)
for i := range blocks {
block := &blocks[i]
block.Block.EthBlockNum = int64(i)
for j := range block.AddedTokens {
token := &block.AddedTokens[j]
token.EthAddr = ethCommon.BigToAddress(big.NewInt(int64(i*len(blocks) + j)))
}
for j := range block.L1UserTxs {
l1Tx := &block.L1UserTxs[j]
l1Tx.UserOrigin = true
l1Tx.Position = j
l1Tx.ToForgeL1TxsNum = &toForgeL1TxsNum
}
}
for i := range blocks {
// fmt.Printf("DBG %+v\n", blocks[i])
fmt.Printf("DBG %+v\n", blocks[i])
// fmt.Printf("DBG Batches %+v\n", blocks[i].Batches)
// for _, l1Tx := range blocks[i].L1UserTxs {
// fmt.Printf("DBG l1UserTx %+v\n", l1Tx)
@@ -433,25 +418,6 @@ func TestGetL1UserTxs(t *testing.T) {
require.Nil(t, err)
}
// // TODO: Use til to generate a set with some L1UserTxs
// l1Txs := []common.L1Tx{}
// l1Tx, err := common.NewL1Tx(&common.L1Tx{
// ToForgeL1TxsNum: &toForgeL1TxsNum,
// Position: 0,
// UserOrigin: true,
// FromIdx: 0,
// FromEthAddr: ethCommon.Address{}, // ethCommon.HexToAddress("0xff"),
// FromBJJ: nil,
// ToIdx: 0,
// TokenID: 1,
// Amount: big.NewInt(0),
// LoadAmount: big.NewInt(0),
// })
// require.Nil(t, err)
// l1Txs = append(l1Txs, *l1Tx)
// require.Nil(t, historyDB.AddL1Txs(l1Txs))
l1UserTxs, err := historyDB.GetL1UserTxs(toForgeL1TxsNum)
require.Nil(t, err)
assert.Equal(t, 5, len(l1UserTxs))