Add cli test for slashing (#6102)

Reference: #5951
This commit is contained in:
SaReN 2020-05-05 19:21:35 +05:30 committed by GitHub
parent 4a28dd1645
commit 7e72e5b8a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 1 deletions

View File

@ -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)),

View File

@ -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) {

View File

@ -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()
}

View File

@ -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
}

View File

@ -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()
}

View File

@ -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
}