various linter fixes (#6106)
x/staking: Fix all linter warnings. Fixed warnings across base packages. New linters: - unparam - nolintlint Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
+4
-8
@@ -159,7 +159,6 @@ func NewDecFromStr(str string) (Dec, error) {
|
||||
return Dec{}, ErrInvalidDecimalLength
|
||||
}
|
||||
combinedStr += strs[1]
|
||||
|
||||
} else if len(strs) > 2 {
|
||||
return Dec{}, ErrInvalidDecimalStr
|
||||
}
|
||||
@@ -277,7 +276,6 @@ func (d Dec) MulInt64(i int64) Dec {
|
||||
|
||||
// quotient
|
||||
func (d Dec) Quo(d2 Dec) Dec {
|
||||
|
||||
// multiply precision twice
|
||||
mul := new(big.Int).Mul(d.i, precisionReuse)
|
||||
mul.Mul(mul, precisionReuse)
|
||||
@@ -293,7 +291,6 @@ func (d Dec) Quo(d2 Dec) Dec {
|
||||
|
||||
// quotient truncate
|
||||
func (d Dec) QuoTruncate(d2 Dec) Dec {
|
||||
|
||||
// multiply precision twice
|
||||
mul := new(big.Int).Mul(d.i, precisionReuse)
|
||||
mul.Mul(mul, precisionReuse)
|
||||
@@ -386,6 +383,7 @@ func (d Dec) Power(power uint64) Dec {
|
||||
return OneDec()
|
||||
}
|
||||
tmp := OneDec()
|
||||
|
||||
for i := power; i > 1; {
|
||||
if i%2 == 0 {
|
||||
i /= 2
|
||||
@@ -395,6 +393,7 @@ func (d Dec) Power(power uint64) Dec {
|
||||
}
|
||||
d = d.Mul(d)
|
||||
}
|
||||
|
||||
return d.Mul(tmp)
|
||||
}
|
||||
|
||||
@@ -423,7 +422,8 @@ func (d Dec) String() string {
|
||||
}
|
||||
|
||||
isNeg := d.IsNegative()
|
||||
if d.IsNegative() {
|
||||
|
||||
if isNeg {
|
||||
d = d.Neg()
|
||||
}
|
||||
|
||||
@@ -451,9 +451,7 @@ func (d Dec) String() string {
|
||||
|
||||
// set final digits
|
||||
copy(bzStr[2+(Precision-inputSize):], bzInt)
|
||||
|
||||
} else {
|
||||
|
||||
// inputSize + 1 to account for the decimal point that is being added
|
||||
bzStr = make([]byte, inputSize+1)
|
||||
decPointPlace := inputSize - Precision
|
||||
@@ -484,7 +482,6 @@ func (d Dec) String() string {
|
||||
//
|
||||
// Mutates the input. Use the non-mutative version if that is undesired
|
||||
func chopPrecisionAndRound(d *big.Int) *big.Int {
|
||||
|
||||
// remove the negative and add it back when returning
|
||||
if d.Sign() == -1 {
|
||||
// make d positive, compute chopped value, and then un-mutate d
|
||||
@@ -517,7 +514,6 @@ func chopPrecisionAndRound(d *big.Int) *big.Int {
|
||||
}
|
||||
|
||||
func chopPrecisionAndRoundUp(d *big.Int) *big.Int {
|
||||
|
||||
// remove the negative and add it back when returning
|
||||
if d.Sign() == -1 {
|
||||
// make d positive, compute chopped value, and then un-mutate d
|
||||
|
||||
@@ -33,6 +33,7 @@ func RandomAcc(r *rand.Rand, accs []Account) (Account, int) {
|
||||
// RandomAccounts generates n random accounts
|
||||
func RandomAccounts(r *rand.Rand, n int) []Account {
|
||||
accs := make([]Account, n)
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
// don't need that much entropy for simulation
|
||||
privkeySeed := make([]byte, 15)
|
||||
@@ -81,5 +82,6 @@ func RandomFees(r *rand.Rand, ctx sdk.Context, spendableCoins sdk.Coins) (sdk.Co
|
||||
// Create a random fee and verify the fees are within the account's spendable
|
||||
// balance.
|
||||
fees := sdk.NewCoins(sdk.NewCoin(randCoin.Denom, amt))
|
||||
|
||||
return fees, nil
|
||||
}
|
||||
|
||||
@@ -27,13 +27,16 @@ func RandStringOfLength(r *rand.Rand, n int) string {
|
||||
if remain == 0 {
|
||||
cache, remain = r.Int63(), letterIdxMax
|
||||
}
|
||||
|
||||
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
|
||||
b[i] = letterBytes[idx]
|
||||
i--
|
||||
}
|
||||
|
||||
cache >>= letterIdxBits
|
||||
remain--
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -42,7 +45,9 @@ func RandPositiveInt(r *rand.Rand, max sdk.Int) (sdk.Int, error) {
|
||||
if !max.GTE(sdk.OneInt()) {
|
||||
return sdk.Int{}, errors.New("max too small")
|
||||
}
|
||||
|
||||
max = max.Sub(sdk.OneInt())
|
||||
|
||||
return sdk.NewIntFromBigInt(new(big.Int).Rand(r, max.BigInt())).Add(sdk.OneInt()), nil
|
||||
}
|
||||
|
||||
@@ -50,6 +55,7 @@ func RandPositiveInt(r *rand.Rand, max sdk.Int) (sdk.Int, error) {
|
||||
// Note: The range of RandomAmount includes max, and is, in fact, biased to return max as well as 0.
|
||||
func RandomAmount(r *rand.Rand, max sdk.Int) sdk.Int {
|
||||
var randInt = big.NewInt(0)
|
||||
|
||||
switch r.Intn(10) {
|
||||
case 0:
|
||||
// randInt = big.NewInt(0)
|
||||
@@ -58,6 +64,7 @@ func RandomAmount(r *rand.Rand, max sdk.Int) sdk.Int {
|
||||
default: // NOTE: there are 10 total cases.
|
||||
randInt = big.NewInt(0).Rand(r, max.BigInt()) // up to max - 1
|
||||
}
|
||||
|
||||
return sdk.NewIntFromBigInt(randInt)
|
||||
}
|
||||
|
||||
@@ -65,6 +72,7 @@ func RandomAmount(r *rand.Rand, max sdk.Int) sdk.Int {
|
||||
// Note: The range of RandomDecAmount includes max, and is, in fact, biased to return max as well as 0.
|
||||
func RandomDecAmount(r *rand.Rand, max sdk.Dec) sdk.Dec {
|
||||
var randInt = big.NewInt(0)
|
||||
|
||||
switch r.Intn(10) {
|
||||
case 0:
|
||||
// randInt = big.NewInt(0)
|
||||
@@ -73,6 +81,7 @@ func RandomDecAmount(r *rand.Rand, max sdk.Dec) sdk.Dec {
|
||||
default: // NOTE: there are 10 total cases.
|
||||
randInt = big.NewInt(0).Rand(r, max.BigInt())
|
||||
}
|
||||
|
||||
return sdk.NewDecFromBigIntWithPrec(randInt, sdk.Precision)
|
||||
}
|
||||
|
||||
@@ -103,7 +112,9 @@ func RandSubsetCoins(r *rand.Rand, coins sdk.Coins) sdk.Coins {
|
||||
if err != nil {
|
||||
return sdk.Coins{}
|
||||
}
|
||||
|
||||
subset := sdk.Coins{sdk.NewCoin(coin.Denom, amt)}
|
||||
|
||||
for i, c := range coins {
|
||||
// skip denom that we already chose earlier
|
||||
if i == denomIdx {
|
||||
@@ -120,8 +131,10 @@ func RandSubsetCoins(r *rand.Rand, coins sdk.Coins) sdk.Coins {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
subset = append(subset, sdk.NewCoin(c.Denom, amt))
|
||||
}
|
||||
|
||||
return subset.Sort()
|
||||
}
|
||||
|
||||
@@ -133,9 +146,11 @@ func RandSubsetCoins(r *rand.Rand, coins sdk.Coins) sdk.Coins {
|
||||
func DeriveRand(r *rand.Rand) *rand.Rand {
|
||||
const num = 8 // TODO what's a good number? Too large is too slow.
|
||||
ms := multiSource(make([]rand.Source, num))
|
||||
|
||||
for i := 0; i < num; i++ {
|
||||
ms[i] = rand.NewSource(r.Int63())
|
||||
}
|
||||
|
||||
return rand.New(ms)
|
||||
}
|
||||
|
||||
@@ -145,6 +160,7 @@ func (ms multiSource) Int63() (r int64) {
|
||||
for _, source := range ms {
|
||||
r ^= source.Int63()
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ func (om OperationMsg) String() string {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return string(out)
|
||||
}
|
||||
|
||||
@@ -99,6 +100,7 @@ func (om OperationMsg) MustMarshal() json.RawMessage {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -108,6 +110,7 @@ func (om OperationMsg) LogEvent(eventLogger func(route, op, evResult string)) {
|
||||
if !om.OK {
|
||||
pass = "failure"
|
||||
}
|
||||
|
||||
eventLogger(om.Route, om.Name, pass)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user