Skip to content

Commit

Permalink
Add cli test for slashing (#6102)
Browse files Browse the repository at this point in the history
Reference: #5951
  • Loading branch information
sahith-narahari authored May 5, 2020
1 parent 4a28dd1 commit 7e72e5b
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import (
)

var (
TotalCoins = sdk.NewCoins(
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(FooDenom, sdk.TokensFromConsensusPower(2000)),
sdk.NewCoin(Denom, sdk.TokensFromConsensusPower(300).Add(sdk.NewInt(12))), // add coins from inflation
)

StartCoins = sdk.NewCoins(
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(1000000)),
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(1000000)),
Expand Down
3 changes: 2 additions & 1 deletion tests/cli/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/tests/cli"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/tests/cli"
)

func TestCLIKeysAddMultisig(t *testing.T) {
Expand Down
17 changes: 17 additions & 0 deletions x/bank/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,20 @@ func TestCLIFeesDeduction(t *testing.T) {

f.Cleanup()
}

func TestCLIQuerySupply(t *testing.T) {
t.Parallel()
f := cli.InitFixtures(t)

// start simd server
proc := f.SDStart()
defer proc.Stop(false)

totalSupply := testutil.QueryTotalSupply(f)
totalSupplyOf := testutil.QueryTotalSupplyOf(f, cli.FooDenom)

require.Equal(t, cli.TotalCoins, totalSupply)
require.True(sdk.IntEq(t, cli.TotalCoins.AmountOf(cli.FooDenom), totalSupplyOf))

f.Cleanup()
}
23 changes: 23 additions & 0 deletions x/bank/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,26 @@ func QueryBalances(f *cli.Fixtures, address sdk.AccAddress, flags ...string) sdk

return balances
}

// QueryTotalSupply returns the total supply of coins
func QueryTotalSupply(f *cli.Fixtures, flags ...string) (totalSupply sdk.Coins) {
cmd := fmt.Sprintf("%s query bank total %s", f.SimcliBinary, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)

err := f.Cdc.UnmarshalJSON([]byte(res), &totalSupply)
require.NoError(f.T, err)
return totalSupply
}

// QueryTotalSupplyOf returns the total supply of a given coin denom
func QueryTotalSupplyOf(f *cli.Fixtures, denom string, flags ...string) sdk.Int {
cmd := fmt.Sprintf("%s query bank total %s %s", f.SimcliBinary, denom, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)

var supplyOf sdk.Int
err := f.Cdc.UnmarshalJSON([]byte(res), &supplyOf)
require.NoError(f.T, err)
return supplyOf
}
33 changes: 33 additions & 0 deletions x/slashing/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// +build cli_test

package cli_test

import (
"github.com/cosmos/cosmos-sdk/x/slashing/client/testutil"
"testing"

"github.com/stretchr/testify/require"

cli "github.com/cosmos/cosmos-sdk/tests/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestCLISlashingGetParams(t *testing.T) {
t.Parallel()
f := cli.InitFixtures(t)

// start simd server
proc := f.SDStart()
defer proc.Stop(false)

params := testutil.QuerySlashingParams(f)
require.Equal(t, int64(100), params.SignedBlocksWindow)
require.Equal(t, sdk.NewDecWithPrec(5, 1), params.MinSignedPerWindow)

sinfo := testutil.QuerySigningInfo(f, f.SDTendermint("show-validator"))
require.Equal(t, int64(0), sinfo.StartHeight)
require.False(t, sinfo.Tombstoned)

// Cleanup testing directories
f.Cleanup()
}
33 changes: 33 additions & 0 deletions x/slashing/client/testutil/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package testutil

import (
"fmt"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/tests/cli"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/stretchr/testify/require"
)

// QuerySigningInfo returns the signing info for a validator
func QuerySigningInfo(f *cli.Fixtures, val string) slashing.ValidatorSigningInfo {
cmd := fmt.Sprintf("%s query slashing signing-info %s %s", f.SimcliBinary, val, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)

var sinfo slashing.ValidatorSigningInfo
err := f.Cdc.UnmarshalJSON([]byte(res), &sinfo)
require.NoError(f.T, err)
return sinfo
}

// QuerySlashingParams returns query slashing params
func QuerySlashingParams(f *cli.Fixtures) slashing.Params {
cmd := fmt.Sprintf("%s query slashing params %s", f.SimcliBinary, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)

var params slashing.Params
err := f.Cdc.UnmarshalJSON([]byte(res), &params)
require.NoError(f.T, err)
return params
}

0 comments on commit 7e72e5b

Please sign in to comment.