Merge PR #5203: Add more linters
This commit is contained in:
parent
97eac176a5
commit
b9490f2d93
|
@ -17,15 +17,19 @@ linters:
|
|||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- maligned
|
||||
- misspell
|
||||
- nakedret
|
||||
- prealloc
|
||||
- scopelint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
- misspell
|
||||
disable:
|
||||
- errcheck
|
||||
|
||||
|
|
|
@ -236,6 +236,7 @@ func TestSetLoader(t *testing.T) {
|
|||
v := []byte("value")
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// prepare a db with some data
|
||||
db := dbm.NewMemDB()
|
||||
|
@ -594,7 +595,7 @@ func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder {
|
|||
}
|
||||
}
|
||||
|
||||
func anteHandlerTxTest(t *testing.T, capKey *sdk.KVStoreKey, storeKey []byte) sdk.AnteHandler {
|
||||
func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler {
|
||||
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
|
||||
store := ctx.KVStore(capKey)
|
||||
txTest := tx.(txTest)
|
||||
|
@ -611,7 +612,7 @@ func anteHandlerTxTest(t *testing.T, capKey *sdk.KVStoreKey, storeKey []byte) sd
|
|||
}
|
||||
}
|
||||
|
||||
func handlerMsgCounter(t *testing.T, capKey *sdk.KVStoreKey, deliverKey []byte) sdk.Handler {
|
||||
func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
||||
store := ctx.KVStore(capKey)
|
||||
var msgCount int64
|
||||
|
|
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -149,7 +150,7 @@ func loadConfigFile(cfgFile string) (*toml.Tree, error) {
|
|||
return tree, nil
|
||||
}
|
||||
|
||||
func saveConfigFile(cfgFile string, tree *toml.Tree) error {
|
||||
func saveConfigFile(cfgFile string, tree io.WriterTo) error {
|
||||
fp, err := os.OpenFile(cfgFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -23,6 +23,7 @@ func TestCreateVerifier(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
verifier, err := context.CreateVerifier(tc.ctx, context.DefaultVerifierCacheSize)
|
||||
require.Equal(t, tc.expectErr, err != nil, err)
|
||||
|
|
|
@ -56,6 +56,7 @@ func TestMarshalJSON(t *testing.T) {
|
|||
{"empty object", args{data.Keys[3]}, data.JSON[3], false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := MarshalJSON(tt.args.o)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
@ -91,6 +92,7 @@ func TestUnmarshalJSON(t *testing.T) {
|
|||
{"empty object", args{data.JSON[3], &data.Answers[3]}, false},
|
||||
}
|
||||
for idx, tt := range tests {
|
||||
idx, tt := idx, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := UnmarshalJSON(tt.args.bz, tt.args.ptr); (err != nil) != tt.wantErr {
|
||||
t.Errorf("unmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
@ -91,6 +91,7 @@ func Test_confirmDeletion(t *testing.T) {
|
|||
{"BAD", args{answerInvalid}, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := confirmDeletion(tt.args.buf); (err != nil) != tt.wantErr {
|
||||
t.Errorf("confirmDeletion() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
@ -44,6 +44,7 @@ func Test_runListCmd(t *testing.T) {
|
|||
{"keybase: w/key", kbHome2, args{cmdBasic, []string{}}, false},
|
||||
}
|
||||
for _, tt := range testData {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, tt.kbDir)
|
||||
if err := runListCmd(tt.args.cmd, tt.args.args); (err != nil) != tt.wantErr {
|
||||
|
|
|
@ -21,6 +21,7 @@ func TestParseKey(t *testing.T) {
|
|||
{"hex", []string{hexstr}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.Equal(t, tt.wantErr, parseKey(nil, tt.args) != nil)
|
||||
})
|
||||
|
|
|
@ -113,6 +113,7 @@ func Test_validateMultisigThreshold(t *testing.T) {
|
|||
{"1-2", args{2, 1}, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := validateMultisigThreshold(tt.args.k, tt.args.nKeys); (err != nil) != tt.wantErr {
|
||||
t.Errorf("validateMultisigThreshold() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
@ -138,6 +139,7 @@ func Test_getBechKeyOut(t *testing.T) {
|
|||
{"cons", args{sdk.PrefixConsensus}, keys.Bech32ConsKeyOutput, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getBechKeyOut(tt.args.bechPrefix)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
@ -52,6 +52,7 @@ func TestPaginate(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
i, tc := i, tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
start, end := client.Paginate(tc.numObjs, tc.page, tc.limit, tc.defLimit)
|
||||
require.Equal(t, tc.expectedStart, start, "invalid result; test case #%d", i)
|
||||
|
|
|
@ -167,7 +167,7 @@ func (kb baseKeybase) CreateMnemonic(
|
|||
// Derive computes a BIP39 seed from the mnemonic and bip39Passphrase. It creates
|
||||
// a private key from the seed using the BIP44 params.
|
||||
func (kb baseKeybase) Derive(
|
||||
keyWriter keyWriter, name, mnemonic, bip39Passphrase, encryptPasswd string, params hd.BIP44Params,
|
||||
keyWriter keyWriter, name, mnemonic, bip39Passphrase, encryptPasswd string, params hd.BIP44Params, // nolint:interfacer
|
||||
) (Info, error) {
|
||||
|
||||
seed, err := bip39.NewSeedWithErrorChecking(mnemonic, bip39Passphrase)
|
||||
|
|
|
@ -91,6 +91,7 @@ func TestSimGenesisAccountValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
require.Equal(t, tc.wantErr, tc.sga.Validate() != nil)
|
||||
})
|
||||
|
|
|
@ -113,6 +113,7 @@ func BenchmarkInvariants(b *testing.B) {
|
|||
// NOTE: We use the crisis keeper as it has all the invariants registered with
|
||||
// their respective metadata which makes it useful for testing/benchmarking.
|
||||
for _, cr := range app.CrisisKeeper.Routes() {
|
||||
cr := cr
|
||||
b.Run(fmt.Sprintf("%s/%s", cr.ModuleName, cr.Route), func(b *testing.B) {
|
||||
if res, stop := cr.Invar(ctx); stop {
|
||||
fmt.Printf("broken invariant at block %d of %d\n%s", ctx.BlockHeight()-1, config.NumBlocks, res)
|
||||
|
|
|
@ -3,6 +3,7 @@ package simapp
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
@ -121,7 +122,7 @@ func AppStateRandomizedFn(
|
|||
|
||||
// AppStateFromGenesisFileFn util function to generate the genesis AppState
|
||||
// from a genesis.json file.
|
||||
func AppStateFromGenesisFileFn(r *rand.Rand, cdc *codec.Codec, genesisFile string) (tmtypes.GenesisDoc, []simulation.Account) {
|
||||
func AppStateFromGenesisFileFn(r io.Reader, cdc *codec.Codec, genesisFile string) (tmtypes.GenesisDoc, []simulation.Account) {
|
||||
bytes, err := ioutil.ReadFile(genesisFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -44,6 +44,7 @@ func TestGetSimulationLog(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.store, func(t *testing.T) {
|
||||
require.Equal(t, tt.expectedLog, GetSimulationLog(tt.store, decoders, cdc, tt.kvPairs, tt.kvPairs), tt.store)
|
||||
})
|
||||
|
|
|
@ -90,6 +90,7 @@ func TestListRandom(t *testing.T) {
|
|||
}
|
||||
|
||||
for k, v := range mocklist {
|
||||
k := k
|
||||
var i uint32
|
||||
require.NotPanics(t, func() { list.Get(uint64(k), &i) })
|
||||
require.Equal(t, v, i)
|
||||
|
|
|
@ -25,6 +25,7 @@ func TestGasMeter(t *testing.T) {
|
|||
used := uint64(0)
|
||||
|
||||
for unum, usage := range tc.usage {
|
||||
usage := usage
|
||||
used += usage
|
||||
require.NotPanics(t, func() { meter.ConsumeGas(usage, "") }, "Not exceeded limit but panicked. tc #%d, usage #%d", tcnum, unum)
|
||||
require.Equal(t, used, meter.GasConsumed(), "Gas consumption not match. tc #%d, usage #%d", tcnum, unum)
|
||||
|
|
|
@ -44,6 +44,7 @@ func TestStoreUpgrades(t *testing.T) {
|
|||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for _, d := range tc.expectDelete {
|
||||
assert.Equal(t, tc.upgrades.IsDeleted(d.key), d.delete)
|
||||
|
|
|
@ -40,6 +40,7 @@ func TestIsEqualCoin(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
if tc.panics {
|
||||
require.Panics(t, func() { tc.inputOne.IsEqual(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -82,6 +83,7 @@ func TestAddCoin(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
if tc.shouldPanic {
|
||||
require.Panics(t, func() { tc.inputOne.Add(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -106,6 +108,7 @@ func TestSubCoin(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
if tc.shouldPanic {
|
||||
require.Panics(t, func() { tc.inputOne.Sub(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -136,6 +139,7 @@ func TestIsGTECoin(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
if tc.panics {
|
||||
require.Panics(t, func() { tc.inputOne.IsGTE(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -161,6 +165,7 @@ func TestIsLTCoin(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
if tc.panics {
|
||||
require.Panics(t, func() { tc.inputOne.IsLT(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -218,6 +223,7 @@ func TestEqualCoins(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcnum, tc := range cases {
|
||||
tc := tc
|
||||
if tc.panics {
|
||||
require.Panics(t, func() { tc.inputOne.IsEqual(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -270,6 +276,7 @@ func TestSubCoins(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
if tc.shouldPanic {
|
||||
require.Panics(t, func() { tc.inputOne.Sub(tc.inputTwo) })
|
||||
} else {
|
||||
|
@ -586,6 +593,7 @@ func TestNewCoins(t *testing.T) {
|
|||
{"panic on dups", []Coin{tenatom, tenatom}, Coins{}, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.wantPanic {
|
||||
require.Panics(t, func() { NewCoins(tt.coins...) })
|
||||
|
@ -636,6 +644,7 @@ func TestFindDup(t *testing.T) {
|
|||
{"dup after first position", args{Coins{abc, def, def}}, 2},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := findDup(tt.args.coins); got != tt.want {
|
||||
t.Errorf("findDup() = %v, want %v", got, tt.want)
|
||||
|
@ -659,6 +668,7 @@ func TestMarshalJSONCoins(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
bz, err := cdc.MarshalJSON(tc.input)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -194,6 +194,7 @@ func TestContextHeaderClone(t *testing.T) {
|
|||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := types.NewContext(nil, tc.h, false, nil)
|
||||
require.Equal(t, tc.h.Height, ctx.BlockHeight())
|
||||
|
|
|
@ -307,6 +307,7 @@ func TestDecCoinsQuoDecTruncate(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
if tc.panics {
|
||||
require.Panics(t, func() { tc.coins.QuoDecTruncate(tc.input) })
|
||||
} else {
|
||||
|
|
|
@ -189,6 +189,7 @@ func TestArithmetic(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range tests {
|
||||
tc := tc
|
||||
resAdd := tc.d1.Add(tc.d2)
|
||||
resSub := tc.d1.Sub(tc.d2)
|
||||
resMul := tc.d1.Mul(tc.d2)
|
||||
|
@ -291,6 +292,7 @@ func TestDecMarshalJSON(t *testing.T) {
|
|||
{"12340Int", NewDec(12340), "\"12340.000000000000000000\"", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := tt.d.MarshalJSON()
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
@ -89,6 +89,7 @@ func TestABCInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
for testName, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
space, code, log := ABCIInfo(tc.err, tc.debug)
|
||||
if space != tc.wantSpace {
|
||||
|
@ -140,6 +141,7 @@ func TestABCIInfoStacktrace(t *testing.T) {
|
|||
const thisTestSrc = "github.com/cosmos/cosmos-sdk/types/errors.TestABCIInfoStacktrace"
|
||||
|
||||
for testName, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
_, _, log := ABCIInfo(tc.err, tc.debug)
|
||||
if tc.wantStacktrace {
|
||||
|
@ -250,6 +252,7 @@ func TestABCIInfoSerializeErr(t *testing.T) {
|
|||
// },
|
||||
}
|
||||
for msg, spec := range specs {
|
||||
spec := spec
|
||||
t.Run(msg, func(t *testing.T) {
|
||||
_, _, log := ABCIInfo(spec.src, spec.debug)
|
||||
if exp, got := spec.exp, log; exp != got {
|
||||
|
|
|
@ -30,6 +30,7 @@ func TestCause(t *testing.T) {
|
|||
}
|
||||
|
||||
for testName, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
if got := errors.Cause(tc.err); got != tc.root {
|
||||
t.Fatal("unexpected result")
|
||||
|
@ -136,6 +137,7 @@ func TestErrorIs(t *testing.T) {
|
|||
// },
|
||||
}
|
||||
for testName, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
if got := tc.a.Is(tc.b); got != tc.wantIs {
|
||||
t.Fatalf("unexpected result - got:%v want: %v", got, tc.wantIs)
|
||||
|
|
|
@ -40,6 +40,7 @@ func TestStackTrace(t *testing.T) {
|
|||
const thisTestSrc = "types/errors/stacktrace_test.go"
|
||||
|
||||
for testName, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
if !reflect.DeepEqual(tc.err.Error(), tc.wantError) {
|
||||
t.Fatalf("errors not equal, got '%s', want '%s'", tc.err.Error(), tc.wantError)
|
||||
|
|
|
@ -129,6 +129,7 @@ func TestResultFromError(t *testing.T) {
|
|||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
res := ResultFromError(tc.err)
|
||||
require.Equal(t, tc.expect, res)
|
||||
|
|
|
@ -54,6 +54,7 @@ func TestBaseReqValidateBasic(t *testing.T) {
|
|||
{"fees and gasprices provided", req4, httptest.NewRecorder(), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.Equal(t, tt.want, tt.req.ValidateBasic(tt.w))
|
||||
})
|
||||
|
@ -90,6 +91,7 @@ func TestParseHTTPArgs(t *testing.T) {
|
|||
{"tags", req4, httptest.NewRecorder(), []string{"foo='faa'"}, DefaultPage, DefaultLimit, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tags, page, limit, err := ParseHTTPArgs(tt.req)
|
||||
if tt.err {
|
||||
|
@ -127,6 +129,7 @@ func TestParseQueryHeight(t *testing.T) {
|
|||
{"negative height", req3, httptest.NewRecorder(), context.CLIContext{}, emptyHeight, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cliCtx, ok := ParseQueryHeightOrReturnBadRequest(tt.w, tt.cliCtx, tt.req)
|
||||
if tt.expectedOk {
|
||||
|
|
|
@ -208,6 +208,7 @@ func TestSafeSub(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
if tc.panic {
|
||||
require.Panics(t, func() { tc.x.Sub(tc.y) })
|
||||
continue
|
||||
|
@ -236,6 +237,7 @@ func TestParseUint(t *testing.T) {
|
|||
{"zero", args{"0"}, ZeroUint(), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ParseUint(tt.args.s)
|
||||
if tt.wantErr {
|
||||
|
|
|
@ -31,6 +31,7 @@ func TestSortJSON(t *testing.T) {
|
|||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
tc := tc
|
||||
got, err := SortJSON([]byte(tc.unsortedJSON))
|
||||
if tc.wantErr {
|
||||
require.NotNil(t, err, "tc #%d", tcIndex)
|
||||
|
@ -55,6 +56,7 @@ func TestTimeFormatAndParse(t *testing.T) {
|
|||
{"2011-01-10T23:10:05.758230235Z", "2011-01-10T23:10:05.758230235", true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
timeFromRFC, err := time.Parse(time.RFC3339Nano, tc.RFC3339NanoStr)
|
||||
require.Nil(t, err)
|
||||
timeFromSDKFormat, err := time.Parse(SortableTimeFormat, tc.SDKSortableTimeStr)
|
||||
|
|
|
@ -643,6 +643,7 @@ func TestCountSubkeys(t *testing.T) {
|
|||
{"multi level multikey", args{multiLevelMultiKey}, 11},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(T *testing.T) {
|
||||
require.Equal(t, tt.want, types.CountSubKeys(tt.args.pub))
|
||||
})
|
||||
|
|
|
@ -85,6 +85,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) {
|
|||
{"unknown key", args{sdk.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := ante.DefaultSigVerificationGasConsumer(tt.args.meter, tt.args.sig, tt.args.pubkey, tt.args.params)
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ func TestCalculateGas(t *testing.T) {
|
|||
{"adjusted gas", args{10, false, 1.2}, 10, 12, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
queryFunc := makeQueryFunc(tt.args.queryFuncGasUsed, tt.args.queryFuncWantErr)
|
||||
gotEstimate, gotAdjusted, err := CalculateGas(queryFunc, cdc, []byte(""), tt.args.adjustment)
|
||||
|
|
|
@ -43,7 +43,7 @@ type GenesisAccounts []GenesisAccount
|
|||
|
||||
// Contains returns true if the given address exists in a slice of GenesisAccount
|
||||
// objects.
|
||||
func (ga GenesisAccounts) Contains(addr sdk.AccAddress) bool {
|
||||
func (ga GenesisAccounts) Contains(addr sdk.Address) bool {
|
||||
for _, acc := range ga {
|
||||
if acc.GetAddress().Equals(addr) {
|
||||
return true
|
||||
|
|
|
@ -162,6 +162,7 @@ func TestMigrateInvalid(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
Migrate(
|
||||
|
|
|
@ -47,6 +47,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -121,6 +121,7 @@ func TestGenesisAccountValidate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.acc.Validate()
|
||||
require.Equal(t, tt.expErr, err)
|
||||
|
|
|
@ -131,6 +131,7 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bldr := NewTxBuilder(
|
||||
tt.fields.TxEncoder, tt.fields.AccountNumber, tt.fields.Sequence,
|
||||
|
|
|
@ -725,6 +725,7 @@ func TestGenesisAccountValidate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.acc.Validate()
|
||||
require.Equal(t, tt.expErr, err)
|
||||
|
|
|
@ -63,6 +63,7 @@ func TestHandleMsgVerifyInvariant(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
h := crisis.NewHandler(app.CrisisKeeper)
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) {
|
|||
{"empty validator address", args{"cosmos1zxcsu7l5qxs53lvp0fqgd09a9r2g6kqrk2cdpa", ""}, nil, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := QueryDelegationRewards(ctx, "", tt.args.delAddr, tt.args.valAddr)
|
||||
require.True(t, err != nil, tt.wantErr)
|
||||
|
|
|
@ -72,6 +72,7 @@ func TestDecodeDistributionStore(t *testing.T) {
|
|||
{"other", ""},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -76,6 +76,7 @@ func TestMigrateEmptyRecord(t *testing.T) {
|
|||
{"Burned and deposited accounts", args{v034accounts.GenesisState{accountDeposited, accountBurned}, []v034gov.DepositWithMetadata{deposit}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
Migrate(
|
||||
|
|
|
@ -39,7 +39,7 @@ func SetGenTxsInAppGenesisState(cdc *codec.Codec, appGenesisState map[string]jso
|
|||
// coins in the genesis accounts
|
||||
func ValidateAccountInGenesis(appGenesisState map[string]json.RawMessage,
|
||||
genAccIterator types.GenesisAccountsIterator,
|
||||
key sdk.AccAddress, coins sdk.Coins, cdc *codec.Codec) error {
|
||||
key sdk.Address, coins sdk.Coins, cdc *codec.Codec) error {
|
||||
|
||||
accountIsInGenesis := false
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A
|
|||
}
|
||||
|
||||
if !types.ValidVoteOption(option) {
|
||||
return types.ErrInvalidVote(keeper.codespace, option)
|
||||
return types.ErrInvalidVote(keeper.codespace, option.String())
|
||||
}
|
||||
|
||||
vote := types.NewVote(proposalID, voterAddr, option)
|
||||
|
|
|
@ -61,6 +61,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -51,8 +51,8 @@ func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType string) sd
|
|||
}
|
||||
|
||||
// ErrInvalidVote error for an invalid vote option
|
||||
func ErrInvalidVote(codespace sdk.CodespaceType, voteOption VoteOption) sdk.Error {
|
||||
return sdk.NewError(codespace, CodeInvalidVote, fmt.Sprintf("'%v' is not a valid voting option", voteOption.String()))
|
||||
func ErrInvalidVote(codespace sdk.CodespaceType, voteOption string) sdk.Error {
|
||||
return sdk.NewError(codespace, CodeInvalidVote, fmt.Sprintf("'%v' is not a valid voting option", voteOption))
|
||||
}
|
||||
|
||||
// ErrInvalidGenesis error for an invalid governance GenesisState
|
||||
|
|
|
@ -157,7 +157,7 @@ func (msg MsgVote) ValidateBasic() sdk.Error {
|
|||
return sdk.ErrInvalidAddress(msg.Voter.String())
|
||||
}
|
||||
if !ValidVoteOption(msg.Option) {
|
||||
return ErrInvalidVote(DefaultCodespace, msg.Option)
|
||||
return ErrInvalidVote(DefaultCodespace, msg.Option.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -36,6 +36,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -21,7 +21,7 @@ type Keeper struct {
|
|||
}
|
||||
|
||||
// NewKeeper constructs a params keeper
|
||||
func NewKeeper(cdc *codec.Codec, key *sdk.KVStoreKey, tkey *sdk.TransientStoreKey, codespace sdk.CodespaceType) (k Keeper) {
|
||||
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, codespace sdk.CodespaceType) (k Keeper) {
|
||||
k = Keeper{
|
||||
cdc: cdc,
|
||||
key: key,
|
||||
|
|
|
@ -43,11 +43,13 @@ func TestKeeper(t *testing.T) {
|
|||
|
||||
// Set params
|
||||
for i, kv := range kvs {
|
||||
kv := kv
|
||||
require.NotPanics(t, func() { space.Set(ctx, []byte(kv.key), kv.param) }, "space.Set panics, tc #%d", i)
|
||||
}
|
||||
|
||||
// Test space.Get
|
||||
for i, kv := range kvs {
|
||||
i, kv := i, kv
|
||||
var param int64
|
||||
require.NotPanics(t, func() { space.Get(ctx, []byte(kv.key), ¶m) }, "space.Get panics, tc #%d", i)
|
||||
require.Equal(t, kv.param, param, "stored param not equal, tc #%d", i)
|
||||
|
@ -74,17 +76,20 @@ func TestKeeper(t *testing.T) {
|
|||
|
||||
// Test invalid space.Get
|
||||
for i, kv := range kvs {
|
||||
kv := kv
|
||||
var param bool
|
||||
require.Panics(t, func() { space.Get(ctx, []byte(kv.key), ¶m) }, "invalid space.Get not panics, tc #%d", i)
|
||||
}
|
||||
|
||||
// Test invalid space.Set
|
||||
for i, kv := range kvs {
|
||||
kv := kv
|
||||
require.Panics(t, func() { space.Set(ctx, []byte(kv.key), true) }, "invalid space.Set not panics, tc #%d", i)
|
||||
}
|
||||
|
||||
// Test GetSubspace
|
||||
for i, kv := range kvs {
|
||||
i, kv := i, kv
|
||||
var gparam, param int64
|
||||
gspace, ok := keeper.GetSubspace("test")
|
||||
require.True(t, ok, "cannot retrieve subspace, tc #%d", i)
|
||||
|
@ -146,6 +151,7 @@ func TestSubspace(t *testing.T) {
|
|||
|
||||
// Test space.Set, space.Modified
|
||||
for i, kv := range kvs {
|
||||
i, kv := i, kv
|
||||
require.False(t, space.Modified(ctx, []byte(kv.key)), "space.Modified returns true before setting, tc #%d", i)
|
||||
require.NotPanics(t, func() { space.Set(ctx, []byte(kv.key), kv.param) }, "space.Set panics, tc #%d", i)
|
||||
require.True(t, space.Modified(ctx, []byte(kv.key)), "space.Modified returns false after setting, tc #%d", i)
|
||||
|
@ -153,6 +159,7 @@ func TestSubspace(t *testing.T) {
|
|||
|
||||
// Test space.Get, space.GetIfExists
|
||||
for i, kv := range kvs {
|
||||
i, kv := i, kv
|
||||
require.NotPanics(t, func() { space.GetIfExists(ctx, []byte("invalid"), kv.ptr) }, "space.GetIfExists panics when no value exists, tc #%d", i)
|
||||
require.Equal(t, kv.zero, indirect(kv.ptr), "space.GetIfExists unmarshalls when no value exists, tc #%d", i)
|
||||
require.Panics(t, func() { space.Get(ctx, []byte("invalid"), kv.ptr) }, "invalid space.Get not panics when no value exists, tc #%d", i)
|
||||
|
|
|
@ -154,6 +154,7 @@ func queueOperations(queuedOps OperationQueue,
|
|||
}
|
||||
|
||||
for _, futureOp := range futureOps {
|
||||
futureOp := futureOp
|
||||
if futureOp.BlockHeight != 0 {
|
||||
if val, ok := queuedOps[futureOp.BlockHeight]; ok {
|
||||
queuedOps[futureOp.BlockHeight] = append(val, futureOp.Op)
|
||||
|
|
|
@ -55,6 +55,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
{"other", ""},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -66,6 +66,7 @@ func TestPrepareFlagsForTxCreateValidator(t *testing.T) {
|
|||
defaultMinSelfDelegation,
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) { runTest(t, tt, defaultParams) })
|
||||
})
|
||||
|
@ -79,6 +80,7 @@ func TestPrepareFlagsForTxCreateValidator(t *testing.T) {
|
|||
viper.Set(FlagCommissionMaxChangeRate, params.commissionMaxChangeRate)
|
||||
viper.Set(FlagMinSelfDelegation, params.minSelfDelegation)
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) { runTest(t, tt, params) })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
genesisState := types.DefaultGenesisState()
|
||||
tt.mutate(&genesisState)
|
||||
|
|
|
@ -49,7 +49,7 @@ func (k Keeper) GetAllDelegations(ctx sdk.Context) (delegations []types.Delegati
|
|||
}
|
||||
|
||||
// return all delegations to a specific validator. Useful for querier.
|
||||
func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation) {
|
||||
func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation) { //nolint:interfacer
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey)
|
||||
defer iterator.Close()
|
||||
|
|
|
@ -62,6 +62,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
{"other", ""},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
|
@ -56,6 +56,6 @@ func (k Keeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.Mo
|
|||
}
|
||||
|
||||
// SetModuleAccount sets the module account to the auth account store
|
||||
func (k Keeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) {
|
||||
func (k Keeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) { //nolint:interfacer
|
||||
k.ak.SetAccount(ctx, macc)
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ func TestValidate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.acc.Validate()
|
||||
require.Equal(t, tt.expErr, err)
|
||||
|
|
|
@ -42,6 +42,7 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
i, tc := i, tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := validatePermissions(tc.permissions...)
|
||||
if tc.expectPass {
|
||||
|
|
|
@ -40,6 +40,7 @@ func TestDecodeStore(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
i, tt := i, tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
switch i {
|
||||
case len(tests) - 1:
|
||||
|
|
Loading…
Reference in New Issue