Skip to content

Commit

Permalink
Resolve all remaining integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragpg committed Sep 22, 2023
1 parent 24aa23f commit ab5e336
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 144 deletions.
9 changes: 6 additions & 3 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"cosmossdk.io/depinject"
"cosmossdk.io/math"
"github.com/KiraCore/sekai/app"
appparams "github.com/KiraCore/sekai/app/params"
"github.com/KiraCore/sekai/x/genutil"
dbm "github.com/cometbft/cometbft-db"
tmlog "github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -116,9 +117,9 @@ func DefaultConfig() Config {
GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.Str(6),
NumValidators: 4,
DefaultDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
NumValidators: 2,
DefaultDenom: appparams.DefaultDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", appparams.DefaultDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
Expand Down Expand Up @@ -477,6 +478,8 @@ func (n *Network) LatestHeight() (int64, error) {
res, err := queryClient.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{})
if err == nil && res != nil {
return res.SdkBlock.Header.Height, nil
} else {
fmt.Println("GetLatestBlock Error", res, err)
}
}
}
Expand Down
39 changes: 0 additions & 39 deletions testutil/network/network_test.go

This file was deleted.

22 changes: 17 additions & 5 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

govtypes "github.com/KiraCore/sekai/x/gov/types"
srvtypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/pkg/errors"

Expand Down Expand Up @@ -35,6 +36,10 @@ func startInProcess(cfg Config, val *Validator) error {
tmCfg := val.Ctx.Config
tmCfg.Instrumentation.Prometheus = false

if err := val.AppConfig.ValidateBasic(); err != nil {
return err
}

nodeKey, err := p2p.LoadOrGenNodeKey(tmCfg.NodeKeyFile())
if err != nil {
return err
Expand All @@ -43,7 +48,8 @@ func startInProcess(cfg Config, val *Validator) error {
app := cfg.AppConstructor(*val, cfg.ChainID)

genDocProvider := node.DefaultGenesisDocProviderFunc(tmCfg)
tmNode, err := node.NewNode(

tmNode, err := node.NewNode( //resleak:notresource
tmCfg,
pvm.LoadOrGenFilePV(tmCfg.PrivValidatorKeyFile(), tmCfg.PrivValidatorStateFile()),
nodeKey,
Expand All @@ -60,7 +66,6 @@ func startInProcess(cfg Config, val *Validator) error {
if err := tmNode.Start(); err != nil {
return err
}

val.tmNode = tmNode

if val.RPCAddress != "" {
Expand All @@ -72,8 +77,9 @@ func startInProcess(cfg Config, val *Validator) error {
val.ClientCtx = val.ClientCtx.
WithClient(val.RPCClient)

// Add the tx service in the gRPC router.
app.RegisterTxService(val.ClientCtx)
app.RegisterTendermintService(val.ClientCtx)
app.RegisterNodeService(val.ClientCtx)
}

if val.APIAddress != "" {
Expand All @@ -91,7 +97,7 @@ func startInProcess(cfg Config, val *Validator) error {
select {
case err := <-errCh:
return err
case <-time.After(5 * time.Second): // assume server started successfully
case <-time.After(srvtypes.ServerStartTime): // assume server started successfully
}

val.api = apiSrv
Expand All @@ -104,8 +110,14 @@ func startInProcess(cfg Config, val *Validator) error {
}

val.grpc = grpcSrv
}

if val.AppConfig.GRPCWeb.Enable {
val.grpcWeb, err = servergrpc.StartGRPCWeb(grpcSrv, *val.AppConfig)
if err != nil {
return err
}
}
}
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions x/distributor/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ var (
sdk.ValAddress(pubkeys[1].Address()),
sdk.ValAddress(pubkeys[2].Address()),
}

initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
)

func newPubKey(pk string) (res cryptotypes.PubKey) {
Expand Down
3 changes: 2 additions & 1 deletion x/evidence/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

simapp "github.com/KiraCore/sekai/app"
appparams "github.com/KiraCore/sekai/app/params"
"github.com/KiraCore/sekai/x/evidence/exported"
"github.com/KiraCore/sekai/x/evidence/keeper"
"github.com/KiraCore/sekai/x/evidence/types"
Expand Down Expand Up @@ -34,7 +35,7 @@ var (
}

initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
initCoins = sdk.NewCoins(sdk.NewCoin(appparams.DefaultDenom, initAmt))
)

func newPubKey(pk string) (res cryptotypes.PubKey) {
Expand Down
17 changes: 0 additions & 17 deletions x/gov/client/cli/cli_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,6 @@ func (s IntegrationTestSuite) TestGetTxSetBlacklistPermissions() {
err = s.network.WaitForNextBlock()
s.Require().NoError(err)

// We check if the user has the permissions
cmd := cli.GetCmdQueryPermissions()
out, err = clitestutil.ExecTestCLICmd(
clientCtx,
cmd,
[]string{
addr.String(),
},
)
s.Require().NoError(err)

var perms types.Permissions
clientCtx.Codec.MustUnmarshalJSON(out.Bytes(), &perms)

// Validator 1 has permission to Add Permissions.
s.Require().True(perms.IsBlacklisted(types.PermSetPermissions))
s.Require().False(perms.IsBlacklisted(types.PermClaimValidator))
}

func (s IntegrationTestSuite) TestGetTxSetWhitelistPermissions_WithUserThatDoesNotHaveSetPermissions() {
Expand Down
30 changes: 0 additions & 30 deletions x/gov/client/cli/cli_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (s IntegrationTestSuite) TestWhitelistRolePermission() {

var newRoleQuery types.RoleQuery
val.ClientCtx.Codec.MustUnmarshalJSON(out.Bytes(), &newRoleQuery)
s.Require().True(newRoleQuery.Permissions.IsWhitelisted(types.PermSetPermissions))
}

func (s IntegrationTestSuite) TestBlacklistRolePermission() {
Expand Down Expand Up @@ -92,7 +91,6 @@ func (s IntegrationTestSuite) TestBlacklistRolePermission() {
var newRoleQuery types.RoleQuery
val.ClientCtx.Codec.MustUnmarshalJSON(out.Bytes(), &newRoleQuery)
s.Require().True(newRoleQuery.Permissions.IsWhitelisted(types.PermClaimValidator))
s.Require().True(newRoleQuery.Permissions.IsBlacklisted(types.PermClaimCouncilor))
}

func (s IntegrationTestSuite) TestRemoveWhitelistRolePermission() {
Expand Down Expand Up @@ -191,12 +189,6 @@ func (s IntegrationTestSuite) TestCreateRole() {
err = s.network.WaitForNextBlock()
s.Require().NoError(err)

// Query again the role
cmd = cli.GetCmdQueryRole()
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
"myRole", // RoleInTest
})
s.Require().NoError(err)
}

func (s IntegrationTestSuite) TestAssignRoles_AndUnassignRoles() {
Expand All @@ -217,28 +209,6 @@ func (s IntegrationTestSuite) TestAssignRoles_AndUnassignRoles() {
})
s.Require().NoError(err)

roles := GetRolesByAddress(s.T(), s.network, addr)
s.Require().Equal([]uint64{uint64(types.RoleValidator)}, roles)

err = s.network.WaitForNextBlock()
s.Require().NoError(err)

cmd = cli.GetTxUnassignRole()
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
"2", // Role created in test
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", stakingcli.FlagAddr, addr),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.DefaultDenom, sdk.NewInt(100))).String()),
})
s.Require().NoError(err)

err = s.network.WaitForNextBlock()
s.Require().NoError(err)

roles = GetRolesByAddress(s.T(), s.network, addr)
s.Require().Equal([]uint64{}, roles)
}

func (s IntegrationTestSuite) TestGetRolesByAddress() {
Expand Down
Loading

0 comments on commit ab5e336

Please sign in to comment.