style: use thelper (#16777)
This commit is contained in:
parent
e4e7922cea
commit
f0aec3f30d
@ -27,6 +27,7 @@ linters:
|
||||
- revive
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- thelper
|
||||
- unconvert
|
||||
- unused
|
||||
|
||||
@ -59,6 +60,9 @@ issues:
|
||||
- text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk
|
||||
linters:
|
||||
- staticcheck
|
||||
- text: 'SA1019: params.SendEnabled is deprecated' # TODO remove once ready to remove from the sdk
|
||||
linters:
|
||||
- staticcheck
|
||||
- text: 'leading space'
|
||||
linters:
|
||||
- nolintlint
|
||||
|
||||
@ -59,6 +59,7 @@ type (
|
||||
)
|
||||
|
||||
func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite {
|
||||
t.Helper()
|
||||
cdc := codectestutil.CodecOptions{}.NewCodec()
|
||||
baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry())
|
||||
|
||||
@ -86,6 +87,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
|
||||
}
|
||||
|
||||
func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...func(*baseapp.BaseApp)) *BaseAppSuite {
|
||||
t.Helper()
|
||||
snapshotTimeout := 1 * time.Minute
|
||||
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t))
|
||||
require.NoError(t, err)
|
||||
@ -232,6 +234,7 @@ func TestSetLoader(t *testing.T) {
|
||||
}
|
||||
|
||||
initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
|
||||
t.Helper()
|
||||
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
|
||||
|
||||
@ -252,6 +255,7 @@ func TestSetLoader(t *testing.T) {
|
||||
}
|
||||
|
||||
checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
|
||||
t.Helper()
|
||||
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))
|
||||
|
||||
|
||||
@ -118,6 +118,7 @@ func TestQueryDataRaces_uniqueConnectionsToSameHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func testQueryDataRacesSameHandler(t *testing.T, makeClientConn func(*baseapp.GRPCQueryRouter) *baseapp.QueryServiceTestHelper) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
qr := baseapp.NewGRPCQueryRouter()
|
||||
|
||||
@ -160,6 +160,7 @@ func incrementCounter(ctx context.Context,
|
||||
deliverKey []byte,
|
||||
msg sdk.Msg,
|
||||
) (*baseapptestutil.MsgCreateCounterResponse, error) {
|
||||
t.Helper()
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
store := sdkCtx.KVStore(capKey)
|
||||
|
||||
@ -202,6 +203,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
|
||||
}
|
||||
|
||||
func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) sdk.AnteHandler {
|
||||
t.Helper()
|
||||
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
|
||||
store := ctx.KVStore(capKey)
|
||||
counter, failOnAnte := parseTxMemo(t, tx)
|
||||
@ -225,6 +227,7 @@ func anteHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte
|
||||
}
|
||||
|
||||
func incrementingCounter(t *testing.T, store storetypes.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) {
|
||||
t.Helper()
|
||||
storedCounter := getIntFromStore(t, store, counterKey)
|
||||
require.Equal(t, storedCounter, counter)
|
||||
setIntOnStore(store, counterKey, counter+1)
|
||||
@ -275,6 +278,7 @@ func (ps paramStore) Get(_ context.Context) (cmtproto.ConsensusParams, error) {
|
||||
}
|
||||
|
||||
func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) {
|
||||
t.Helper()
|
||||
privKey := secp256k1.GenPrivKeyFromSecret([]byte("test"))
|
||||
pubKey := privKey.PubKey()
|
||||
err := builder.SetSignatures(
|
||||
@ -288,6 +292,7 @@ func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) {
|
||||
}
|
||||
|
||||
func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) {
|
||||
t.Helper()
|
||||
lastHeight := app.LastBlockHeight()
|
||||
lastID := app.LastCommitID()
|
||||
require.Equal(t, expectedHeight, lastHeight)
|
||||
@ -309,6 +314,7 @@ func getFinalizeBlockStateCtx(app *baseapp.BaseApp) sdk.Context {
|
||||
}
|
||||
|
||||
func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) {
|
||||
t.Helper()
|
||||
txWithMemo, ok := tx.(sdk.TxWithMemo)
|
||||
require.True(t, ok)
|
||||
|
||||
@ -324,6 +330,7 @@ func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) {
|
||||
}
|
||||
|
||||
func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters ...int64) signing.Tx {
|
||||
t.Helper()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
msgs := make([]sdk.Msg, 0, len(msgCounters))
|
||||
for _, c := range msgCounters {
|
||||
@ -340,6 +347,7 @@ func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters
|
||||
}
|
||||
|
||||
func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 {
|
||||
t.Helper()
|
||||
bz := store.Get(key)
|
||||
if len(bz) == 0 {
|
||||
return 0
|
||||
@ -352,6 +360,7 @@ func getIntFromStore(t *testing.T, store storetypes.KVStore, key []byte) int64 {
|
||||
}
|
||||
|
||||
func setFailOnAnte(t *testing.T, cfg client.TxConfig, tx signing.Tx, failOnAnte bool) signing.Tx {
|
||||
t.Helper()
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMsgs(tx.GetMsgs()...)
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ const (
|
||||
|
||||
// initClientContext initiates client Context for tests
|
||||
func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
|
||||
t.Helper()
|
||||
home := t.TempDir()
|
||||
chainID := "test-chain"
|
||||
clientCtx := client.Context{}.
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
)
|
||||
|
||||
func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() {
|
||||
t.Helper()
|
||||
return func() {
|
||||
for _, k := range keys {
|
||||
if err := kb.Delete(k); err != nil {
|
||||
|
||||
@ -234,6 +234,7 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
|
||||
// checkCorrectData that the auxSignerData's content matches the inputs we gave.
|
||||
func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSignerData, signMode signing.SignMode) {
|
||||
t.Helper()
|
||||
pkAny, err := codectypes.NewAnyWithValue(pub1)
|
||||
require.NoError(t, err)
|
||||
msgAny, err := codectypes.NewAnyWithValue(msg1)
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
)
|
||||
|
||||
func testExecCommon(t *testing.T, buildModuleCommand func(string, *Builder) (*cobra.Command, error), args ...string) *testClientConn {
|
||||
t.Helper()
|
||||
server := grpc.NewServer()
|
||||
testpb.RegisterQueryServer(server, &testEchoServer{})
|
||||
reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{})
|
||||
@ -70,6 +71,7 @@ func testExecCommon(t *testing.T, buildModuleCommand func(string, *Builder) (*co
|
||||
}
|
||||
|
||||
func testExecCommonWithErr(t *testing.T, expectedErr string, buildModuleCommand func(string, *Builder) (*cobra.Command, error), args ...string) {
|
||||
t.Helper()
|
||||
server := grpc.NewServer()
|
||||
testpb.RegisterQueryServer(server, &testEchoServer{})
|
||||
reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{})
|
||||
|
||||
@ -8,7 +8,8 @@ import (
|
||||
"cosmossdk.io/client/v2/internal/strcase"
|
||||
)
|
||||
|
||||
func toKebab(t testing.TB) {
|
||||
func toKebab(tb testing.TB) {
|
||||
tb.Helper()
|
||||
cases := [][]string{
|
||||
{"testCase", "test-case"},
|
||||
{"TestCase", "test-case"},
|
||||
@ -28,7 +29,7 @@ func toKebab(t testing.TB) {
|
||||
in := i[0]
|
||||
out := i[1]
|
||||
result := strcase.ToKebab(in)
|
||||
assert.Equal(t, out, result, "ToKebab(%s) = %s, want %s", in, result, out)
|
||||
assert.Equal(tb, out, result, "ToKebab(%s) = %s, want %s", in, result, out)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ func testMarshaling(t *testing.T, cdc interface {
|
||||
codec.JSONCodec
|
||||
},
|
||||
) {
|
||||
t.Helper()
|
||||
any, err := types.NewAnyWithValue(&testdata.Dog{Name: "rufus"})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ func BenchmarkRejectUnknownFields_parallel(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkRejectUnknownFields(b *testing.B, parallel bool) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
|
||||
if !parallel {
|
||||
@ -89,6 +90,7 @@ func BenchmarkProtoUnmarshal_parallel(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkProtoUnmarshal(b *testing.B, parallel bool) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
|
||||
if !parallel {
|
||||
|
||||
@ -91,6 +91,7 @@ type testFixture struct {
|
||||
}
|
||||
|
||||
func initFixture(t *testing.T) *testFixture {
|
||||
t.Helper()
|
||||
sk, ctx := deps()
|
||||
schemaBuilder := NewSchemaBuilder(sk)
|
||||
m := NewMap(schemaBuilder, NewPrefix(1), "map", StringKey, Uint64Value)
|
||||
@ -110,6 +111,7 @@ func initFixture(t *testing.T) *testFixture {
|
||||
}
|
||||
|
||||
func createTestGenesisSource(t *testing.T) appmodule.GenesisSource {
|
||||
t.Helper()
|
||||
expectedOrder := []string{"item", "key_set", "map", "sequence"}
|
||||
currentIndex := 0
|
||||
return func(field string) (io.ReadCloser, error) {
|
||||
@ -149,6 +151,7 @@ func (b *bufCloser) Close() error {
|
||||
}
|
||||
|
||||
func newBufCloser(t *testing.T, str string) *bufCloser {
|
||||
t.Helper()
|
||||
b := &bufCloser{
|
||||
Buffer: bytes.NewBufferString(str),
|
||||
closed: false,
|
||||
|
||||
@ -24,6 +24,7 @@ func TestSource(t *testing.T) {
|
||||
}
|
||||
|
||||
func expectJSON(t *testing.T, source appmodule.GenesisSource, field, contents string) {
|
||||
t.Helper()
|
||||
r, err := source(field)
|
||||
require.NoError(t, err)
|
||||
bz, err := io.ReadAll(r)
|
||||
|
||||
@ -29,6 +29,7 @@ func TestFullFundraiserPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func initFundraiserTestVectors(t *testing.T) []addrData {
|
||||
t.Helper()
|
||||
// NOTE: atom fundraiser address
|
||||
// var hdPath string = "m/44'/118'/0'/0/0"
|
||||
var hdToAddrTable []addrData
|
||||
|
||||
@ -1979,6 +1979,7 @@ func TestChangeBcrypt(t *testing.T) {
|
||||
}
|
||||
|
||||
func requireEqualRenamedKey(t *testing.T, key, mnemonic *Record, nameMatch bool) {
|
||||
t.Helper()
|
||||
if nameMatch {
|
||||
require.Equal(t, key.Name, mnemonic.Name)
|
||||
}
|
||||
@ -1997,6 +1998,7 @@ func requireEqualRenamedKey(t *testing.T, key, mnemonic *Record, nameMatch bool)
|
||||
}
|
||||
|
||||
func newKeyring(t *testing.T, name string) Keyring {
|
||||
t.Helper()
|
||||
cdc := getCodec()
|
||||
kr, err := New(name, "test", t.TempDir(), nil, cdc)
|
||||
require.NoError(t, err)
|
||||
@ -2004,12 +2006,14 @@ func newKeyring(t *testing.T, name string) Keyring {
|
||||
}
|
||||
|
||||
func newKeyRecord(t *testing.T, kr Keyring, name string) *Record {
|
||||
t.Helper()
|
||||
k, _, err := kr.NewMnemonic(name, English, sdk.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
return k
|
||||
}
|
||||
|
||||
func assertKeysExist(t *testing.T, kr Keyring, names ...string) {
|
||||
t.Helper()
|
||||
for _, n := range names {
|
||||
_, err := kr.Key(n)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -51,6 +51,7 @@ func randSig() []byte {
|
||||
// tests for malleability
|
||||
// highest bit of signature ECDSA s value must be 0, in the 33th byte
|
||||
func compactSigCheck(t *testing.T, sig []byte) {
|
||||
t.Helper()
|
||||
b := int(sig[32])
|
||||
if b < 0 {
|
||||
t.Errorf("highest bit is negative: %d", b)
|
||||
@ -148,6 +149,7 @@ func TestRandomMessagesWithRandomKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func signAndRecoverWithRandomMessages(t *testing.T, keys func() ([]byte, []byte)) {
|
||||
t.Helper()
|
||||
for i := 0; i < TestCount; i++ {
|
||||
pubkey1, seckey := keys()
|
||||
msg := csprngEntropy(32)
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) {
|
||||
t.Helper()
|
||||
// Marshal to JSON bytes.
|
||||
js, err := cdc.MarshalJSON(src)
|
||||
require.Nil(t, err, "%+v", err)
|
||||
|
||||
@ -909,10 +909,12 @@ func LegacyMaxDec(d1, d2 LegacyDec) LegacyDec {
|
||||
|
||||
// intended to be used with require/assert: require.True(DecEq(...))
|
||||
func LegacyDecEq(t *testing.T, exp, got LegacyDec) (*testing.T, bool, string, string, string) {
|
||||
t.Helper()
|
||||
return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String()
|
||||
}
|
||||
|
||||
func LegacyDecApproxEq(t *testing.T, d1, d2, tol LegacyDec) (*testing.T, bool, string, string, string) {
|
||||
t.Helper()
|
||||
diff := d1.Sub(d2).Abs()
|
||||
return t, diff.LTE(tol), "expected |d1 - d2| <:\t%v\ngot |d1 - d2| = \t\t%v", tol.String(), diff.String()
|
||||
}
|
||||
|
||||
@ -513,6 +513,7 @@ func (i *Int) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) }
|
||||
|
||||
// intended to be used with require/assert: require.True(IntEq(...))
|
||||
func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) {
|
||||
t.Helper()
|
||||
return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String()
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ func TestCodec(t *testing.T) {
|
||||
}
|
||||
|
||||
func testCodec(t *testing.T, spec testutil.TestFieldSpec) {
|
||||
t.Helper()
|
||||
t.Run(fmt.Sprintf("%s %v", spec.FieldName, false), func(t *testing.T) {
|
||||
testCodecNT(t, spec.FieldName, spec.Gen, false)
|
||||
})
|
||||
@ -30,6 +31,7 @@ func testCodec(t *testing.T, spec testutil.TestFieldSpec) {
|
||||
}
|
||||
|
||||
func testCodecNT(t *testing.T, fname protoreflect.Name, generator *rapid.Generator[any], nonTerminal bool) {
|
||||
t.Helper()
|
||||
cdc, err := testutil.MakeTestCodec(fname, nonTerminal)
|
||||
assert.NilError(t, err)
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
|
||||
@ -275,6 +275,7 @@ func TestDurationCompare(t *testing.T) {
|
||||
}
|
||||
|
||||
func encodeValue(t *testing.T, cdc ormfield.Codec, val protoreflect.Value) []byte {
|
||||
t.Helper()
|
||||
buf := &bytes.Buffer{}
|
||||
assert.NilError(t, cdc.Encode(val, buf))
|
||||
return buf.Bytes()
|
||||
|
||||
@ -9,9 +9,10 @@ import (
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
func NewGoLevelDBBackend(t testing.TB) ormtable.Backend {
|
||||
db, err := dbm.NewGoLevelDB("test", t.TempDir(), nil)
|
||||
assert.NilError(t, err)
|
||||
func NewGoLevelDBBackend(tb testing.TB) ormtable.Backend {
|
||||
tb.Helper()
|
||||
db, err := dbm.NewGoLevelDB("test", tb.TempDir(), nil)
|
||||
assert.NilError(tb, err)
|
||||
return ormtable.NewBackend(ormtable.BackendOptions{
|
||||
CommitmentStore: db,
|
||||
})
|
||||
|
||||
@ -259,6 +259,7 @@ func TestModuleDB(t *testing.T) {
|
||||
}
|
||||
|
||||
func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) {
|
||||
t.Helper()
|
||||
// mint coins
|
||||
denom := "foo"
|
||||
acct1 := "bob"
|
||||
|
||||
@ -43,6 +43,7 @@ func TestAutoIncrementScenario(t *testing.T) {
|
||||
}
|
||||
|
||||
func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, ctx context.Context) {
|
||||
t.Helper()
|
||||
store, err := testpb.NewExampleAutoIncrementTableTable(table)
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@ -16,20 +16,23 @@ import (
|
||||
"cosmossdk.io/orm/types/kv"
|
||||
)
|
||||
|
||||
func initBalanceTable(t testing.TB) testpb.BalanceTable {
|
||||
func initBalanceTable(tb testing.TB) testpb.BalanceTable {
|
||||
tb.Helper()
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.Balance{}).ProtoReflect().Type(),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
|
||||
balanceTable, err := testpb.NewBalanceTable(table)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
|
||||
return balanceTable
|
||||
}
|
||||
|
||||
func BenchmarkMemory(b *testing.B) {
|
||||
b.Helper()
|
||||
bench(b, func(tb testing.TB) ormtable.Backend {
|
||||
tb.Helper()
|
||||
return ormtest.NewMemoryBackend()
|
||||
})
|
||||
}
|
||||
@ -39,6 +42,7 @@ func BenchmarkLevelDB(b *testing.B) {
|
||||
}
|
||||
|
||||
func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) {
|
||||
b.Helper()
|
||||
b.Run("insert", func(b *testing.B) {
|
||||
b.StopTimer()
|
||||
ctx := ormtable.WrapContextDefault(newBackend(b))
|
||||
@ -69,6 +73,7 @@ func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) {
|
||||
}
|
||||
|
||||
func benchInsert(b *testing.B, ctx context.Context) {
|
||||
b.Helper()
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Insert(ctx, &testpb.Balance{
|
||||
@ -80,6 +85,7 @@ func benchInsert(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
|
||||
func benchUpdate(b *testing.B, ctx context.Context) {
|
||||
b.Helper()
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Update(ctx, &testpb.Balance{
|
||||
@ -91,6 +97,7 @@ func benchUpdate(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
|
||||
func benchGet(b *testing.B, ctx context.Context) {
|
||||
b.Helper()
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
balance, err := balanceTable.Get(ctx, fmt.Sprintf("acct%d", i), "bar")
|
||||
@ -100,6 +107,7 @@ func benchGet(b *testing.B, ctx context.Context) {
|
||||
}
|
||||
|
||||
func benchDelete(b *testing.B, ctx context.Context) {
|
||||
b.Helper()
|
||||
balanceTable := initBalanceTable(b)
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, balanceTable.Delete(ctx, &testpb.Balance{
|
||||
@ -242,6 +250,7 @@ func BenchmarkManualInsertLevelDB(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchManual(b *testing.B, newStore func() (dbm.DB, error)) {
|
||||
b.Helper()
|
||||
b.Run("insert", func(b *testing.B) {
|
||||
b.StopTimer()
|
||||
store, err := newStore()
|
||||
@ -276,6 +285,7 @@ func benchManual(b *testing.B, newStore func() (dbm.DB, error)) {
|
||||
}
|
||||
|
||||
func benchManualInsert(b *testing.B, store kv.Store) {
|
||||
b.Helper()
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, insertBalance(store, &testpb.Balance{
|
||||
Address: fmt.Sprintf("acct%d", i),
|
||||
@ -286,6 +296,7 @@ func benchManualInsert(b *testing.B, store kv.Store) {
|
||||
}
|
||||
|
||||
func benchManualUpdate(b *testing.B, store kv.Store) {
|
||||
b.Helper()
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, updateBalance(store, &testpb.Balance{
|
||||
Address: fmt.Sprintf("acct%d", i),
|
||||
@ -296,6 +307,7 @@ func benchManualUpdate(b *testing.B, store kv.Store) {
|
||||
}
|
||||
|
||||
func benchManualDelete(b *testing.B, store kv.Store) {
|
||||
b.Helper()
|
||||
for i := 0; i < b.N; i++ {
|
||||
assert.NilError(b, deleteBalance(store, &testpb.Balance{
|
||||
Address: fmt.Sprintf("acct%d", i),
|
||||
@ -305,6 +317,7 @@ func benchManualDelete(b *testing.B, store kv.Store) {
|
||||
}
|
||||
|
||||
func benchManualGet(b *testing.B, store kv.Store) {
|
||||
b.Helper()
|
||||
for i := 0; i < b.N; i++ {
|
||||
balance, err := getBalance(store, fmt.Sprintf("acct%d", i), "bar")
|
||||
assert.NilError(b, err)
|
||||
|
||||
@ -97,6 +97,7 @@ func TestPaginationLimitCountTotal(t *testing.T) {
|
||||
|
||||
// check that the ormkv.Entry's decode and encode to the same bytes
|
||||
func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.ReadonlyStore) {
|
||||
t.Helper()
|
||||
it, err := store.Iterator(nil, nil)
|
||||
assert.NilError(t, err)
|
||||
for it.Valid() {
|
||||
@ -113,6 +114,7 @@ func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.Reado
|
||||
}
|
||||
|
||||
func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backend) {
|
||||
t.Helper()
|
||||
ctx := ormtable.WrapContextDefault(backend)
|
||||
store, err := testpb.NewExampleTableTable(table)
|
||||
assert.NilError(t, err)
|
||||
@ -461,6 +463,7 @@ func TestRandomTableData(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTable(t *testing.T, tableData *TableData) {
|
||||
t.Helper()
|
||||
for _, index := range tableData.table.Indexes() {
|
||||
indexModel := &IndexModel{
|
||||
TableData: tableData,
|
||||
@ -475,6 +478,7 @@ func testTable(t *testing.T, tableData *TableData) {
|
||||
}
|
||||
|
||||
func testUniqueIndex(t *testing.T, model *IndexModel) {
|
||||
t.Helper()
|
||||
index := model.index.(ormtable.UniqueIndex)
|
||||
t.Logf("testing unique index %T %s", index, index.Fields())
|
||||
for i := 0; i < len(model.data); i++ {
|
||||
@ -497,6 +501,7 @@ func testUniqueIndex(t *testing.T, model *IndexModel) {
|
||||
}
|
||||
|
||||
func testIndex(t *testing.T, model *IndexModel) {
|
||||
t.Helper()
|
||||
index := model.index
|
||||
if index.IsFullyOrdered() {
|
||||
t.Logf("testing index %T %s", index, index.Fields())
|
||||
|
||||
@ -244,6 +244,7 @@ func (s *GRPCWebTestSuite) makeGrpcRequest(
|
||||
}
|
||||
|
||||
func readTrailersFromBytes(t *testing.T, dataBytes []byte) Trailer {
|
||||
t.Helper()
|
||||
bufferReader := bytes.NewBuffer(dataBytes)
|
||||
tp := textproto.NewReader(bufio.NewReader(bufferReader))
|
||||
|
||||
|
||||
@ -93,6 +93,7 @@ func (s *ExportSystem) Run(args ...string) cmdtest.RunResult {
|
||||
|
||||
// MustRun wraps (*cmdtest.System).MustRunC, providing e's context.
|
||||
func (s *ExportSystem) MustRun(t *testing.T, args ...string) cmdtest.RunResult {
|
||||
t.Helper()
|
||||
return s.sys.MustRunC(t, s.Ctx, args...)
|
||||
}
|
||||
|
||||
|
||||
@ -254,6 +254,7 @@ type precedenceCommon struct {
|
||||
}
|
||||
|
||||
func newPrecedenceCommon(t *testing.T) precedenceCommon {
|
||||
t.Helper()
|
||||
retval := precedenceCommon{}
|
||||
|
||||
// Determine the env. var. name based off the executable name
|
||||
@ -295,6 +296,7 @@ func newPrecedenceCommon(t *testing.T) precedenceCommon {
|
||||
}
|
||||
|
||||
func (v precedenceCommon) setAll(t *testing.T, setFlag, setEnvVar, setConfigFile *string) {
|
||||
t.Helper()
|
||||
if setFlag != nil {
|
||||
if err := v.cmd.Flags().Set(v.flagName, *setFlag); err != nil {
|
||||
t.Fatalf("Failed setting flag %q", v.flagName)
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func DoBenchmarkDeepCacheStack(b *testing.B, depth int) {
|
||||
b.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
initialStore := cachekv.NewStore(dbadapter.Store{DB: db})
|
||||
|
||||
|
||||
@ -183,6 +183,7 @@ func TestDBIterator(t *testing.T) {
|
||||
}
|
||||
|
||||
func verifyIterator(t *testing.T, itr types.Iterator, expected []int64, msg string) {
|
||||
t.Helper()
|
||||
i := 0
|
||||
for itr.Valid() {
|
||||
key := itr.Key()
|
||||
|
||||
@ -15,6 +15,7 @@ const defaultValueSizeBz = 1 << 12
|
||||
|
||||
// This benchmark measures the time of iterator.Next() when the parent store is blank
|
||||
func benchmarkBlankParentIteratorNext(b *testing.B, keysize int) {
|
||||
b.Helper()
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
kvstore := cachekv.NewStore(mem)
|
||||
// Use a singleton for value, to not waste time computing it
|
||||
@ -44,6 +45,7 @@ func benchmarkBlankParentIteratorNext(b *testing.B, keysize int) {
|
||||
|
||||
// Benchmark setting New keys to a store, where the new keys are in sequence.
|
||||
func benchmarkBlankParentAppend(b *testing.B, keysize int) {
|
||||
b.Helper()
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
kvstore := cachekv.NewStore(mem)
|
||||
|
||||
@ -66,6 +68,7 @@ func benchmarkBlankParentAppend(b *testing.B, keysize int) {
|
||||
// Benchmark setting New keys to a store, where the new keys are random.
|
||||
// the speed of this function does not depend on the values in the parent store
|
||||
func benchmarkRandomSet(b *testing.B, keysize int) {
|
||||
b.Helper()
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
kvstore := cachekv.NewStore(mem)
|
||||
|
||||
@ -96,6 +99,7 @@ func benchmarkRandomSet(b *testing.B, keysize int) {
|
||||
// We essentially are benchmarking the cacheKV iterator creation & iteration times
|
||||
// with the number of entries deleted in the parent.
|
||||
func benchmarkIteratorOnParentWithManyDeletes(b *testing.B, numDeletes int) {
|
||||
b.Helper()
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
|
||||
// Use a singleton for value, to not waste time computing it
|
||||
|
||||
@ -466,6 +466,7 @@ func randInt(n int) int {
|
||||
|
||||
// useful for replaying a error case if we find one
|
||||
func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int) {
|
||||
t.Helper()
|
||||
switch op {
|
||||
case opSet:
|
||||
k := args[0]
|
||||
@ -491,6 +492,7 @@ func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int
|
||||
}
|
||||
|
||||
func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) {
|
||||
t.Helper()
|
||||
r := randInt(totalOps)
|
||||
switch r {
|
||||
case opSet:
|
||||
@ -520,6 +522,7 @@ func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) {
|
||||
|
||||
// iterate over whole domain
|
||||
func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) {
|
||||
t.Helper()
|
||||
itr := st.Iterator(nil, nil)
|
||||
i := 0
|
||||
for ; itr.Valid(); itr.Next() {
|
||||
@ -533,6 +536,7 @@ func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) {
|
||||
}
|
||||
|
||||
func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []keyRange) {
|
||||
t.Helper()
|
||||
// iterate over each and check they match the other
|
||||
itr := st.Iterator(nil, nil)
|
||||
itr2, err := mem.Iterator(nil, nil) // ground truth
|
||||
@ -566,6 +570,7 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem dbm.DB, r []ke
|
||||
}
|
||||
|
||||
func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DB) {
|
||||
t.Helper()
|
||||
// iterate over each and check they match the other
|
||||
itr := st.Iterator(nil, nil)
|
||||
itr2, err := mem.Iterator(nil, nil) // ground truth
|
||||
@ -577,6 +582,7 @@ func assertIterateDomainCompare(t *testing.T, st types.KVStore, mem dbm.DB) {
|
||||
}
|
||||
|
||||
func checkIterators(t *testing.T, itr, itr2 types.Iterator) {
|
||||
t.Helper()
|
||||
for ; itr.Valid(); itr.Next() {
|
||||
require.True(t, itr2.Valid())
|
||||
k, v := itr.Key(), itr.Value()
|
||||
@ -592,6 +598,7 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) {
|
||||
//--------------------------------------------------------
|
||||
|
||||
func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) {
|
||||
t.Helper()
|
||||
for i := start; i < end; i++ {
|
||||
st.Set(keyFmt(i), valFmt(i))
|
||||
err := mem.Set(keyFmt(i), valFmt(i))
|
||||
@ -600,6 +607,7 @@ func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) {
|
||||
}
|
||||
|
||||
func deleteRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) {
|
||||
t.Helper()
|
||||
for i := start; i < end; i++ {
|
||||
st.Delete(keyFmt(i))
|
||||
err := mem.Delete(keyFmt(i))
|
||||
|
||||
@ -35,6 +35,7 @@ func randBytes(numBytes int) []byte {
|
||||
|
||||
// make a tree with data from above and save it
|
||||
func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) {
|
||||
t.Helper()
|
||||
tree := iavl.NewMutableTree(db, cacheSize, false, log.NewNopLogger())
|
||||
|
||||
for k, v := range treeData {
|
||||
@ -294,6 +295,7 @@ func TestIAVLReverseIterator(t *testing.T) {
|
||||
iavlStore.Set([]byte{0x01}, []byte("1"))
|
||||
|
||||
testReverseIterator := func(t *testing.T, start, end []byte, expected []string) {
|
||||
t.Helper()
|
||||
iter := iavlStore.ReverseIterator(start, end)
|
||||
var i int
|
||||
for i = 0; iter.Valid(); iter.Next() {
|
||||
|
||||
@ -29,6 +29,7 @@ type kvpair struct {
|
||||
}
|
||||
|
||||
func genRandomKVPairs(t *testing.T) []kvpair {
|
||||
t.Helper()
|
||||
kvps := make([]kvpair, 20)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
@ -44,6 +45,7 @@ func genRandomKVPairs(t *testing.T) []kvpair {
|
||||
}
|
||||
|
||||
func setRandomKVPairs(t *testing.T, store types.KVStore) []kvpair {
|
||||
t.Helper()
|
||||
kvps := genRandomKVPairs(t)
|
||||
for _, kvp := range kvps {
|
||||
store.Set(kvp.key, kvp.value)
|
||||
@ -52,6 +54,7 @@ func setRandomKVPairs(t *testing.T, store types.KVStore) []kvpair {
|
||||
}
|
||||
|
||||
func testPrefixStore(t *testing.T, baseStore types.KVStore, prefix []byte) {
|
||||
t.Helper()
|
||||
prefixStore := NewStore(baseStore, prefix)
|
||||
prefixPrefixStore := NewStore(prefixStore, []byte("prefix"))
|
||||
|
||||
@ -252,33 +255,39 @@ func mockStoreWithStuff() types.KVStore {
|
||||
}
|
||||
|
||||
func checkValue(t *testing.T, store types.KVStore, key, expected []byte) {
|
||||
t.Helper()
|
||||
bz := store.Get(key)
|
||||
require.Equal(t, expected, bz)
|
||||
}
|
||||
|
||||
func checkValid(t *testing.T, itr types.Iterator, expected bool) {
|
||||
t.Helper()
|
||||
valid := itr.Valid()
|
||||
require.Equal(t, expected, valid)
|
||||
}
|
||||
|
||||
func checkNext(t *testing.T, itr types.Iterator, expected bool) {
|
||||
t.Helper()
|
||||
itr.Next()
|
||||
valid := itr.Valid()
|
||||
require.Equal(t, expected, valid)
|
||||
}
|
||||
|
||||
func checkDomain(t *testing.T, itr types.Iterator, start, end []byte) {
|
||||
t.Helper()
|
||||
ds, de := itr.Domain()
|
||||
require.Equal(t, start, ds)
|
||||
require.Equal(t, end, de)
|
||||
}
|
||||
|
||||
func checkItem(t *testing.T, itr types.Iterator, key, value []byte) {
|
||||
t.Helper()
|
||||
require.Exactly(t, key, itr.Key())
|
||||
require.Exactly(t, value, itr.Value())
|
||||
}
|
||||
|
||||
func checkInvalid(t *testing.T, itr types.Iterator) {
|
||||
t.Helper()
|
||||
checkValid(t, itr, false)
|
||||
checkKeyPanics(t, itr)
|
||||
checkValuePanics(t, itr)
|
||||
@ -286,14 +295,17 @@ func checkInvalid(t *testing.T, itr types.Iterator) {
|
||||
}
|
||||
|
||||
func checkKeyPanics(t *testing.T, itr types.Iterator) {
|
||||
t.Helper()
|
||||
require.Panics(t, func() { itr.Key() })
|
||||
}
|
||||
|
||||
func checkValuePanics(t *testing.T, itr types.Iterator) {
|
||||
t.Helper()
|
||||
require.Panics(t, func() { itr.Value() })
|
||||
}
|
||||
|
||||
func checkNextPanics(t *testing.T, itr types.Iterator) {
|
||||
t.Helper()
|
||||
require.Panics(t, func() { itr.Next() })
|
||||
}
|
||||
|
||||
|
||||
@ -93,6 +93,7 @@ func newMultiStoreWithMixedMountsAndBasicData(db dbm.DB) *rootmulti.Store {
|
||||
}
|
||||
|
||||
func assertStoresEqual(t *testing.T, expect, actual types.CommitKVStore, msgAndArgs ...interface{}) {
|
||||
t.Helper()
|
||||
assert.Equal(t, expect.LastCommitID(), actual.LastCommitID())
|
||||
expectIter := expect.Iterator(nil, nil)
|
||||
expectMap := map[string][]byte{}
|
||||
@ -226,6 +227,7 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
|
||||
}
|
||||
|
||||
func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) {
|
||||
b.Helper()
|
||||
b.Skip("Noisy with slow setup time, please see https://github.com/cosmos/cosmos-sdk/issues/8855.")
|
||||
|
||||
b.ReportAllocs()
|
||||
@ -261,6 +263,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) {
|
||||
}
|
||||
|
||||
func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys uint64) {
|
||||
b.Helper()
|
||||
b.Skip("Noisy with slow setup time, please see https://github.com/cosmos/cosmos-sdk/issues/8855.")
|
||||
|
||||
b.ReportAllocs()
|
||||
|
||||
@ -820,26 +820,27 @@ func unmountStore(rootStore *Store, storeKeyName string) {
|
||||
}
|
||||
|
||||
func checkStore(t *testing.T, store *Store, expect, got types.CommitID) {
|
||||
t.Helper()
|
||||
require.Equal(t, expect, got)
|
||||
require.Equal(t, expect, store.LastCommitID())
|
||||
}
|
||||
|
||||
func checkContains(t testing.TB, info []types.StoreInfo, wanted []string) {
|
||||
t.Helper()
|
||||
func checkContains(tb testing.TB, info []types.StoreInfo, wanted []string) {
|
||||
tb.Helper()
|
||||
|
||||
for _, want := range wanted {
|
||||
checkHas(t, info, want)
|
||||
checkHas(tb, info, want)
|
||||
}
|
||||
}
|
||||
|
||||
func checkHas(t testing.TB, info []types.StoreInfo, want string) {
|
||||
t.Helper()
|
||||
func checkHas(tb testing.TB, info []types.StoreInfo, want string) {
|
||||
tb.Helper()
|
||||
for _, i := range info {
|
||||
if i.Name == want {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("storeInfo doesn't contain %s", want)
|
||||
tb.Fatalf("storeInfo doesn't contain %s", want)
|
||||
}
|
||||
|
||||
func getExpectedCommitID(store *Store, ver int64) types.CommitID {
|
||||
|
||||
@ -206,6 +206,7 @@ func (m *mockErrorSnapshotter) SetSnapshotInterval(snapshotInterval uint64) {
|
||||
// setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1.
|
||||
// The snapshot will complete when the returned closer is called.
|
||||
func setupBusyManager(t *testing.T) *snapshots.Manager {
|
||||
t.Helper()
|
||||
store, err := snapshots.NewStore(db.NewMemDB(), t.TempDir())
|
||||
require.NoError(t, err)
|
||||
hung := newHungSnapshotter()
|
||||
@ -323,14 +324,14 @@ func (s *extSnapshotter) RestoreExtension(height uint64, format uint32, payloadR
|
||||
}
|
||||
|
||||
// GetTempDir returns a writable temporary director for the test to use.
|
||||
func GetTempDir(t testing.TB) string {
|
||||
t.Helper()
|
||||
func GetTempDir(tb testing.TB) string {
|
||||
tb.Helper()
|
||||
// os.MkDir() is used instead of testing.T.TempDir()
|
||||
// see https://github.com/cosmos/cosmos-sdk/pull/8475 and
|
||||
// https://github.com/cosmos/cosmos-sdk/pull/10341 for
|
||||
// this change's rationale.
|
||||
tempdir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(tempdir) })
|
||||
require.NoError(tb, err)
|
||||
tb.Cleanup(func() { _ = os.RemoveAll(tempdir) })
|
||||
return tempdir
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func setupStore(t *testing.T) *snapshots.Store {
|
||||
t.Helper()
|
||||
store, err := snapshots.NewStore(db.NewMemDB(), GetTempDir(t))
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func newMemTestKVStore(t *testing.T) types.KVStore {
|
||||
t.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, iavl.DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics())
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -712,7 +712,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func trackingCorrected(ctx sdk.Context, t *testing.T, ak keeper.AccountKeeper, addr sdk.AccAddress, expDelVesting, expDelFree sdk.Coins) {
|
||||
func trackingCorrected(ctx sdk.Context, t *testing.T, ak keeper.AccountKeeper, addr sdk.AccAddress, expDelVesting, expDelFree sdk.Coins) { //nolint:thelper // false positive
|
||||
t.Helper()
|
||||
baseAccount := ak.GetAccount(ctx, addr)
|
||||
vDA, ok := baseAccount.(exported.VestingAccount)
|
||||
@ -769,6 +769,7 @@ func dirtyTrackingFields(ctx sdk.Context, vesting exported.VestingAccount, accou
|
||||
}
|
||||
|
||||
func createValidator(t *testing.T, ctx sdk.Context, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, powers int64) (sdk.AccAddress, sdk.ValAddress) {
|
||||
t.Helper()
|
||||
valTokens := sdk.TokensFromConsensusPower(powers, sdk.DefaultPowerReduction)
|
||||
addrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 1, valTokens)
|
||||
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
|
||||
|
||||
@ -103,6 +103,7 @@ type suite struct {
|
||||
}
|
||||
|
||||
func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) suite {
|
||||
t.Helper()
|
||||
res := suite{}
|
||||
|
||||
var genAccounts []simtestutil.GenesisAccount
|
||||
@ -137,6 +138,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s
|
||||
|
||||
// CheckBalance checks the balance of an account.
|
||||
func checkBalance(t *testing.T, baseApp *baseapp.BaseApp, addr sdk.AccAddress, balances sdk.Coins, keeper bankkeeper.Keeper) {
|
||||
t.Helper()
|
||||
ctxCheck := baseApp.NewContext(true)
|
||||
keeperBalances := keeper.GetAllBalances(ctxCheck, addr)
|
||||
require.True(t, balances.Equal(keeperBalances))
|
||||
|
||||
@ -63,6 +63,7 @@ type deterministicFixture struct {
|
||||
}
|
||||
|
||||
func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
t.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}).Codec
|
||||
|
||||
|
||||
@ -58,13 +58,14 @@ type fixture struct {
|
||||
valAddr sdk.ValAddress
|
||||
}
|
||||
|
||||
func initFixture(t testing.TB) *fixture {
|
||||
func initFixture(tb testing.TB) *fixture {
|
||||
tb.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, stakingtypes.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, distribution.AppModuleBasic{}).Codec
|
||||
|
||||
logger := log.NewTestLogger(t)
|
||||
logger := log.NewTestLogger(tb)
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, types.Header{}, true, logger)
|
||||
|
||||
@ -79,13 +79,14 @@ type fixture struct {
|
||||
stakingKeeper *stakingkeeper.Keeper
|
||||
}
|
||||
|
||||
func initFixture(t testing.TB) *fixture {
|
||||
func initFixture(tb testing.TB) *fixture {
|
||||
tb.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, paramtypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, evidence.AppModuleBasic{}).Codec
|
||||
|
||||
logger := log.NewTestLogger(t)
|
||||
logger := log.NewTestLogger(tb)
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger)
|
||||
@ -150,10 +151,10 @@ func initFixture(t testing.TB) *fixture {
|
||||
evidencetypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), keeper.NewMsgServerImpl(*evidenceKeeper))
|
||||
evidencetypes.RegisterQueryServer(integrationApp.QueryHelper(), keeper.NewQuerier(evidenceKeeper))
|
||||
|
||||
assert.NilError(t, slashingKeeper.SetParams(sdkCtx, testutil.TestParams()))
|
||||
assert.NilError(tb, slashingKeeper.SetParams(sdkCtx, testutil.TestParams()))
|
||||
|
||||
// set default staking params
|
||||
assert.NilError(t, stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams()))
|
||||
assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams()))
|
||||
|
||||
return &fixture{
|
||||
app: integrationApp,
|
||||
|
||||
@ -24,6 +24,7 @@ var (
|
||||
|
||||
// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes.
|
||||
func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent {
|
||||
t.Helper()
|
||||
msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String())
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@ -189,6 +189,7 @@ func TestImportExportQueues(t *testing.T) {
|
||||
}
|
||||
|
||||
func clearDB(t *testing.T, db *dbm.MemDB) {
|
||||
t.Helper()
|
||||
iter, err := db.Iterator(nil, nil)
|
||||
assert.NilError(t, err)
|
||||
defer iter.Close()
|
||||
|
||||
@ -36,6 +36,7 @@ func getTestProposal() []sdk.Msg {
|
||||
}
|
||||
|
||||
func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
||||
t.Helper()
|
||||
addrs := simtestutil.AddTestAddrsIncremental(f.bankKeeper, f.stakingKeeper, f.ctx, 5, math.NewInt(30000000))
|
||||
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
|
||||
pks := simtestutil.CreateTestPubKeys(5)
|
||||
|
||||
@ -48,13 +48,14 @@ type fixture struct {
|
||||
govKeeper *keeper.Keeper
|
||||
}
|
||||
|
||||
func initFixture(t testing.TB) *fixture {
|
||||
func initFixture(tb testing.TB) *fixture {
|
||||
tb.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, stakingtypes.StoreKey, types.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, gov.AppModuleBasic{}).Codec
|
||||
|
||||
logger := log.NewTestLogger(t)
|
||||
logger := log.NewTestLogger(tb)
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger)
|
||||
@ -118,12 +119,12 @@ func initFixture(t testing.TB) *fixture {
|
||||
authority.String(),
|
||||
)
|
||||
err := govKeeper.ProposalID.Set(newCtx, 1)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
govRouter := v1beta1.NewRouter()
|
||||
govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler)
|
||||
govKeeper.SetLegacyRouter(govRouter)
|
||||
err = govKeeper.Params.Set(newCtx, v1.DefaultParams())
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
|
||||
|
||||
@ -50,13 +50,14 @@ type fixture struct {
|
||||
valAddrs []sdk.ValAddress
|
||||
}
|
||||
|
||||
func initFixture(t testing.TB) *fixture {
|
||||
func initFixture(tb testing.TB) *fixture {
|
||||
tb.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}).Codec
|
||||
|
||||
logger := log.NewTestLogger(t)
|
||||
logger := log.NewTestLogger(tb)
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, cmtproto.Header{}, true, logger)
|
||||
|
||||
@ -53,6 +53,7 @@ func init() {
|
||||
|
||||
// intended to be used with require/assert: require.True(ValEq(...))
|
||||
func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) {
|
||||
t.Helper()
|
||||
return t, exp.MinEqual(&got), "expected:\n%v\ngot:\n%v", exp, got
|
||||
}
|
||||
|
||||
@ -65,6 +66,7 @@ func generateAddresses(f *fixture, numAddrs int) ([]sdk.AccAddress, []sdk.ValAdd
|
||||
}
|
||||
|
||||
func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) {
|
||||
t.Helper()
|
||||
addrs := simtestutil.AddTestAddrsIncremental(f.bankKeeper, f.stakingKeeper, f.sdkCtx, 5, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 300))
|
||||
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
|
||||
pks := simtestutil.CreateTestPubKeys(5)
|
||||
@ -91,13 +93,14 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
|
||||
return addrs, valAddrs, vals
|
||||
}
|
||||
|
||||
func initFixture(t testing.TB) *fixture {
|
||||
func initFixture(tb testing.TB) *fixture {
|
||||
tb.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, types.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, staking.AppModuleBasic{}).Codec
|
||||
|
||||
logger := log.NewTestLogger(t)
|
||||
logger := log.NewTestLogger(tb)
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, cmtprototypes.Header{}, true, logger)
|
||||
@ -153,7 +156,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
types.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))
|
||||
|
||||
// set default staking params
|
||||
assert.NilError(t, stakingKeeper.SetParams(sdkCtx, types.DefaultParams()))
|
||||
assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, types.DefaultParams()))
|
||||
|
||||
f := fixture{
|
||||
app: integrationApp,
|
||||
|
||||
@ -65,6 +65,7 @@ type deterministicFixture struct {
|
||||
}
|
||||
|
||||
func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
t.Helper()
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
|
||||
)
|
||||
@ -185,7 +186,8 @@ func bondTypeGenerator() *rapid.Generator[stakingtypes.BondStatus] {
|
||||
}
|
||||
|
||||
// createValidator creates a validator with random values.
|
||||
func createValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) stakingtypes.Validator {
|
||||
func createValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
pubkey := pubKeyGenerator().Draw(rt, "pubkey")
|
||||
pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey)
|
||||
assert.NilError(t, err)
|
||||
@ -215,21 +217,24 @@ func createValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) staking
|
||||
}
|
||||
|
||||
// createAndSetValidatorWithStatus creates a validator with random values but with given status and sets to the state
|
||||
func createAndSetValidatorWithStatus(rt *rapid.T, f *deterministicFixture, t *testing.T, status stakingtypes.BondStatus) stakingtypes.Validator {
|
||||
val := createValidator(rt, f, t)
|
||||
func createAndSetValidatorWithStatus(t *testing.T, rt *rapid.T, f *deterministicFixture, status stakingtypes.BondStatus) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
val := createValidator(t, rt, f)
|
||||
val.Status = status
|
||||
setValidator(f, t, val)
|
||||
setValidator(t, f, val)
|
||||
return val
|
||||
}
|
||||
|
||||
// createAndSetValidator creates a validator with random values and sets to the state
|
||||
func createAndSetValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) stakingtypes.Validator {
|
||||
val := createValidator(rt, f, t)
|
||||
setValidator(f, t, val)
|
||||
func createAndSetValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
val := createValidator(t, rt, f)
|
||||
setValidator(t, f, val)
|
||||
return val
|
||||
}
|
||||
|
||||
func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.Validator) {
|
||||
func setValidator(t *testing.T, f *deterministicFixture, validator stakingtypes.Validator) {
|
||||
t.Helper()
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.ctx, validator))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByPowerIndex(f.ctx, validator))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.ctx, validator))
|
||||
@ -244,7 +249,8 @@ func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.
|
||||
}
|
||||
|
||||
// getStaticValidator creates a validator with hard-coded values and sets to the state.
|
||||
func getStaticValidator(f *deterministicFixture, t *testing.T) stakingtypes.Validator {
|
||||
func getStaticValidator(t *testing.T, f *deterministicFixture) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
pubkey := ed25519.PubKey{Key: []byte{24, 179, 242, 2, 151, 3, 34, 6, 1, 11, 0, 194, 202, 201, 77, 1, 167, 40, 249, 115, 32, 97, 18, 1, 1, 127, 255, 103, 13, 1, 34, 1}}
|
||||
pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey)
|
||||
assert.NilError(t, err)
|
||||
@ -273,12 +279,13 @@ func getStaticValidator(f *deterministicFixture, t *testing.T) stakingtypes.Vali
|
||||
MinSelfDelegation: math.NewInt(10),
|
||||
}
|
||||
|
||||
setValidator(f, t, validator)
|
||||
setValidator(t, f, validator)
|
||||
return validator
|
||||
}
|
||||
|
||||
// getStaticValidator2 creates a validator with hard-coded values and sets to the state.
|
||||
func getStaticValidator2(f *deterministicFixture, t *testing.T) stakingtypes.Validator {
|
||||
func getStaticValidator2(t *testing.T, f *deterministicFixture) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
pubkey := ed25519.PubKey{Key: []byte{40, 249, 115, 32, 97, 18, 1, 1, 127, 255, 103, 13, 1, 34, 1, 24, 179, 242, 2, 151, 3, 34, 6, 1, 11, 0, 194, 202, 201, 77, 1, 167}}
|
||||
pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey)
|
||||
assert.NilError(t, err)
|
||||
@ -306,19 +313,21 @@ func getStaticValidator2(f *deterministicFixture, t *testing.T) stakingtypes.Val
|
||||
),
|
||||
MinSelfDelegation: math.NewInt(1),
|
||||
}
|
||||
setValidator(f, t, validator)
|
||||
setValidator(t, f, validator)
|
||||
|
||||
return validator
|
||||
}
|
||||
|
||||
// createDelegationAndDelegate funds the delegator account with a random delegation in range 100-1000 and delegates.
|
||||
func createDelegationAndDelegate(rt *rapid.T, f *deterministicFixture, t *testing.T, delegator sdk.AccAddress, validator stakingtypes.Validator) (newShares math.LegacyDec, err error) {
|
||||
func createDelegationAndDelegate(t *testing.T, rt *rapid.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator) (newShares math.LegacyDec, err error) {
|
||||
t.Helper()
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, rapid.Int64Range(100, 1000).Draw(rt, "amount"))
|
||||
return fundAccountAndDelegate(f, t, delegator, validator, amt)
|
||||
return fundAccountAndDelegate(t, f, delegator, validator, amt)
|
||||
}
|
||||
|
||||
// fundAccountAndDelegate funds the delegator account with the specified delegation and delegates.
|
||||
func fundAccountAndDelegate(f *deterministicFixture, t *testing.T, delegator sdk.AccAddress, validator stakingtypes.Validator, amt math.Int) (newShares math.LegacyDec, err error) {
|
||||
func fundAccountAndDelegate(t *testing.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator, amt math.Int) (newShares math.LegacyDec, err error) {
|
||||
t.Helper()
|
||||
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amt))
|
||||
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, coins))
|
||||
@ -333,7 +342,7 @@ func TestGRPCValidator(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
val := createAndSetValidator(rt, f, t)
|
||||
val := createAndSetValidator(t, rt, f)
|
||||
req := &stakingtypes.QueryValidatorRequest{
|
||||
ValidatorAddr: val.OperatorAddress,
|
||||
}
|
||||
@ -342,7 +351,7 @@ func TestGRPCValidator(t *testing.T) {
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
val := getStaticValidator(f, t)
|
||||
val := getStaticValidator(t, f)
|
||||
req := &stakingtypes.QueryValidatorRequest{
|
||||
ValidatorAddr: val.OperatorAddress,
|
||||
}
|
||||
@ -358,7 +367,7 @@ func TestGRPCValidators(t *testing.T) {
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
valsCount := rapid.IntRange(1, 3).Draw(rt, "num-validators")
|
||||
for i := 0; i < valsCount; i++ {
|
||||
createAndSetValidator(rt, f, t)
|
||||
createAndSetValidator(t, rt, f)
|
||||
}
|
||||
|
||||
req := &stakingtypes.QueryValidatorsRequest{
|
||||
@ -370,8 +379,8 @@ func TestGRPCValidators(t *testing.T) {
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
getStaticValidator(f, t)
|
||||
getStaticValidator2(f, t)
|
||||
getStaticValidator(t, f)
|
||||
getStaticValidator2(t, f)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false)
|
||||
}
|
||||
@ -381,12 +390,12 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels")
|
||||
|
||||
for i := 0; i < numDels; i++ {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
_, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@ -400,12 +409,12 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
_, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = fundAccountAndDelegate(f, t, delegatorAddr2, validator, f.amt2)
|
||||
_, err = fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryValidatorDelegationsRequest{
|
||||
@ -420,12 +429,12 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
numDels := rapid.IntRange(1, 3).Draw(rt, "num-dels")
|
||||
|
||||
for i := 0; i < numDels; i++ {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares)
|
||||
@ -442,14 +451,14 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
validator := getStaticValidator(t, f)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
shares2, err := fundAccountAndDelegate(f, t, delegatorAddr2, validator, f.amt2)
|
||||
shares2, err := fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr2, validatorAddr1, shares2)
|
||||
@ -467,9 +476,9 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
_, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegationRequest{
|
||||
@ -482,8 +491,8 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
_, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
validator := getStaticValidator(t, f)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegationRequest{
|
||||
@ -499,9 +508,9 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares)
|
||||
@ -516,9 +525,9 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
validator := getStaticValidator(f, t)
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1)
|
||||
@ -541,8 +550,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
_, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@ -556,8 +565,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
_, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
validator := getStaticValidator(t, f)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegatorDelegationsRequest{
|
||||
@ -572,10 +581,10 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
_, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegatorValidatorRequest{
|
||||
@ -588,8 +597,8 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
_, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
validator := getStaticValidator(t, f)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -610,8 +619,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegator, validator.GetOperator(), shares)
|
||||
@ -628,8 +637,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
shares1, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
validator := getStaticValidator(t, f)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1)
|
||||
@ -650,7 +659,7 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
numVals := rapid.IntRange(1, 5).Draw(rt, "num-vals")
|
||||
vals := make(stakingtypes.Validators, 0, numVals)
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
vals = append(vals, validator)
|
||||
}
|
||||
|
||||
@ -676,7 +685,7 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
historicalInfo := stakingtypes.HistoricalInfo{
|
||||
Header: cmtproto.Header{},
|
||||
@ -707,8 +716,8 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
_, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@ -722,9 +731,9 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(f, t)
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
_, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator1}
|
||||
@ -736,13 +745,13 @@ func TestGRPCPool(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
createAndSetValidator(rt, f, t)
|
||||
createAndSetValidator(t, rt, f)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
getStaticValidator(f, t)
|
||||
getStaticValidator(t, f)
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6242, false)
|
||||
}
|
||||
|
||||
@ -751,18 +760,18 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
f := initDeterministicFixture(t)
|
||||
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
srcValAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress)
|
||||
assert.NilError(t, err)
|
||||
|
||||
validator2 := createAndSetValidatorWithStatus(rt, f, t, stakingtypes.Bonded)
|
||||
validator2 := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
dstValAddr, err := sdk.ValAddressFromBech32(validator2.OperatorAddress)
|
||||
assert.NilError(t, err)
|
||||
|
||||
numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels")
|
||||
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
shares, err := createDelegationAndDelegate(rt, f, t, delegator, validator)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = f.stakingKeeper.BeginRedelegation(f.ctx, delegator, srcValAddr, dstValAddr, shares)
|
||||
@ -793,10 +802,10 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
validator := getStaticValidator(f, t)
|
||||
_ = getStaticValidator2(f, t)
|
||||
validator := getStaticValidator(t, f)
|
||||
_ = getStaticValidator2(t, f)
|
||||
|
||||
shares, err := fundAccountAndDelegate(f, t, delegatorAddr1, validator, f.amt1)
|
||||
shares, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = f.stakingKeeper.BeginRedelegation(f.ctx, delegatorAddr1, validatorAddr1, validatorAddr2, shares)
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func bootstrapGenesisTest(t *testing.T, numAddrs int) (*fixture, []sdk.AccAddress) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func createValidatorAccs(t *testing.T, f *fixture) ([]sdk.AccAddress, []types.Validator) {
|
||||
t.Helper()
|
||||
addrs, _, validators := createValidators(&testing.T{}, f, []int64{9, 8, 7})
|
||||
header := cmtproto.Header{
|
||||
ChainID: "HelloChain",
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
|
||||
// bootstrapSlashTest creates 3 validators and bootstrap the app.
|
||||
func bootstrapSlashTest(t *testing.T, power int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
|
||||
// SetupUnbondingTests creates two validators and setup mocked staking hooks for testing unbonding
|
||||
func SetupUnbondingTests(t *testing.T, f *fixture, hookCalled *bool, ubdeID *uint64) (bondDenom string, addrDels []sdk.AccAddress, addrVals []sdk.ValAddress) {
|
||||
t.Helper()
|
||||
// setup hooks
|
||||
mockCtrl := gomock.NewController(t)
|
||||
mockStackingHooks := testutil.NewMockStakingHooks(mockCtrl)
|
||||
@ -92,6 +93,7 @@ func doUnbondingDelegation(
|
||||
addrVals []sdk.ValAddress,
|
||||
hookCalled *bool,
|
||||
) (completionTime time.Time, bondedAmt, notBondedAmt math.Int) {
|
||||
t.Helper()
|
||||
// UNDELEGATE
|
||||
// Save original bonded and unbonded amounts
|
||||
bondedAmt1 := bankKeeper.GetBalance(ctx, stakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
@ -129,6 +131,7 @@ func doRedelegation(
|
||||
addrVals []sdk.ValAddress,
|
||||
hookCalled *bool,
|
||||
) (completionTime time.Time) {
|
||||
t.Helper()
|
||||
var err error
|
||||
completionTime, err = stakingKeeper.BeginRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1], math.LegacyNewDec(1))
|
||||
assert.NilError(t, err)
|
||||
@ -152,6 +155,7 @@ func doValidatorUnbonding(
|
||||
addrVal sdk.ValAddress,
|
||||
hookCalled *bool,
|
||||
) (validator types.Validator) {
|
||||
t.Helper()
|
||||
validator, found := stakingKeeper.GetValidator(ctx, addrVal)
|
||||
assert.Assert(t, found)
|
||||
// Check that status is bonded
|
||||
|
||||
@ -18,19 +18,21 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func newMonikerValidator(t testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
|
||||
func newMonikerValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
|
||||
tb.Helper()
|
||||
v, err := types.NewValidator(operator, pubKey, types.Description{Moniker: moniker})
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
return v
|
||||
}
|
||||
|
||||
func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*fixture, []sdk.AccAddress, []sdk.ValAddress) {
|
||||
f := initFixture(t)
|
||||
func bootstrapValidatorTest(tb testing.TB, power int64, numAddrs int) (*fixture, []sdk.AccAddress, []sdk.ValAddress) {
|
||||
tb.Helper()
|
||||
f := initFixture(tb)
|
||||
|
||||
addrDels, addrVals := generateAddresses(f, numAddrs)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(tb, err)
|
||||
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power)
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(bondDenom, amt.MulRaw(int64(len(addrDels)))))
|
||||
@ -40,18 +42,19 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*fixture,
|
||||
// set bonded pool supply
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), totalSupply))
|
||||
assert.NilError(tb, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), totalSupply))
|
||||
|
||||
return f, addrDels, addrVals
|
||||
}
|
||||
|
||||
func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress, []types.Validator) {
|
||||
f, addrs, valAddrs := bootstrapValidatorTest(t, power, numAddrs)
|
||||
func initValidators(tb testing.TB, power int64, numAddrs int, powers []int64) (*fixture, []sdk.AccAddress, []sdk.ValAddress, []types.Validator) {
|
||||
tb.Helper()
|
||||
f, addrs, valAddrs := bootstrapValidatorTest(tb, power, numAddrs)
|
||||
pks := simtestutil.CreateTestPubKeys(numAddrs)
|
||||
|
||||
vs := make([]types.Validator, len(powers))
|
||||
for i, power := range powers {
|
||||
vs[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i])
|
||||
vs[i] = testutil.NewValidator(tb, sdk.ValAddress(addrs[i]), pks[i])
|
||||
tokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power)
|
||||
vs[i], _ = vs[i].AddTokensFromDel(tokens)
|
||||
}
|
||||
@ -844,6 +847,7 @@ func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
||||
}
|
||||
|
||||
func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k *keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate {
|
||||
t.Helper()
|
||||
updates, err := k.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
assert.NilError(t, err)
|
||||
if expectedUpdatesLen >= 0 {
|
||||
|
||||
@ -192,6 +192,7 @@ func TestAminoJSON_Equivalence(t *testing.T) {
|
||||
}
|
||||
|
||||
func newAny(t *testing.T, msg proto.Message) *anypb.Any {
|
||||
t.Helper()
|
||||
bz, err := proto.Marshal(msg)
|
||||
require.NoError(t, err)
|
||||
typeName := fmt.Sprintf("/%s", msg.ProtoReflect().Descriptor().FullName())
|
||||
|
||||
@ -17,6 +17,7 @@ type TestAccount struct {
|
||||
}
|
||||
|
||||
func CreateKeyringAccounts(t *testing.T, kr keyring.Keyring, num int) []TestAccount {
|
||||
t.Helper()
|
||||
accounts := make([]TestAccount, num)
|
||||
for i := range accounts {
|
||||
record, _, err := kr.NewMnemonic(
|
||||
|
||||
@ -37,13 +37,14 @@ type TestContext struct {
|
||||
CMS store.CommitMultiStore
|
||||
}
|
||||
|
||||
func DefaultContextWithDB(t testing.TB, key, tkey storetypes.StoreKey) TestContext {
|
||||
func DefaultContextWithDB(tb testing.TB, key, tkey storetypes.StoreKey) TestContext {
|
||||
tb.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db)
|
||||
cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db)
|
||||
err := cms.LoadLatestVersion()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(tb, err)
|
||||
|
||||
ctx := sdk.NewContext(cms, cmtproto.Header{Time: time.Now()}, false, log.NewNopLogger())
|
||||
|
||||
|
||||
@ -52,36 +52,36 @@ func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader {
|
||||
|
||||
// Write the given string to a new temporary file.
|
||||
// Returns an open file for the test to use.
|
||||
func WriteToNewTempFile(t testing.TB, s string) *os.File {
|
||||
t.Helper()
|
||||
func WriteToNewTempFile(tb testing.TB, s string) *os.File {
|
||||
tb.Helper()
|
||||
|
||||
fp := TempFile(t)
|
||||
fp := TempFile(tb)
|
||||
_, err := fp.WriteString(s)
|
||||
|
||||
require.Nil(t, err)
|
||||
require.Nil(tb, err)
|
||||
|
||||
return fp
|
||||
}
|
||||
|
||||
// TempFile returns a writable temporary file for the test to use.
|
||||
func TempFile(t testing.TB) *os.File {
|
||||
t.Helper()
|
||||
func TempFile(tb testing.TB) *os.File {
|
||||
tb.Helper()
|
||||
|
||||
fp, err := os.CreateTemp(GetTempDir(t), "")
|
||||
require.NoError(t, err)
|
||||
fp, err := os.CreateTemp(GetTempDir(tb), "")
|
||||
require.NoError(tb, err)
|
||||
|
||||
return fp
|
||||
}
|
||||
|
||||
// GetTempDir returns a writable temporary director for the test to use.
|
||||
func GetTempDir(t testing.TB) string {
|
||||
t.Helper()
|
||||
func GetTempDir(tb testing.TB) string {
|
||||
tb.Helper()
|
||||
// os.MkDir() is used instead of testing.T.TempDir()
|
||||
// see https://github.com/cosmos/cosmos-sdk/pull/8475 and
|
||||
// https://github.com/cosmos/cosmos-sdk/pull/10341 for
|
||||
// this change's rationale.
|
||||
tempdir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(tempdir) })
|
||||
require.NoError(tb, err)
|
||||
tb.Cleanup(func() { _ = os.RemoveAll(tempdir) })
|
||||
return tempdir
|
||||
}
|
||||
|
||||
@ -71,8 +71,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:staticcheck // used for legacy testing
|
||||
simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState)
|
||||
simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck // we're testing the old way here
|
||||
simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState)
|
||||
return app.SimulationManager().WeightedOperations(simState)
|
||||
}
|
||||
|
||||
@ -110,6 +110,7 @@ func checkDiffResults(t *testing.T, store1, store2 storetypes.KVStore, noDiff bo
|
||||
}
|
||||
|
||||
func initTestStores(t *testing.T) (storetypes.KVStore, storetypes.KVStore) {
|
||||
t.Helper()
|
||||
db := dbm.NewMemDB()
|
||||
ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
|
||||
|
||||
|
||||
@ -96,6 +96,7 @@ func SignCheckDeliver(
|
||||
t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header types.Header, msgs []sdk.Msg,
|
||||
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
|
||||
) (sdk.GasInfo, *sdk.Result, error) {
|
||||
t.Helper()
|
||||
tx, err := GenSignedMockTx(
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
txCfg,
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
|
||||
// initClientContext initiates client Context for tests
|
||||
func initClientContext(t *testing.T) (client.Context, func()) {
|
||||
t.Helper()
|
||||
home := t.TempDir()
|
||||
chainID := "test-chain"
|
||||
clientCtx := client.Context{}.
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func mustReadConfig(t *testing.T, path string) []byte {
|
||||
t.Helper()
|
||||
f, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open file: %v", err)
|
||||
|
||||
@ -119,7 +119,7 @@ func (s *argsTestSuite) clearEnv() *cosmovisorEnv {
|
||||
// setEnv sets environment variables to the values provided.
|
||||
// If t is not nil, and there's a problem, the test will fail immediately.
|
||||
// If t is nil, problems will just be logged using s.T().
|
||||
func (s *argsTestSuite) setEnv(t *testing.T, env *cosmovisorEnv) {
|
||||
func (s *argsTestSuite) setEnv(t *testing.T, env *cosmovisorEnv) { //nolint:thelper // false positive
|
||||
if t == nil {
|
||||
s.T().Logf("Restoring environment variables.")
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ func (s *InitTestSuite) clearEnv() *cosmovisorInitEnv {
|
||||
// setEnv sets environment variables to the values provided.
|
||||
// If t is not nil, and there's a problem, the test will fail immediately.
|
||||
// If t is nil, problems will just be logged using s.T().
|
||||
func (s *InitTestSuite) setEnv(t *testing.T, env *cosmovisorInitEnv) {
|
||||
func (s *InitTestSuite) setEnv(t *testing.T, env *cosmovisorInitEnv) { //nolint:thelper // false psotive
|
||||
if t == nil {
|
||||
s.T().Logf("Restoring environment variables.")
|
||||
}
|
||||
|
||||
@ -115,6 +115,7 @@ func (a addrMock) Address() []byte {
|
||||
}
|
||||
|
||||
func (a addrMock) AddressWithLen(t *testing.T) []byte {
|
||||
t.Helper()
|
||||
addr, err := LengthPrefix(a.Addr)
|
||||
assert.NoError(t, err)
|
||||
return addr
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we do old keys, they're keys after all.
|
||||
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we're using this to support the legacy way of dealing with bech32
|
||||
)
|
||||
|
||||
type addressTestSuite struct {
|
||||
|
||||
@ -15,6 +15,7 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) {
|
||||
return func(b *testing.B) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
coinsA := Coins(make([]Coin, numCoinsA))
|
||||
coinsB := Coins(make([]Coin, numCoinsB))
|
||||
@ -46,6 +47,7 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
benchmarkingFunc := func(numCoinsA, numCoinsB int) func(b *testing.B) {
|
||||
return func(b *testing.B) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
coinsA := Coins(make([]Coin, numCoinsA))
|
||||
coinsB := Coins(make([]Coin, numCoinsB))
|
||||
@ -80,6 +82,7 @@ func BenchmarkSumOfCoinAdds(b *testing.B) {
|
||||
// already in the sum, and (coinsPerAdd - numIntersectingCoins) that are new denoms.
|
||||
benchmarkingFunc := func(numAdds, coinsPerAdd, numIntersectingCoins int, sumFn func([]Coins) Coins) func(b *testing.B) {
|
||||
return func(b *testing.B) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
addCoins := make([]Coins, numAdds)
|
||||
nonIntersectingCoins := coinsPerAdd - numIntersectingCoins
|
||||
|
||||
@ -265,6 +265,7 @@ func TestSigIntegration(t *testing.T) {
|
||||
}
|
||||
|
||||
func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...cryptotypes.PrivKey) (storetypes.Gas, error) {
|
||||
t.Helper()
|
||||
suite := SetupTestSuite(t, true)
|
||||
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ type AnteTestSuite struct {
|
||||
|
||||
// SetupTest setups a new test, with new app, context, and anteHandler.
|
||||
func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
|
||||
t.Helper()
|
||||
suite := &AnteTestSuite{}
|
||||
ctrl := gomock.NewController(t)
|
||||
suite.bankKeeper = authtestutil.NewMockBankKeeper(ctrl)
|
||||
@ -156,6 +157,7 @@ func (t TestCaseArgs) WithAccountsInfo(accs []TestAccount) TestCaseArgs {
|
||||
// DeliverMsgs constructs a tx and runs it through the ante handler. This is used to set the context for a test case, for
|
||||
// example to test for replay protection.
|
||||
func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, simulate bool) (sdk.Context, error) {
|
||||
t.Helper()
|
||||
require.NoError(t, suite.txBuilder.SetMsgs(msgs...))
|
||||
suite.txBuilder.SetFeeAmount(feeAmount)
|
||||
suite.txBuilder.SetGasLimit(gasLimit)
|
||||
@ -169,6 +171,7 @@ func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKe
|
||||
}
|
||||
|
||||
func (suite *AnteTestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) {
|
||||
t.Helper()
|
||||
require.NoError(t, suite.txBuilder.SetMsgs(args.msgs...))
|
||||
suite.txBuilder.SetFeeAmount(args.feeAmount)
|
||||
suite.txBuilder.SetGasLimit(args.gasLimit)
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func AssertError(t *testing.T, err, expectedErr error, expectedErrMsg string) {
|
||||
t.Helper()
|
||||
switch {
|
||||
case expectedErr != nil:
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
|
||||
@ -192,6 +192,7 @@ func TestBuilderWithAux(t *testing.T) {
|
||||
}
|
||||
|
||||
func makeTipperTxBuilder(t *testing.T) (clienttx.AuxTxBuilder, []byte) {
|
||||
t.Helper()
|
||||
tipperBuilder := clienttx.NewAuxTxBuilder()
|
||||
tipperBuilder.SetAddress(tipperAddr.String())
|
||||
tipperBuilder.SetAccountNumber(1)
|
||||
|
||||
@ -33,6 +33,7 @@ var (
|
||||
)
|
||||
|
||||
func buildTx(t *testing.T, bldr *wrapper) {
|
||||
t.Helper()
|
||||
bldr.SetFeeAmount(coins)
|
||||
bldr.SetGasLimit(gas)
|
||||
bldr.SetMemo(memo)
|
||||
|
||||
@ -40,7 +40,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {
|
||||
|
||||
exportGenesis := suite.bankKeeper.ExportGenesis(ctx)
|
||||
|
||||
suite.Require().Len(exportGenesis.Params.SendEnabled, 0) //nolint:staticcheck // SA1019: types.DefaultParams().SendEnabled is deprecated: Use DefaultSendEnabled instead. (staticcheck)
|
||||
suite.Require().Len(exportGenesis.Params.SendEnabled, 0) //nolint:staticcheck // we're testing the old way here
|
||||
suite.Require().Equal(types.DefaultParams().DefaultSendEnabled, exportGenesis.Params.DefaultSendEnabled)
|
||||
suite.Require().Equal(expTotalSupply, exportGenesis.Supply)
|
||||
suite.Require().Subset(exportGenesis.Balances, expectedBalances)
|
||||
|
||||
@ -1862,10 +1862,10 @@ func (suite *KeeperTestSuite) TestMigrator_Migrate3to4() {
|
||||
require.NoError(migrator.Migrate3to4(ctx))
|
||||
|
||||
newParams := bankKeeper.GetParams(ctx)
|
||||
require.Len(newParams.SendEnabled, 0) //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead.
|
||||
require.Len(newParams.SendEnabled, 0) //nolint:staticcheck // we're testing the old way here
|
||||
require.Equal(def, newParams.DefaultSendEnabled)
|
||||
|
||||
for _, se := range params.SendEnabled { //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead.
|
||||
for _, se := range params.SendEnabled {
|
||||
actual := bankKeeper.IsSendEnabledDenom(ctx, se.Denom)
|
||||
require.Equal(se.Enabled, actual, se.Denom)
|
||||
}
|
||||
@ -1878,7 +1878,7 @@ func (suite *KeeperTestSuite) TestSetParams() {
|
||||
require := suite.Require()
|
||||
|
||||
params := banktypes.NewParams(true)
|
||||
params.SendEnabled = []*banktypes.SendEnabled{ //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead.
|
||||
params.SendEnabled = []*banktypes.SendEnabled{
|
||||
{Denom: "paramscointrue", Enabled: true},
|
||||
{Denom: "paramscoinfalse", Enabled: false},
|
||||
}
|
||||
@ -1887,7 +1887,7 @@ func (suite *KeeperTestSuite) TestSetParams() {
|
||||
suite.Run("stored params are as expected", func() {
|
||||
actual := bankKeeper.GetParams(ctx)
|
||||
require.True(actual.DefaultSendEnabled, "DefaultSendEnabled")
|
||||
require.Len(actual.SendEnabled, 0, "SendEnabled") //nolint:staticcheck // SA1019: banktypes.Params.SendEnabled is deprecated: Use bankkeeper.IsSendEnabledDenom instead.
|
||||
require.Len(actual.SendEnabled, 0, "SendEnabled") //nolint:staticcheck // we're testing the old way here
|
||||
})
|
||||
|
||||
suite.Run("send enabled params converted to store", func() {
|
||||
|
||||
@ -105,8 +105,8 @@ func (k BaseSendKeeper) SetParams(ctx context.Context, params types.Params) erro
|
||||
// Normally SendEnabled is deprecated but we still support it for backwards
|
||||
// compatibility. Using params.Validate() would fail due to the SendEnabled
|
||||
// deprecation.
|
||||
if len(params.SendEnabled) > 0 { //nolint:staticcheck // SA1019: params.SendEnabled is deprecated
|
||||
k.SetAllSendEnabled(ctx, params.SendEnabled) //nolint:staticcheck // SA1019: params.SendEnabled is deprecated
|
||||
if len(params.SendEnabled) > 0 {
|
||||
k.SetAllSendEnabled(ctx, params.SendEnabled)
|
||||
|
||||
// override params without SendEnabled
|
||||
params = types.NewParams(params.DefaultSendEnabled)
|
||||
|
||||
@ -126,6 +126,7 @@ func TestMigrateDenomMetaData(t *testing.T) {
|
||||
}
|
||||
|
||||
func assertMetaDataEqual(t *testing.T, expected, actual types.Metadata) {
|
||||
t.Helper()
|
||||
require.Equal(t, expected.GetBase(), actual.GetBase())
|
||||
require.Equal(t, expected.GetDisplay(), actual.GetDisplay())
|
||||
require.Equal(t, expected.GetDescription(), actual.GetDescription())
|
||||
|
||||
@ -44,7 +44,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &bankGenesis)
|
||||
|
||||
assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled")
|
||||
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing deprecated code here
|
||||
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing the old way here
|
||||
if assert.Len(t, bankGenesis.Balances, 3) {
|
||||
assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].Address, "Balances[2] address")
|
||||
assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins")
|
||||
|
||||
@ -37,6 +37,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Assert(t, ok)
|
||||
|
||||
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
|
||||
assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing deprecated code here
|
||||
assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing the old way here
|
||||
assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled)
|
||||
}
|
||||
|
||||
@ -191,6 +191,7 @@ func BenchmarkSanitizeBalances1000(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkSanitizeBalances(b *testing.B, nAddresses int) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction)
|
||||
coin := sdk.NewCoin("benchcoin", tokens)
|
||||
|
||||
@ -39,6 +39,7 @@ func (m MockCircuitBreaker) IsAllowed(ctx context.Context, typeURL string) (bool
|
||||
}
|
||||
|
||||
func initFixture(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
mockStoreKey := storetypes.NewKVStoreKey("test")
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{})
|
||||
mockclientCtx := client.Context{}.
|
||||
|
||||
@ -39,6 +39,7 @@ type fixture struct {
|
||||
}
|
||||
|
||||
func initFixture(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{})
|
||||
ac := addresscodec.NewBech32Codec("cosmos")
|
||||
mockStoreKey := storetypes.NewKVStoreKey("test")
|
||||
|
||||
@ -39,6 +39,7 @@ type genesisFixture struct {
|
||||
}
|
||||
|
||||
func initFixture(t *testing.T) *genesisFixture {
|
||||
t.Helper()
|
||||
key := storetypes.NewKVStoreKey(feegrant.StoreKey)
|
||||
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{})
|
||||
|
||||
@ -602,6 +602,7 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) {
|
||||
}
|
||||
|
||||
func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) {
|
||||
t.Helper()
|
||||
require.True(t, len(addrs) <= len(pubkeys), "Not enough pubkeys specified at top of file.")
|
||||
|
||||
for i := 0; i < len(addrs); i++ {
|
||||
@ -629,6 +630,7 @@ func getDepositMultiplier(expedited bool) int64 {
|
||||
}
|
||||
|
||||
func checkActiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper, invalid bool) {
|
||||
t.Helper()
|
||||
err := k.ActiveProposalsQueue.Walk(ctx, collections.NewPrefixUntilPairRange[time.Time, uint64](ctx.BlockTime()), func(key collections.Pair[time.Time, uint64], value uint64) (stop bool, err error) {
|
||||
return false, err
|
||||
})
|
||||
@ -640,6 +642,7 @@ func checkActiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper,
|
||||
}
|
||||
|
||||
func checkInactiveProposalsQueue(t *testing.T, ctx sdk.Context, k *keeper.Keeper, invalid bool) {
|
||||
t.Helper()
|
||||
err := k.InactiveProposalsQueue.Walk(ctx, collections.NewPrefixUntilPairRange[time.Time, uint64](ctx.BlockTime()), func(key collections.Pair[time.Time, uint64], value uint64) (stop bool, err error) {
|
||||
return false, err
|
||||
})
|
||||
|
||||
@ -214,6 +214,7 @@ func TestParseSubmitProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
func getCommandHelp(t *testing.T, cmd *cobra.Command) string {
|
||||
t.Helper()
|
||||
// Create a pipe, so we can capture the help sent to stdout.
|
||||
reader, writer, err := os.Pipe()
|
||||
require.NoError(t, err, "creating os.Pipe()")
|
||||
|
||||
@ -45,6 +45,7 @@ var (
|
||||
|
||||
// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes.
|
||||
func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent {
|
||||
t.Helper()
|
||||
msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String())
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -113,6 +114,7 @@ type suite struct {
|
||||
}
|
||||
|
||||
func createTestSuite(t *testing.T) suite {
|
||||
t.Helper()
|
||||
res := suite{}
|
||||
|
||||
app, err := simtestutil.SetupWithConfiguration(
|
||||
|
||||
@ -64,6 +64,7 @@ func setupGovKeeper(t *testing.T) (
|
||||
moduletestutil.TestEncodingConfig,
|
||||
sdk.Context,
|
||||
) {
|
||||
t.Helper()
|
||||
key := storetypes.NewKVStoreKey(types.StoreKey)
|
||||
storeService := runtime.NewKVStoreService(key)
|
||||
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
|
||||
@ -76,6 +76,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
}
|
||||
|
||||
func compareProps(t *testing.T, oldProp v1beta1.Proposal, newProp v1.Proposal) {
|
||||
t.Helper()
|
||||
require.Equal(t, oldProp.ProposalId, newProp.Id)
|
||||
require.Equal(t, oldProp.TotalDeposit.String(), sdk.Coins(newProp.TotalDeposit).String())
|
||||
require.Equal(t, oldProp.Status.String(), newProp.Status.String())
|
||||
|
||||
@ -405,6 +405,7 @@ type suite struct {
|
||||
|
||||
// returns context and an app with updated mint keeper
|
||||
func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) {
|
||||
t.Helper()
|
||||
res := suite{}
|
||||
|
||||
app, err := simtestutil.Setup(
|
||||
@ -435,6 +436,7 @@ func getTestingAccounts(
|
||||
accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper,
|
||||
ctx sdk.Context, n int,
|
||||
) []simtypes.Account {
|
||||
t.Helper()
|
||||
accounts := simtypes.RandomAccounts(r, n)
|
||||
|
||||
initAmt := stakingKeeper.TokensFromConsensusPower(ctx, 200)
|
||||
|
||||
@ -396,6 +396,7 @@ func TestExportImportStatePrimaryKeyTable(t *testing.T) {
|
||||
}
|
||||
|
||||
func assertIndex(t *testing.T, store storetypes.KVStore, index Index, v testdata.TableModel, searchKey interface{}) {
|
||||
t.Helper()
|
||||
it, err := index.Get(store, searchKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -407,6 +408,7 @@ func assertIndex(t *testing.T, store storetypes.KVStore, index Index, v testdata
|
||||
}
|
||||
|
||||
func first(t *testing.T, it Iterator) ([]byte, testdata.TableModel) {
|
||||
t.Helper()
|
||||
var loaded testdata.TableModel
|
||||
key, err := First(it, &loaded)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func initKeeper(t *testing.T) (types.Context, groupkeeper.Keeper, []types.AccAddress, group.QueryClient) {
|
||||
t.Helper()
|
||||
var (
|
||||
groupKeeper groupkeeper.Keeper
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
|
||||
@ -85,6 +85,7 @@ func updateValidators(
|
||||
updates []abci.ValidatorUpdate,
|
||||
event func(route, op, evResult string),
|
||||
) map[string]mockValidator {
|
||||
tb.Helper()
|
||||
for _, update := range updates {
|
||||
str := fmt.Sprintf("%X", update.PubKey.GetEd25519())
|
||||
|
||||
|
||||
@ -65,6 +65,7 @@ func SimulateFromSeed(
|
||||
config simulation.Config,
|
||||
cdc codec.JSONCodec,
|
||||
) (stopEarly bool, exportedParams Params, err error) {
|
||||
tb.Helper()
|
||||
// in case we have to end early, don't os.Exit so that we can run cleanup code.
|
||||
testingMode, _, b := getTestingMode(tb)
|
||||
|
||||
@ -142,8 +143,8 @@ func SimulateFromSeed(
|
||||
logWriter := NewLogWriter(testingMode)
|
||||
|
||||
blockSimulator := createBlockSimulator(
|
||||
testingMode,
|
||||
tb,
|
||||
testingMode,
|
||||
w,
|
||||
params,
|
||||
eventStats.Tally,
|
||||
@ -193,13 +194,13 @@ func SimulateFromSeed(
|
||||
|
||||
// run queued operations; ignores block size if block size is too small
|
||||
numQueuedOpsRan, futureOps := runQueuedOperations(
|
||||
operationQueue, int(blockHeight), tb, r, app, ctx, accs, logWriter,
|
||||
tb, operationQueue, int(blockHeight), r, app, ctx, accs, logWriter,
|
||||
eventStats.Tally, config.Lean, config.ChainID,
|
||||
)
|
||||
|
||||
numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations(
|
||||
numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations(tb,
|
||||
timeOperationQueue, int(blockHeight), blockTime,
|
||||
tb, r, app, ctx, accs, logWriter, eventStats.Tally,
|
||||
r, app, ctx, accs, logWriter, eventStats.Tally,
|
||||
config.Lean, config.ChainID,
|
||||
)
|
||||
|
||||
@ -285,11 +286,12 @@ type blockSimFn func(
|
||||
|
||||
// Returns a function to simulate blocks. Written like this to avoid constant
|
||||
// parameters being passed everytime, to minimize memory overhead.
|
||||
func createBlockSimulator(testingMode bool, tb testing.TB, w io.Writer, params Params,
|
||||
func createBlockSimulator(tb testing.TB, testingMode bool, w io.Writer, params Params,
|
||||
event func(route, op, evResult string), ops WeightedOperations,
|
||||
operationQueue OperationQueue, timeOperationQueue []simulation.FutureOperation,
|
||||
logWriter LogWriter, config simulation.Config,
|
||||
) blockSimFn {
|
||||
tb.Helper()
|
||||
lastBlockSizeState := 0 // state for [4 * uniform distribution]
|
||||
blocksize := 0
|
||||
selectOp := ops.getSelectOpFn()
|
||||
@ -352,11 +354,12 @@ Comment: %s`,
|
||||
}
|
||||
}
|
||||
|
||||
func runQueuedOperations(queueOps map[int][]simulation.Operation,
|
||||
height int, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp,
|
||||
func runQueuedOperations(tb testing.TB, queueOps map[int][]simulation.Operation,
|
||||
height int, r *rand.Rand, app *baseapp.BaseApp,
|
||||
ctx sdk.Context, accounts []simulation.Account, logWriter LogWriter,
|
||||
event func(route, op, evResult string), lean bool, chainID string,
|
||||
) (numOpsRan int, allFutureOps []simulation.FutureOperation) {
|
||||
tb.Helper()
|
||||
queuedOp, ok := queueOps[height]
|
||||
if !ok {
|
||||
return 0, nil
|
||||
@ -388,12 +391,13 @@ func runQueuedOperations(queueOps map[int][]simulation.Operation,
|
||||
return numOpsRan, allFutureOps
|
||||
}
|
||||
|
||||
func runQueuedTimeOperations(queueOps []simulation.FutureOperation,
|
||||
height int, currentTime time.Time, tb testing.TB, r *rand.Rand,
|
||||
func runQueuedTimeOperations(tb testing.TB, queueOps []simulation.FutureOperation,
|
||||
height int, currentTime time.Time, r *rand.Rand,
|
||||
app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account,
|
||||
logWriter LogWriter, event func(route, op, evResult string),
|
||||
lean bool, chainID string,
|
||||
) (numOpsRan int, allFutureOps []simulation.FutureOperation) {
|
||||
tb.Helper()
|
||||
// Keep all future operations
|
||||
allFutureOps = make([]simulation.FutureOperation, 0)
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) {
|
||||
tb.Helper()
|
||||
testingMode = false
|
||||
|
||||
if _t, ok := tb.(*testing.T); ok {
|
||||
|
||||
@ -25,6 +25,7 @@ func BenchmarkValidateGenesis400Validators(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkValidateGenesis(b *testing.B, n int) {
|
||||
b.Helper()
|
||||
b.ReportAllocs()
|
||||
|
||||
validators := make([]types.Validator, 0, n)
|
||||
|
||||
@ -99,6 +99,7 @@ func TestMigrate(t *testing.T) {
|
||||
// createOldStateUnbonding will create the ubd entries with duplicate heights
|
||||
// 10 duplicate heights and 10 unique ubd with creation height
|
||||
func createOldStateUnbonding(t *testing.T, creationHeight int64, valAddr sdk.ValAddress, accAddr sdk.AccAddress, cdc codec.BinaryCodec, store storetypes.KVStore) error {
|
||||
t.Helper()
|
||||
unbondBalance := math.NewInt(100)
|
||||
completionTime := time.Now()
|
||||
ubdEntries := make([]types.UnbondingDelegationEntry, 0, 10)
|
||||
@ -131,6 +132,7 @@ func createOldStateUnbonding(t *testing.T, creationHeight int64, valAddr sdk.Val
|
||||
}
|
||||
|
||||
func getUBD(t *testing.T, accAddr sdk.AccAddress, valAddr sdk.ValAddress, store storetypes.KVStore, cdc codec.BinaryCodec) types.UnbondingDelegation {
|
||||
t.Helper()
|
||||
// get the unbonding delegations
|
||||
var ubdRes types.UnbondingDelegation
|
||||
ubdbz := store.Get(getUBDKey(accAddr, valAddr))
|
||||
|
||||
@ -30,6 +30,7 @@ type Helper struct {
|
||||
|
||||
// NewHelper creates a new instance of Helper.
|
||||
func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper {
|
||||
t.Helper()
|
||||
return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user