test: migrate remaining e2e tests to integration tests (#22364)
Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
co-authored by
Julien Robert
Marko
parent
fc5536a641
commit
e37d71ad24
@@ -0,0 +1,46 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
authTest "github.com/cosmos/cosmos-sdk/tests/integration/auth/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
func TestAccountRetriever(t *testing.T) {
|
||||
cfg, err := network.DefaultConfigWithAppConfig(authTest.AppConfig)
|
||||
require.NoError(t, err)
|
||||
cfg.NumValidators = 1
|
||||
|
||||
network, err := network.New(t, t.TempDir(), cfg)
|
||||
require.NoError(t, err)
|
||||
defer network.Cleanup()
|
||||
|
||||
_, err = network.WaitForHeight(3)
|
||||
require.NoError(t, err)
|
||||
|
||||
val := network.GetValidators()[0]
|
||||
clientCtx := val.GetClientCtx()
|
||||
ar := types.AccountRetriever{}
|
||||
|
||||
clientCtx = clientCtx.WithHeight(2)
|
||||
|
||||
acc, err := ar.GetAccount(clientCtx, val.GetAddress())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, acc)
|
||||
|
||||
acc, height, err := ar.GetAccountWithHeight(clientCtx, val.GetAddress())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, acc)
|
||||
require.Equal(t, height, int64(2))
|
||||
|
||||
require.NoError(t, ar.EnsureExists(clientCtx, val.GetAddress()))
|
||||
|
||||
accNum, accSeq, err := ar.GetAccountNumberSequence(clientCtx, val.GetAddress())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, accNum, uint64(0))
|
||||
require.Equal(t, accSeq, uint64(1))
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
_ "cosmossdk.io/x/accounts" // import as blank for app wiring
|
||||
_ "cosmossdk.io/x/bank" // import as blank for app wiring
|
||||
_ "cosmossdk.io/x/consensus" // import as blank for app wiring
|
||||
_ "cosmossdk.io/x/staking" // import as blank for app wiring
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring``
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring
|
||||
_ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring
|
||||
)
|
||||
|
||||
var AppConfig = configurator.NewAppConfig(
|
||||
configurator.AccountsModule(),
|
||||
configurator.AuthModule(),
|
||||
configurator.BankModule(),
|
||||
configurator.VestingModule(),
|
||||
configurator.StakingModule(),
|
||||
configurator.TxModule(),
|
||||
configurator.ValidateModule(),
|
||||
configurator.ConsensusModule(),
|
||||
configurator.GenutilModule(),
|
||||
)
|
||||
@@ -0,0 +1,67 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
authTest "github.com/cosmos/cosmos-sdk/tests/integration/auth/keeper"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
)
|
||||
|
||||
func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
var accountKeeper keeper.AccountKeeper
|
||||
app, err := simtestutil.Setup(
|
||||
depinject.Configs(
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
authTest.AppConfig,
|
||||
),
|
||||
&accountKeeper,
|
||||
)
|
||||
require.NoError(b, err)
|
||||
|
||||
ctx := app.BaseApp.NewContext(false)
|
||||
|
||||
// assumes b.N < 2**24
|
||||
for i := 0; i < b.N; i++ {
|
||||
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
|
||||
addr := sdk.AccAddress(arr)
|
||||
acc := accountKeeper.NewAccountWithAddress(ctx, addr)
|
||||
accountKeeper.SetAccount(ctx, acc)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
|
||||
accountKeeper.GetAccount(ctx, sdk.AccAddress(arr))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAccountMapperSetAccount(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
var accountKeeper keeper.AccountKeeper
|
||||
app, err := simtestutil.Setup(
|
||||
depinject.Configs(
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
authTest.AppConfig,
|
||||
), &accountKeeper)
|
||||
require.NoError(b, err)
|
||||
|
||||
ctx := app.BaseApp.NewContext(false)
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
// assumes b.N < 2**24
|
||||
for i := 0; i < b.N; i++ {
|
||||
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
|
||||
addr := sdk.AccAddress(arr)
|
||||
acc := accountKeeper.NewAccountWithAddress(ctx, addr)
|
||||
accountKeeper.SetAccount(ctx, acc)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
authTest "github.com/cosmos/cosmos-sdk/tests/integration/auth/keeper"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
|
||||
var accountKeeper keeper.AccountKeeper
|
||||
app, err := simtestutil.SetupAtGenesis(
|
||||
depinject.Configs(
|
||||
authTest.AppConfig,
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
),
|
||||
&accountKeeper)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := app.BaseApp.NewContext(false)
|
||||
acc := accountKeeper.GetAccount(ctx, types.NewModuleAddress(types.FeeCollectorName))
|
||||
require.NotNil(t, acc)
|
||||
}
|
||||
Reference in New Issue
Block a user