mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add linter checks to GHA & Fix code to pass lints
Add linter checks to GHA & Fix code to pass lints. The linters added are: - whitespace: Tool for detection of leading and trailing whitespace - gosec: Inspects source code for security problems - gci: Gci control golang package import order and make it always deterministic - misspell: Finds commonly misspelled English words in comments - gomnd: An analyzer to detect magic numbers The file utils/utils.go is excluded from the checks of gomnd, as uses magic numbers through the code
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq" // driver for postgres DB
|
||||
|
||||
//nolint:errcheck // driver for postgres DB
|
||||
_ "github.com/lib/pq"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestBlocks(t *testing.T) {
|
||||
// Generate fake blocks
|
||||
blocks := genBlocks(fromBlock, toBlock)
|
||||
// Insert blocks into DB
|
||||
for _, block := range blocks {
|
||||
err := historyDB.AddBlock(&block)
|
||||
for i := 0; i < len(blocks); i++ {
|
||||
err := historyDB.AddBlock(&blocks[i])
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
// Get all blocks from DB
|
||||
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq" // driver for postgres DB
|
||||
|
||||
//nolint:errcheck // driver for postgres DB
|
||||
_ "github.com/lib/pq"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
@@ -26,7 +28,7 @@ type L2DB struct {
|
||||
|
||||
// NewL2DB creates a L2DB.
|
||||
// More info on how to set dbDialect and dbArgs here: http://gorm.io/docs/connecting_to_the_database.html
|
||||
// safetyPeriod is the ammount of blockchain blocks that must be waited before deleting anything (to avoid reorg problems).
|
||||
// safetyPeriod is the amount of blockchain blocks that must be waited before deleting anything (to avoid reorg problems).
|
||||
// maxTxs indicates the desired maximum amount of txs stored on the L2DB.
|
||||
// TTL indicates the maximum amount of time that a tx can be in the L2DB
|
||||
// (to prevent tx that won't ever be forged to stay there, will be used if maxTxs is exceeded).
|
||||
@@ -153,7 +155,7 @@ func (l2db *L2DB) UpdateTxs(txs []*common.PoolL2Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reorg updates the state of txs that were updated in a batch that has been discarted due to a blockchian reorg.
|
||||
// Reorg updates the state of txs that were updated in a batch that has been discarted due to a blockchain reorg.
|
||||
// The state of the affected txs can change form Forged -> Pending or from Invalid -> Pending
|
||||
func (l2db *L2DB) Reorg(lastValidBatch common.BatchNum) error {
|
||||
// TODO: impl
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestStartForging(t *testing.T) {
|
||||
|
||||
func genTxs(n int) []*common.PoolL2Tx {
|
||||
// WARNING: This tx doesn't follow the protocol (signature, txID, ...)
|
||||
// it's just to test geting/seting from/to the DB.
|
||||
// it's just to test getting/setting from/to the DB.
|
||||
// Type and RqTxCompressedData: not initialized because it's not stored
|
||||
// on the DB and add noise when checking results.
|
||||
txs := make([]*common.PoolL2Tx, 0, n)
|
||||
|
||||
@@ -32,7 +32,6 @@ func newAccount(t *testing.T, i int) *common.Account {
|
||||
PublicKey: pk,
|
||||
EthAddr: address,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStateDBWithoutMT(t *testing.T) {
|
||||
|
||||
@@ -213,7 +213,7 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// substract amount to the sender
|
||||
// subtract amount to the sender
|
||||
accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount)
|
||||
// add amount to the receiver
|
||||
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
||||
@@ -247,7 +247,7 @@ func (s *StateDB) applyTransfer(tx *common.Tx) error {
|
||||
// increment nonce
|
||||
accSender.Nonce++
|
||||
|
||||
// substract amount to the sender
|
||||
// subtract amount to the sender
|
||||
accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount)
|
||||
// add amount to the receiver
|
||||
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
|
||||
@@ -267,7 +267,7 @@ func (s *StateDB) applyTransfer(tx *common.Tx) error {
|
||||
}
|
||||
|
||||
func (s *StateDB) applyExit(exitTree *merkletree.MerkleTree, tx *common.Tx) (*common.Account, error) {
|
||||
// 0. substract tx.Amount from current Account in StateMT
|
||||
// 0. subtract tx.Amount from current Account in StateMT
|
||||
// add the tx.Amount into the Account (tx.FromIdx) in the ExitMT
|
||||
acc, err := s.GetAccount(tx.FromIdx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user