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:
arnaucube
2020-08-27 18:10:05 +02:00
parent fe8431edfa
commit fd1e9c25ee
27 changed files with 95 additions and 75 deletions

View File

@@ -12,7 +12,13 @@ import (
cryptoUtils "github.com/iden3/go-iden3-crypto/utils"
)
const NLEAFELEMS = 4
const (
NLEAFELEMS = 4
// maxNonceValue is the maximum value that the Account.Nonce can have (40 bits: maxNonceValue=2**40-1)
maxNonceValue = 0xffffffffff
// maxBalanceBytes is the maximum bytes that can use the Account.Balance *big.Int
maxBalanceBytes = 24
)
// Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
type Account struct {
@@ -37,10 +43,10 @@ func (a *Account) String() string {
func (a *Account) Bytes() ([32 * NLEAFELEMS]byte, error) {
var b [32 * NLEAFELEMS]byte
if a.Nonce > 0xffffffffff {
if a.Nonce > maxNonceValue {
return b, fmt.Errorf("%s Nonce", ErrNumOverflow)
}
if len(a.Balance.Bytes()) > 24 {
if len(a.Balance.Bytes()) > maxBalanceBytes {
return b, fmt.Errorf("%s Balance", ErrNumOverflow)
}