mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add lll to linter checks
Updated: batchbuilder common coordinator db/statedb eth log node priceupdater prover synchronizer test/* txprocessor txselector Pending (once https://github.com/hermeznetwork/hermez-node/tree/feature/serveapicli is merged to master): Update golangci-lint version to v1.37.1 api apitypes cli config db/historydb db/l2db
This commit is contained in:
@@ -447,7 +447,8 @@ func (txsel *TxSelector) getL1L2TxSelection(selectionConfig *SelectionConfig,
|
||||
// send the fee to the Idx of the Coordinator for the TokenID
|
||||
accCoord, err := txsel.localAccountsDB.GetAccount(idx)
|
||||
if err != nil {
|
||||
log.Errorw("Can not distribute accumulated fees to coordinator account: No coord Idx to receive fee", "idx", idx)
|
||||
log.Errorw("Can not distribute accumulated fees to coordinator "+
|
||||
"account: No coord Idx to receive fee", "idx", idx)
|
||||
return nil, nil, nil, nil, nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
accCoord.Balance = new(big.Int).Add(accCoord.Balance, accumulatedFee)
|
||||
@@ -511,14 +512,19 @@ func (txsel *TxSelector) processTxToEthAddrBJJ(validTxs []common.PoolL2Tx,
|
||||
accAuth, err = txsel.l2db.GetAccountCreationAuth(l2Tx.ToEthAddr)
|
||||
if err != nil {
|
||||
// not found, l2Tx will not be added in the selection
|
||||
return nil, nil, nil, tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found in StateDB, neither ToEthAddr found in AccountCreationAuths L2DB. ToIdx: %d, ToEthAddr: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr.Hex()))
|
||||
return nil, nil, nil,
|
||||
tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found "+
|
||||
"in StateDB, neither ToEthAddr found in AccountCreationAuths L2DB. ToIdx: %d, ToEthAddr: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr.Hex()))
|
||||
}
|
||||
if accAuth.BJJ != l2Tx.ToBJJ {
|
||||
// if AccountCreationAuth.BJJ is not the same
|
||||
// than in the tx, tx is not accepted
|
||||
return nil, nil, nil, tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found in StateDB, neither ToEthAddr & ToBJJ found in AccountCreationAuths L2DB. ToIdx: %d, ToEthAddr: %s, ToBJJ: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr.Hex(), l2Tx.ToBJJ.String()))
|
||||
return nil, nil, nil,
|
||||
tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found in StateDB, "+
|
||||
"neither ToEthAddr & ToBJJ found in AccountCreationAuths L2DB. "+
|
||||
"ToIdx: %d, ToEthAddr: %s, ToBJJ: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr.Hex(), l2Tx.ToBJJ.String()))
|
||||
}
|
||||
} else {
|
||||
// case: ToBJJ==0:
|
||||
@@ -534,8 +540,11 @@ func (txsel *TxSelector) processTxToEthAddrBJJ(validTxs []common.PoolL2Tx,
|
||||
accAuth, err = txsel.l2db.GetAccountCreationAuth(l2Tx.ToEthAddr)
|
||||
if err != nil {
|
||||
// not found, l2Tx will not be added in the selection
|
||||
return nil, nil, nil, tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found in StateDB, neither ToEthAddr found in AccountCreationAuths L2DB. ToIdx: %d, ToEthAddr: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr))
|
||||
return nil, nil, nil,
|
||||
tracerr.Wrap(fmt.Errorf("invalid L2Tx: ToIdx not found in "+
|
||||
"StateDB, neither ToEthAddr found in "+
|
||||
"AccountCreationAuths L2DB. ToIdx: %d, ToEthAddr: %s",
|
||||
l2Tx.ToIdx, l2Tx.ToEthAddr))
|
||||
}
|
||||
}
|
||||
// create L1CoordinatorTx for the accountCreation
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func initTest(t *testing.T, chainID uint16, hermezContractAddr ethCommon.Address, coordUser *til.User) *TxSelector {
|
||||
func initTest(t *testing.T, chainID uint16, hermezContractAddr ethCommon.Address,
|
||||
coordUser *til.User) *TxSelector {
|
||||
pass := os.Getenv("POSTGRES_PASS")
|
||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||
require.NoError(t, err)
|
||||
@@ -67,7 +68,8 @@ func initTest(t *testing.T, chainID uint16, hermezContractAddr ethCommon.Address
|
||||
return txsel
|
||||
}
|
||||
|
||||
func addAccCreationAuth(t *testing.T, tc *til.Context, txsel *TxSelector, chainID uint16, hermezContractAddr ethCommon.Address, username string) []byte {
|
||||
func addAccCreationAuth(t *testing.T, tc *til.Context, txsel *TxSelector, chainID uint16,
|
||||
hermezContractAddr ethCommon.Address, username string) []byte {
|
||||
user := tc.Users[username]
|
||||
auth := &common.AccountCreationAuth{
|
||||
EthAddr: user.Addr,
|
||||
@@ -113,13 +115,15 @@ func addTokens(t *testing.T, tc *til.Context, db *sqlx.DB) {
|
||||
assert.NoError(t, hdb.AddTokens(tokens))
|
||||
}
|
||||
|
||||
func checkBalance(t *testing.T, tc *til.Context, txsel *TxSelector, username string, tokenid int, expected string) {
|
||||
func checkBalance(t *testing.T, tc *til.Context, txsel *TxSelector, username string,
|
||||
tokenid int, expected string) {
|
||||
// Accounts.Idx does not match with the TxSelector tests as we are not
|
||||
// using the Til L1CoordinatorTxs (as are generated by the TxSelector
|
||||
// itself when processing the txs, so the Idxs does not match the Til
|
||||
// idxs). But the Idx is obtained through StateDB.GetIdxByEthAddrBJJ
|
||||
user := tc.Users[username]
|
||||
idx, err := txsel.localAccountsDB.GetIdxByEthAddrBJJ(user.Addr, user.BJJ.Public().Compress(), common.TokenID(tokenid))
|
||||
idx, err := txsel.localAccountsDB.GetIdxByEthAddrBJJ(user.Addr, user.BJJ.Public().Compress(),
|
||||
common.TokenID(tokenid))
|
||||
require.NoError(t, err)
|
||||
checkBalanceByIdx(t, txsel, idx, expected)
|
||||
}
|
||||
@@ -133,7 +137,8 @@ func checkBalanceByIdx(t *testing.T, txsel *TxSelector, idx common.Idx, expected
|
||||
// checkSortedByNonce takes as input testAccNonces map, and the array of
|
||||
// common.PoolL2Txs, and checks if the nonces correspond to the accumulated
|
||||
// values of the map. Also increases the Nonces computed on the map.
|
||||
func checkSortedByNonce(t *testing.T, testAccNonces map[common.Idx]common.Nonce, txs []common.PoolL2Tx) {
|
||||
func checkSortedByNonce(t *testing.T, testAccNonces map[common.Idx]common.Nonce,
|
||||
txs []common.PoolL2Tx) {
|
||||
for _, tx := range txs {
|
||||
assert.True(t, testAccNonces[tx.FromIdx] == tx.Nonce,
|
||||
fmt.Sprintf("Idx: %d, expected: %d, tx.Nonce: %d",
|
||||
@@ -178,7 +183,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:1")
|
||||
l1UserTxs := []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err := txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -188,7 +194,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:2")
|
||||
l1UserTxs = []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -198,7 +205,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:3")
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[2].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -210,7 +218,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:4")
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[3].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -223,7 +232,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:5")
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[4].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -236,7 +246,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
|
||||
log.Debug("block:0 batch:6")
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[5].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -269,7 +280,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
assert.True(t, l2TxsFromDB[0].VerifySignature(chainID, tc.Users["A"].BJJ.Public().Compress()))
|
||||
assert.True(t, l2TxsFromDB[1].VerifySignature(chainID, tc.Users["B"].BJJ.Public().Compress()))
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[6].Batch.ForgeL1TxsNum])
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err := txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []common.Idx{261, 262}, coordIdxs)
|
||||
assert.Equal(t, txsel.coordAccount.AccountCreationAuth, accAuths[0])
|
||||
@@ -291,7 +303,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
checkBalance(t, tc, txsel, "C", 0, "100")
|
||||
checkBalance(t, tc, txsel, "D", 0, "800")
|
||||
checkSortedByNonce(t, testAccNonces, oL2Txs)
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
log.Debug("block:0 batch:8")
|
||||
@@ -315,7 +328,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
assert.True(t, l2TxsFromDB[2].VerifySignature(chainID, tc.Users["B"].BJJ.Public().Compress()))
|
||||
assert.True(t, l2TxsFromDB[3].VerifySignature(chainID, tc.Users["A"].BJJ.Public().Compress()))
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[7].Batch.ForgeL1TxsNum])
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []common.Idx{261, 262}, coordIdxs)
|
||||
assert.Equal(t, 0, len(accAuths))
|
||||
@@ -335,7 +349,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
checkBalance(t, tc, txsel, "C", 1, "100")
|
||||
checkBalance(t, tc, txsel, "D", 0, "800")
|
||||
checkSortedByNonce(t, testAccNonces, oL2Txs)
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
log.Debug("(batch9)block:1 batch:1")
|
||||
@@ -356,7 +371,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
assert.True(t, l2TxsFromDB[0].VerifySignature(chainID, tc.Users["D"].BJJ.Public().Compress()))
|
||||
assert.True(t, l2TxsFromDB[1].VerifySignature(chainID, tc.Users["B"].BJJ.Public().Compress()))
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[1].Rollup.Batches[0].Batch.ForgeL1TxsNum])
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
coordIdxs, accAuths, oL1UserTxs, oL1CoordTxs, oL2Txs, _, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []common.Idx{262}, coordIdxs)
|
||||
assert.Equal(t, 0, len(accAuths))
|
||||
@@ -376,7 +392,8 @@ func TestGetL2TxSelectionMinimumFlow0(t *testing.T) {
|
||||
checkBalance(t, tc, txsel, "C", 1, "100")
|
||||
checkBalance(t, tc, txsel, "D", 0, "470")
|
||||
checkSortedByNonce(t, testAccNonces, oL2Txs)
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -423,10 +440,12 @@ func TestPoolL2TxsWithoutEnoughBalance(t *testing.T) {
|
||||
l1UserTxs := []common.L1Tx{}
|
||||
_, _, _, _, _, _, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedTxID0 := "0x028847b86613c0b70be18c8622119ed045b42e4e47d7938fa90bb3d1dc14928965" // 1st TransferToEthAddr
|
||||
expectedTxID1 := "0x0200b18773dcf56f770d65870fb02041cb59a088fd35b7c3f3df69f8a250b99a42" // 1st Exit
|
||||
expectedTxID2 := "0x029720ff506153f970f120ac638cd7ee759eeff2c2012e7634a78e4fdc05c04a90" // 2nd TransferToEthAddr
|
||||
// 1st TransferToEthAddr
|
||||
expectedTxID0 := "0x028847b86613c0b70be18c8622119ed045b42e4e47d7938fa90bb3d1dc14928965"
|
||||
// 1st Exit
|
||||
expectedTxID1 := "0x0200b18773dcf56f770d65870fb02041cb59a088fd35b7c3f3df69f8a250b99a42"
|
||||
// 2nd TransferToEthAddr
|
||||
expectedTxID2 := "0x029720ff506153f970f120ac638cd7ee759eeff2c2012e7634a78e4fdc05c04a90"
|
||||
|
||||
// batch2
|
||||
// prepare the PoolL2Txs
|
||||
@@ -440,7 +459,8 @@ func TestPoolL2TxsWithoutEnoughBalance(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[1].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err := txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 3, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -448,7 +468,8 @@ func TestPoolL2TxsWithoutEnoughBalance(t *testing.T) {
|
||||
assert.Equal(t, 2, len(discardedL2Txs))
|
||||
assert.Equal(t, expectedTxID0, discardedL2Txs[0].TxID.String())
|
||||
assert.Equal(t, expectedTxID1, discardedL2Txs[1].TxID.String())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
// as the PoolL2Txs have not been really processed, restart nonces
|
||||
@@ -468,7 +489,8 @@ func TestPoolL2TxsWithoutEnoughBalance(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
|
||||
l1UserTxs = []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
@@ -478,23 +500,27 @@ func TestPoolL2TxsWithoutEnoughBalance(t *testing.T) {
|
||||
assert.Equal(t, expectedTxID0, discardedL2Txs[0].TxID.String())
|
||||
assert.Equal(t, expectedTxID1, discardedL2Txs[1].TxID.String())
|
||||
assert.Equal(t, common.TxTypeTransferToEthAddr, oL2Txs[0].Type)
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
// batch4
|
||||
// make the selection of another batch, which should include the
|
||||
// initial PoolExit, which now is valid as B has enough Balance
|
||||
l1UserTxs = []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
assert.Equal(t, 1, len(oL2Txs))
|
||||
assert.Equal(t, 1, len(discardedL2Txs))
|
||||
assert.Equal(t, expectedTxID1, oL2Txs[0].TxID.String()) // the Exit that was not accepted at the batch2
|
||||
// the Exit that was not accepted at the batch2
|
||||
assert.Equal(t, expectedTxID1, oL2Txs[0].TxID.String())
|
||||
assert.Equal(t, expectedTxID0, discardedL2Txs[0].TxID.String())
|
||||
assert.Equal(t, common.TxTypeExit, oL2Txs[0].Type)
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -558,7 +584,8 @@ func TestTransferToBjj(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[1].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err := txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 4, len(oL1UserTxs))
|
||||
// We expect the coordinator to add an L1CoordTx to create an account for the recipient of the l2tx
|
||||
@@ -568,7 +595,8 @@ func TestTransferToBjj(t *testing.T) {
|
||||
// fmt.Printf("DBG l1CoordTx[0]: %+v\n", oL1CoordTxs[0])
|
||||
assert.Equal(t, 1, len(oL2Txs))
|
||||
assert.Equal(t, 0, len(discardedL2Txs))
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now the BJJ-only account for B is already created, so the transfer
|
||||
@@ -584,14 +612,16 @@ func TestTransferToBjj(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
|
||||
l1UserTxs = []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
// Since the BJJ-only account B already exists, the coordinator doesn't add any L1CoordTxs
|
||||
assert.Equal(t, 0, len(oL1CoordTxs))
|
||||
assert.Equal(t, 1, len(oL2Txs))
|
||||
assert.Equal(t, 0, len(discardedL2Txs))
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
|
||||
// The transfer now is ToBJJ to a BJJ-only account that doesn't exist
|
||||
@@ -610,7 +640,8 @@ func TestTransferToBjj(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
|
||||
l1UserTxs = []common.L1Tx{}
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err = txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err =
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, len(oL1UserTxs))
|
||||
// We expect the coordinator to add an L1CoordTx to create an account
|
||||
@@ -626,7 +657,8 @@ func TestTransferToBjj(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 1, len(oL2Txs))
|
||||
assert.Equal(t, 0, len(discardedL2Txs))
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -699,13 +731,15 @@ func TestTransferManyFromSameAccount(t *testing.T) {
|
||||
addL2Txs(t, txsel, poolL2Txs)
|
||||
// batch 2 to crate some accounts with positive balance, and do 8 L2Tx transfers from account A
|
||||
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[1].Batch.ForgeL1TxsNum])
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err := txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
_, _, oL1UserTxs, oL1CoordTxs, oL2Txs, discardedL2Txs, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 3, len(oL1UserTxs))
|
||||
require.Equal(t, 0, len(oL1CoordTxs))
|
||||
assert.Equal(t, 7, len(oL2Txs))
|
||||
assert.Equal(t, 1, len(discardedL2Txs))
|
||||
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs), txsel.localAccountsDB.CurrentBatch())
|
||||
err = txsel.l2db.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
|
||||
txsel.localAccountsDB.CurrentBatch())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user