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:
arnaucube
2021-03-01 12:19:27 +01:00
parent 73c3a91746
commit 93b7866d3e
63 changed files with 1570 additions and 757 deletions

View File

@@ -66,10 +66,12 @@ type ProcessTxOutput struct {
func newErrorNotEnoughBalance(tx common.Tx) error {
var msg error
if tx.IsL1 {
msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d",
msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. "+
"TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d",
tx.TxID, tx.Type, tx.FromIdx, tx.ToIdx, tx.Amount)
} else {
msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d, Fee: %d",
msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. "+
"TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d, Fee: %d",
tx.TxID, tx.Type, tx.FromIdx, tx.ToIdx, tx.Amount, tx.Fee)
}
return tracerr.Wrap(msg)
@@ -116,21 +118,28 @@ func (tp *TxProcessor) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinat
var createdAccounts []common.Account
if tp.zki != nil {
return nil, tracerr.Wrap(errors.New("Expected StateDB.zki==nil, something went wrong and it's not empty"))
return nil, tracerr.Wrap(
errors.New("Expected StateDB.zki==nil, something went wrong and it's not empty"))
}
defer tp.resetZKInputs()
if len(coordIdxs) >= int(tp.config.MaxFeeTx) {
return nil, tracerr.Wrap(fmt.Errorf("CoordIdxs (%d) length must be smaller than MaxFeeTx (%d)", len(coordIdxs), tp.config.MaxFeeTx))
return nil, tracerr.Wrap(
fmt.Errorf("CoordIdxs (%d) length must be smaller than MaxFeeTx (%d)",
len(coordIdxs), tp.config.MaxFeeTx))
}
nTx := len(l1usertxs) + len(l1coordinatortxs) + len(l2txs)
if nTx > int(tp.config.MaxTx) {
return nil, tracerr.Wrap(fmt.Errorf("L1UserTx + L1CoordinatorTx + L2Tx (%d) can not be bigger than MaxTx (%d)", nTx, tp.config.MaxTx))
return nil, tracerr.Wrap(
fmt.Errorf("L1UserTx + L1CoordinatorTx + L2Tx (%d) can not be bigger than MaxTx (%d)",
nTx, tp.config.MaxTx))
}
if len(l1usertxs)+len(l1coordinatortxs) > int(tp.config.MaxL1Tx) {
return nil, tracerr.Wrap(fmt.Errorf("L1UserTx + L1CoordinatorTx (%d) can not be bigger than MaxL1Tx (%d)", len(l1usertxs)+len(l1coordinatortxs), tp.config.MaxTx))
return nil,
tracerr.Wrap(fmt.Errorf("L1UserTx + L1CoordinatorTx (%d) can not be bigger than MaxL1Tx (%d)",
len(l1usertxs)+len(l1coordinatortxs), tp.config.MaxTx))
}
if tp.s.Type() == statedb.TypeSynchronizer {
@@ -377,7 +386,8 @@ func (tp *TxProcessor) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinat
// works)
accCoord, err := tp.s.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, tracerr.Wrap(err)
}
if tp.zki != nil {
@@ -483,7 +493,8 @@ func (tp *TxProcessor) getFeePlanTokens(coordIdxs []common.Idx) ([]*big.Int, err
for i := 0; i < len(coordIdxs); i++ {
acc, err := tp.s.GetAccount(coordIdxs[i])
if err != nil {
log.Errorf("could not get account to determine TokenID of CoordIdx %d not found: %s", coordIdxs[i], err.Error())
log.Errorf("could not get account to determine TokenID of CoordIdx %d not found: %s",
coordIdxs[i], err.Error())
return nil, tracerr.Wrap(err)
}
tBI = append(tBI, acc.TokenID.BigInt())
@@ -642,7 +653,8 @@ func (tp *TxProcessor) ProcessL2Tx(coordIdxsMap map[common.TokenID]common.Idx,
if tp.s.Type() == statedb.TypeSynchronizer {
// thisTypeould never be reached
log.Error("WARNING: In StateDB with Synchronizer mode L2.ToIdx can't be 0")
return nil, nil, false, tracerr.Wrap(fmt.Errorf("In StateDB with Synchronizer mode L2.ToIdx can't be 0"))
return nil, nil, false,
tracerr.Wrap(fmt.Errorf("In StateDB with Synchronizer mode L2.ToIdx can't be 0"))
}
// case when tx.Type== common.TxTypeTransferToEthAddr or common.TxTypeTransferToBJJ
@@ -730,7 +742,8 @@ func (tp *TxProcessor) ProcessL2Tx(coordIdxsMap map[common.TokenID]common.Idx,
}
case common.TxTypeExit:
// execute exit flow
exitAccount, newExit, err := tp.applyExit(coordIdxsMap, collectedFees, exitTree, tx.Tx(), tx.Amount)
exitAccount, newExit, err := tp.applyExit(coordIdxsMap, collectedFees, exitTree,
tx.Tx(), tx.Amount)
if err != nil {
log.Error(err)
return nil, nil, false, tracerr.Wrap(err)
@@ -790,7 +803,8 @@ func (tp *TxProcessor) applyCreateAccount(tx *common.L1Tx) error {
// createAccount is a wrapper over the StateDB.CreateAccount method that also
// stores the created account in the updatedAccounts map in case the StateDB is
// of TypeSynchronizer
func (tp *TxProcessor) createAccount(idx common.Idx, account *common.Account) (*merkletree.CircomProcessorProof, error) {
func (tp *TxProcessor) createAccount(idx common.Idx, account *common.Account) (
*merkletree.CircomProcessorProof, error) {
if tp.s.Type() == statedb.TypeSynchronizer {
account.Idx = idx
tp.updatedAccounts[idx] = account
@@ -801,7 +815,8 @@ func (tp *TxProcessor) createAccount(idx common.Idx, account *common.Account) (*
// updateAccount is a wrapper over the StateDB.UpdateAccount method that also
// stores the updated account in the updatedAccounts map in case the StateDB is
// of TypeSynchronizer
func (tp *TxProcessor) updateAccount(idx common.Idx, account *common.Account) (*merkletree.CircomProcessorProof, error) {
func (tp *TxProcessor) updateAccount(idx common.Idx, account *common.Account) (
*merkletree.CircomProcessorProof, error) {
if tp.s.Type() == statedb.TypeSynchronizer {
account.Idx = idx
tp.updatedAccounts[idx] = account
@@ -937,7 +952,9 @@ func (tp *TxProcessor) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
if _, ok := coordIdxsMap[accSender.TokenID]; ok {
accCoord, err := tp.s.GetAccount(coordIdxsMap[accSender.TokenID])
if err != nil {
return tracerr.Wrap(fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d", accSender.TokenID, coordIdxsMap[accSender.TokenID]))
return tracerr.Wrap(
fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d",
accSender.TokenID, coordIdxsMap[accSender.TokenID]))
}
// accumulate the fee for the Coord account
accumulated := tp.AccumulatedFees[accCoord.Idx]
@@ -1141,7 +1158,9 @@ func (tp *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
if _, ok := coordIdxsMap[acc.TokenID]; ok {
accCoord, err := tp.s.GetAccount(coordIdxsMap[acc.TokenID])
if err != nil {
return nil, false, tracerr.Wrap(fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d", acc.TokenID, coordIdxsMap[acc.TokenID]))
return nil, false, tracerr.Wrap(
fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d",
acc.TokenID, coordIdxsMap[acc.TokenID]))
}
// accumulate the fee for the Coord account
@@ -1301,13 +1320,15 @@ func (tp *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) {
// check if tx.TokenID==receiver.TokenID
accReceiver, err := tp.s.GetAccount(tx.ToIdx)
if err != nil {
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d",
tx.ToIdx)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0)
return
}
if tx.TokenID != accReceiver.TokenID {
log.Debugf("EffectiveAmount = 0: tx TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accReceiver.TokenID)
log.Debugf("EffectiveAmount = 0: tx TokenID (%d) != receiver account TokenID (%d)",
tx.TokenID, accReceiver.TokenID)
tx.EffectiveAmount = big.NewInt(0)
return
}
@@ -1316,7 +1337,8 @@ func (tp *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) {
accSender, err := tp.s.GetAccount(tx.FromIdx)
if err != nil {
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.FromIdx: %d", tx.FromIdx)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.FromIdx: %d",
tx.FromIdx)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0)
return
@@ -1324,7 +1346,9 @@ func (tp *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) {
// check that tx.TokenID corresponds to the Sender account TokenID
if tx.TokenID != accSender.TokenID {
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx.TokenID (%d) !=sender account TokenID (%d)", tx.TokenID, accSender.TokenID)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: "+
"tx.TokenID (%d) !=sender account TokenID (%d)",
tx.TokenID, accSender.TokenID)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0)
return
@@ -1345,7 +1369,9 @@ func (tp *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) {
// check that the tx.FromEthAddr is the same than the EthAddress of the
// Sender
if !bytes.Equal(tx.FromEthAddr.Bytes(), accSender.EthAddr.Bytes()) {
log.Debugf("EffectiveAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of the sender account by the Idx (%s)", tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
log.Debugf("EffectiveAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of "+
"the sender account by the Idx (%s)",
tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
tx.EffectiveAmount = big.NewInt(0)
}
@@ -1357,18 +1383,22 @@ func (tp *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) {
// check that TokenID is the same for Sender & Receiver account
accReceiver, err := tp.s.GetAccount(tx.ToIdx)
if err != nil {
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d",
tx.ToIdx)
tx.EffectiveDepositAmount = big.NewInt(0)
tx.EffectiveAmount = big.NewInt(0)
return
}
if accSender.TokenID != accReceiver.TokenID {
log.Debugf("EffectiveAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", accSender.TokenID, accReceiver.TokenID)
log.Debugf("EffectiveAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)",
accSender.TokenID, accReceiver.TokenID)
tx.EffectiveAmount = big.NewInt(0)
return
}
if tx.TokenID != accReceiver.TokenID {
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accReceiver.TokenID)
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: "+
"tx TokenID (%d) != receiver account TokenID (%d)",
tx.TokenID, accReceiver.TokenID)
tx.EffectiveAmount = big.NewInt(0)
return
}

View File

@@ -17,7 +17,8 @@ import (
"github.com/stretchr/testify/require"
)
func checkBalance(t *testing.T, tc *til.Context, sdb *statedb.StateDB, username string, tokenid int, expected string) {
func checkBalance(t *testing.T, tc *til.Context, sdb *statedb.StateDB, username string,
tokenid int, expected string) {
idx := tc.Users[username].Accounts[common.TokenID(tokenid)].Idx
acc, err := sdb.GetAccount(idx)
require.NoError(t, err)
@@ -249,7 +250,9 @@ func TestProcessTxsBalances(t *testing.T) {
_, err = tp.ProcessTxs(nil, l1UserTxs, blocks[0].Rollup.Batches[2].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
checkBalance(t, tc, sdb, "A", 0, "500")
assert.Equal(t, "13644148972047617726265275926674266298636745191961029124811988256139761111521", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"13644148972047617726265275926674266298636745191961029124811988256139761111521",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:4")
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[3].Batch.ForgeL1TxsNum])
@@ -258,7 +261,9 @@ func TestProcessTxsBalances(t *testing.T) {
require.NoError(t, err)
checkBalance(t, tc, sdb, "A", 0, "500")
checkBalance(t, tc, sdb, "A", 1, "500")
assert.Equal(t, "12433441613247342495680642890662773367605896324555599297255745922589338651261", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:5")
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[4].Batch.ForgeL1TxsNum])
@@ -267,7 +272,9 @@ func TestProcessTxsBalances(t *testing.T) {
require.NoError(t, err)
checkBalance(t, tc, sdb, "A", 0, "500")
checkBalance(t, tc, sdb, "A", 1, "500")
assert.Equal(t, "12433441613247342495680642890662773367605896324555599297255745922589338651261", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:6")
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[5].Batch.ForgeL1TxsNum])
@@ -277,7 +284,9 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "A", 0, "600")
checkBalance(t, tc, sdb, "A", 1, "500")
checkBalance(t, tc, sdb, "B", 0, "400")
assert.Equal(t, "4191361650490017591061467288209836928064232431729236465872209988325272262963", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"4191361650490017591061467288209836928064232431729236465872209988325272262963",
tp.s.MT.Root().BigInt().String())
coordIdxs := []common.Idx{261, 262}
log.Debug("block:0 batch:7")
@@ -293,7 +302,9 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "B", 1, "200")
checkBalance(t, tc, sdb, "C", 0, "100")
checkBalance(t, tc, sdb, "D", 0, "800")
assert.Equal(t, "7614010373759339299470010949167613050707822522530721724565424494781010548240", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"7614010373759339299470010949167613050707822522530721724565424494781010548240",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:8")
l1UserTxs = til.L1TxsToCommonL1Txs(tc.Queues[*blocks[0].Rollup.Batches[7].Batch.ForgeL1TxsNum])
@@ -309,7 +320,9 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "C", 0, "45")
checkBalance(t, tc, sdb, "C", 1, "100")
checkBalance(t, tc, sdb, "D", 0, "800")
assert.Equal(t, "21231789250434471575486264439945776732824482207853465397552873521865656677689", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"21231789250434471575486264439945776732824482207853465397552873521865656677689",
tp.s.MT.Root().BigInt().String())
coordIdxs = []common.Idx{262}
log.Debug("block:1 batch:1")
@@ -326,7 +339,9 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "C", 0, "845")
checkBalance(t, tc, sdb, "C", 1, "100")
checkBalance(t, tc, sdb, "D", 0, "470")
assert.Equal(t, "11289313644810782435120113035387729451095637380468777086895109386127538554246", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"11289313644810782435120113035387729451095637380468777086895109386127538554246",
tp.s.MT.Root().BigInt().String())
coordIdxs = []common.Idx{}
log.Debug("block:1 batch:2")
@@ -334,7 +349,9 @@ func TestProcessTxsBalances(t *testing.T) {
l2Txs = common.L2TxsToPoolL2Txs(blocks[1].Rollup.Batches[1].L2Txs)
_, err = tp.ProcessTxs(coordIdxs, l1UserTxs, blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
assert.Equal(t, "10342681351319338354912862547249967104198317571995055517008223832276478908482", tp.s.MT.Root().BigInt().String())
assert.Equal(t,
"10342681351319338354912862547249967104198317571995055517008223832276478908482",
tp.s.MT.Root().BigInt().String())
// use Set of PoolL2 txs
poolL2Txs, err := tc.GeneratePoolL2Txs(txsets.SetPoolL2MinimumFlow1)
@@ -446,8 +463,8 @@ func TestProcessTxsSynchronizer(t *testing.T) {
assert.Equal(t, common.Nonce(5), l2Txs[0].Nonce)
assert.Equal(t, common.Nonce(6), l2Txs[1].Nonce)
assert.Equal(t, common.Nonce(7), l2Txs[2].Nonce)
assert.Equal(t, 4, len(ptOut.ExitInfos)) // the 'ForceExit(1)' is not computed yet, as the batch is without L1UserTxs
// the 'ForceExit(1)' is not computed yet, as the batch is without L1UserTxs
assert.Equal(t, 4, len(ptOut.ExitInfos))
assert.Equal(t, 1, len(ptOut.CreatedAccounts))
assert.Equal(t, 4, len(ptOut.CollectedFees))
assert.Equal(t, "0", ptOut.CollectedFees[common.TokenID(0)].String())
@@ -463,8 +480,10 @@ func TestProcessTxsSynchronizer(t *testing.T) {
ptOut, err = tp.ProcessTxs(coordIdxs, blocks[1].Rollup.L1UserTxs,
blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
assert.Equal(t, 1, len(ptOut.ExitInfos)) // 1, as previous batch was without L1UserTxs, and has pending the 'ForceExit(1) A: 5', and the 2 exit transactions get grouped under 1 ExitInfo
// 1, as previous batch was without L1UserTxs, and has pending the
// 'ForceExit(1) A: 5', and the 2 exit transactions get grouped under 1
// ExitInfo
assert.Equal(t, 1, len(ptOut.ExitInfos))
assert.Equal(t, 1, len(ptOut.CreatedAccounts))
assert.Equal(t, 4, len(ptOut.CollectedFees))
assert.Equal(t, "0", ptOut.CollectedFees[common.TokenID(0)].String())
@@ -526,7 +545,8 @@ func TestProcessTxsBatchBuilder(t *testing.T) {
log.Debug("block:0 batch:2")
l2Txs := common.L2TxsToPoolL2Txs(blocks[0].Rollup.Batches[1].L2Txs)
ptOut, err = tp.ProcessTxs(coordIdxs, blocks[0].Rollup.L1UserTxs, blocks[0].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
ptOut, err = tp.ProcessTxs(coordIdxs, blocks[0].Rollup.L1UserTxs,
blocks[0].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
assert.Equal(t, 0, len(ptOut.ExitInfos))
assert.Equal(t, 0, len(ptOut.CreatedAccounts))
@@ -554,7 +574,8 @@ func TestProcessTxsBatchBuilder(t *testing.T) {
log.Debug("block:1 batch:2")
l2Txs = common.L2TxsToPoolL2Txs(blocks[1].Rollup.Batches[1].L2Txs)
_, err = tp.ProcessTxs(coordIdxs, blocks[1].Rollup.L1UserTxs, blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
_, err = tp.ProcessTxs(coordIdxs, blocks[1].Rollup.L1UserTxs,
blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
acc, err = sdb.GetAccount(idxA1)
assert.NoError(t, err)
@@ -575,7 +596,9 @@ func TestProcessTxsBatchBuilder(t *testing.T) {
assert.Equal(t, common.TokenID(1), acc.TokenID)
assert.Equal(t, "2", acc.Balance.String())
assert.Equal(t, "18894163991492573893706613133132363559300580460789469708968288074813925659539", sdb.MT.Root().BigInt().String())
assert.Equal(t,
"18894163991492573893706613133132363559300580460789469708968288074813925659539",
sdb.MT.Root().BigInt().String())
}
func TestProcessTxsRootTestVectors(t *testing.T) {
@@ -588,7 +611,8 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
assert.NoError(t, err)
// same values than in the js test
bjj0, err := common.BJJFromStringWithChecksum("21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d7")
bjj0, err := common.BJJFromStringWithChecksum(
"21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d7")
assert.NoError(t, err)
l1Txs := []common.L1Tx{
{
@@ -626,7 +650,9 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
tp := NewTxProcessor(sdb, config)
_, err = tp.ProcessTxs(nil, l1Txs, nil, l2Txs)
require.NoError(t, err)
assert.Equal(t, "9827704113668630072730115158977131501210702363656902211840117643154933433410", sdb.MT.Root().BigInt().String())
assert.Equal(t,
"9827704113668630072730115158977131501210702363656902211840117643154933433410",
sdb.MT.Root().BigInt().String())
}
func TestCreateAccountDepositMaxValue(t *testing.T) {
@@ -699,7 +725,8 @@ func TestCreateAccountDepositMaxValue(t *testing.T) {
assert.Equal(t, daMax1BI, acc.Balance)
}
func initTestMultipleCoordIdxForTokenID(t *testing.T) (*TxProcessor, *til.Context, []common.BlockData) {
func initTestMultipleCoordIdxForTokenID(t *testing.T) (*TxProcessor, *til.Context,
[]common.BlockData) {
dir, err := ioutil.TempDir("", "tmpdb")
require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(dir))
@@ -1049,13 +1076,17 @@ func TestExitOf0Amount(t *testing.T) {
// process Batch4:
ptOut, err := tp.ProcessTxs(nil, blocks[0].Rollup.Batches[3].L1UserTxs, nil, nil)
require.NoError(t, err)
assert.Equal(t, "14329759303391468223438874789317921522067594445474390443816827472846339238908", ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
assert.Equal(t,
"14329759303391468223438874789317921522067594445474390443816827472846339238908",
ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
exitRootBatch4 := ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String()
// process Batch6:
ptOut, err = tp.ProcessTxs(nil, blocks[0].Rollup.Batches[5].L1UserTxs, nil, nil)
require.NoError(t, err)
assert.Equal(t, "14329759303391468223438874789317921522067594445474390443816827472846339238908", ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
assert.Equal(t,
"14329759303391468223438874789317921522067594445474390443816827472846339238908",
ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
// Expect that the ExitRoot for the Batch6 will be equal than for the
// Batch4, as the Batch4 & Batch6 have the same tx with Exit Amount=10,
// and Batch4 has a 2nd tx with Exit Amount=0.

View File

@@ -23,7 +23,7 @@ func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
b := pkComp[:]
for i := 0; i < 256; i++ {
if b[i/8]&(1<<(i%8)) == 0 {
if b[i/8]&(1<<(i%8)) == 0 { //nolint:gomnd
r[i] = big.NewInt(0)
} else {
r[i] = big.NewInt(1)
@@ -36,8 +36,8 @@ func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
// formatAccumulatedFees returns an array of [nFeeAccounts]*big.Int containing
// the balance of each FeeAccount, taken from the 'collectedFees' map, in the
// order of the 'orderTokenIDs'
// func formatAccumulatedFees(collectedFees map[common.TokenID]*big.Int, orderTokenIDs []*big.Int) []*big.Int {
func formatAccumulatedFees(collectedFees map[common.TokenID]*big.Int, orderTokenIDs []*big.Int, coordIdxs []common.Idx) []*big.Int {
func formatAccumulatedFees(collectedFees map[common.TokenID]*big.Int, orderTokenIDs []*big.Int,
coordIdxs []common.Idx) []*big.Int {
accFeeOut := make([]*big.Int, len(orderTokenIDs))
for i := 0; i < len(accFeeOut); i++ {
accFeeOut[i] = big.NewInt(0)

File diff suppressed because one or more lines are too long