mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add Coordinator goroutines & channels processes
Add Coordinator goroutines & channels processes - Add Coordinator goroutines & channels - Add Coordinator test to debug batches - Add MakeCheckpoint call after BatchBuilder BuildBatch process - Update ethClient BlockByNumber to return hermez/common.Block instead of go-ethereum/core/types.Block
This commit is contained in:
50
test/txs.go
50
test/txs.go
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
ethCrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
@@ -53,12 +55,12 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
|
||||
accounts := GenerateKeys(t, instructions.Accounts)
|
||||
l1CreatedAccounts := make(map[string]*Account)
|
||||
|
||||
var batchL1txs []*common.L1Tx
|
||||
var batchCoordinatorL1txs []*common.L1Tx
|
||||
var batchL2txs []*common.PoolL2Tx
|
||||
var l1txs [][]*common.L1Tx
|
||||
var coordinatorL1txs [][]*common.L1Tx
|
||||
var l2txs [][]*common.PoolL2Tx
|
||||
var batchL1Txs []*common.L1Tx
|
||||
var batchCoordinatorL1Txs []*common.L1Tx
|
||||
var batchPoolL2Txs []*common.PoolL2Tx
|
||||
var l1Txs [][]*common.L1Tx
|
||||
var coordinatorL1Txs [][]*common.L1Tx
|
||||
var poolL2Txs [][]*common.PoolL2Tx
|
||||
idx := 1
|
||||
for _, inst := range instructions.Instructions {
|
||||
switch inst.Type {
|
||||
@@ -71,7 +73,7 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
|
||||
LoadAmount: big.NewInt(int64(inst.Amount)),
|
||||
Type: common.TxTypeCreateAccountDeposit,
|
||||
}
|
||||
batchL1txs = append(batchL1txs, &tx)
|
||||
batchL1Txs = append(batchL1Txs, &tx)
|
||||
if accounts[idxTokenIDToString(inst.From, inst.TokenID)].Idx == common.Idx(0) { // if account.Idx is not set yet, set it and increment idx
|
||||
accounts[idxTokenIDToString(inst.From, inst.TokenID)].Idx = common.Idx(idx)
|
||||
|
||||
@@ -90,7 +92,7 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
|
||||
}
|
||||
accounts[idxTokenIDToString(inst.To, inst.TokenID)].Idx = common.Idx(idx)
|
||||
l1CreatedAccounts[idxTokenIDToString(inst.To, inst.TokenID)] = accounts[idxTokenIDToString(inst.To, inst.TokenID)]
|
||||
batchCoordinatorL1txs = append(batchCoordinatorL1txs, &tx)
|
||||
batchCoordinatorL1Txs = append(batchCoordinatorL1Txs, &tx)
|
||||
idx++
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
|
||||
tx.Signature = sig
|
||||
|
||||
accounts[idxTokenIDToString(inst.From, inst.TokenID)].Nonce++
|
||||
batchL2txs = append(batchL2txs, &tx)
|
||||
batchPoolL2Txs = append(batchPoolL2Txs, &tx)
|
||||
|
||||
case common.TxTypeExit, common.TxTypeForceExit:
|
||||
tx := common.L1Tx{
|
||||
@@ -130,22 +132,30 @@ func GenerateTestTxs(t *testing.T, instructions Instructions) ([][]*common.L1Tx,
|
||||
Amount: big.NewInt(int64(inst.Amount)),
|
||||
Type: common.TxTypeExit,
|
||||
}
|
||||
batchL1txs = append(batchL1txs, &tx)
|
||||
batchL1Txs = append(batchL1Txs, &tx)
|
||||
case TypeNewBatch:
|
||||
l1txs = append(l1txs, batchL1txs)
|
||||
coordinatorL1txs = append(coordinatorL1txs, batchCoordinatorL1txs)
|
||||
l2txs = append(l2txs, batchL2txs)
|
||||
batchL1txs = []*common.L1Tx{}
|
||||
batchCoordinatorL1txs = []*common.L1Tx{}
|
||||
batchL2txs = []*common.PoolL2Tx{}
|
||||
l1Txs = append(l1Txs, batchL1Txs)
|
||||
coordinatorL1Txs = append(coordinatorL1Txs, batchCoordinatorL1Txs)
|
||||
poolL2Txs = append(poolL2Txs, batchPoolL2Txs)
|
||||
batchL1Txs = []*common.L1Tx{}
|
||||
batchCoordinatorL1Txs = []*common.L1Tx{}
|
||||
batchPoolL2Txs = []*common.PoolL2Tx{}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
l1txs = append(l1txs, batchL1txs)
|
||||
coordinatorL1txs = append(coordinatorL1txs, batchCoordinatorL1txs)
|
||||
l2txs = append(l2txs, batchL2txs)
|
||||
l1Txs = append(l1Txs, batchL1Txs)
|
||||
coordinatorL1Txs = append(coordinatorL1Txs, batchCoordinatorL1Txs)
|
||||
poolL2Txs = append(poolL2Txs, batchPoolL2Txs)
|
||||
|
||||
return l1txs, coordinatorL1txs, l2txs
|
||||
return l1Txs, coordinatorL1Txs, poolL2Txs
|
||||
}
|
||||
|
||||
func GenerateTestTxsFromSet(t *testing.T, set string) ([][]*common.L1Tx, [][]*common.L1Tx, [][]*common.PoolL2Tx) {
|
||||
parser := NewParser(strings.NewReader(set))
|
||||
instructions, err := parser.Parse()
|
||||
require.Nil(t, err)
|
||||
|
||||
return GenerateTestTxs(t, instructions)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user