Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing cli tests for staking module #6347

Merged
merged 24 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eb36d6b
edit validator flags issue fixed
atheeshp Jun 2, 2020
d2a1848
added remaining tests
atheeshp Jun 2, 2020
def6796
fixed example command
atheeshp Jun 3, 2020
0fa68ca
fixed redelegation query in tests
atheeshp Jun 3, 2020
9a3d129
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 8, 2020
d09c4c9
changed all "require" conditions to relevant type
atheeshp Jun 8, 2020
99d16e1
added err condition at query execution
atheeshp Jun 8, 2020
1edadfb
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 9, 2020
3b9d756
Added consoles for err msgs
atheeshp Jun 9, 2020
b4d921e
added comments
atheeshp Jun 9, 2020
6606813
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 10, 2020
98064dd
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 11, 2020
ee28e4a
fixed bug in query.go
atheeshp Jun 11, 2020
b3f2679
updated helpers, cli_test
atheeshp Jun 11, 2020
9237270
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 11, 2020
676bb29
updated docs
atheeshp Jun 11, 2020
4e93610
Merge branch 'master' into atheesh/missing-staking-cli-tests
anilcse Jun 11, 2020
07e928d
Merge branch 'master' into atheesh/missing-staking-cli-tests
fedekunze Jun 12, 2020
103a6ac
Update x/staking/client/cli/cli_test.go
Jun 12, 2020
05ebbbf
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/mi…
atheeshp Jun 12, 2020
a0ac44c
fixed type errors
atheeshp Jun 12, 2020
240dca4
removed TODO comment
atheeshp Jun 12, 2020
c9273ac
updated docs
atheeshp Jun 12, 2020
b5a8ea3
Merge branch 'master' into atheesh/missing-staking-cli-tests
fedekunze Jun 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 113 additions & 6 deletions x/staking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func TestCLICreateValidator(t *testing.T) {
barAddr := f.KeyAddress(cli.KeyBar)
barVal := sdk.ValAddress(barAddr)

// Check for the params
params := testutil.QueryStakingParameters(f)
require.NotEmpty(t, params)

// Query for the staking pool
pool := testutil.QueryStakingPool(f)
require.NotEmpty(t, pool)

consPubKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, ed25519.GenPrivKey().PubKey())

sendTokens := sdk.TokensFromConsensusPower(10)
Expand All @@ -34,15 +42,15 @@ func TestCLICreateValidator(t *testing.T) {

require.Equal(t, sendTokens, bankclienttestutil.QueryBalances(f, barAddr).AmountOf(cli.Denom))

//Generate a create validator transaction and ensure correctness
// Generate a create validator transaction and ensure correctness
success, stdout, stderr := testutil.TxStakingCreateValidator(f, barAddr.String(), consPubKey, sdk.NewInt64Coin(cli.Denom, 2), "--generate-only")
require.True(f.T, success)
require.Empty(f.T, stderr)
require.True(t, success)
require.Empty(t, stderr)

msg := cli.UnmarshalStdTx(f.T, f.Cdc, stdout)
msg := cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

// Test --dry-run
newValTokens := sdk.TokensFromConsensusPower(2)
Expand All @@ -66,7 +74,38 @@ func TestCLICreateValidator(t *testing.T) {
require.Len(t, validatorDelegations, 1)
require.NotZero(t, validatorDelegations[0].Shares)

// Edit validator
// params to be changed in edit validator (NOTE: a validator can only change its commission once per day)
newMoniker := "test-moniker"
newWebsite := "https://cosmos.network"
newIdentity := "6A0D65E29A4CBC8D"
newDetails := "To-infinity-and-beyond!"

// Test --generate-only"
success, stdout, stderr = testutil.TxStakingEditValidator(f, barAddr.String(), newMoniker, newWebsite, newIdentity, newDetails, "--generate-only")
require.True(t, success)
require.True(t, success)
require.Empty(t, stderr)

msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

success, _, _ = testutil.TxStakingEditValidator(f, cli.KeyBar, newMoniker, newWebsite, newIdentity, newDetails, "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)

udpatedValidator := testutil.QueryStakingValidator(f, barVal)
require.Equal(t, udpatedValidator.Description.Moniker, newMoniker)
require.Equal(t, udpatedValidator.Description.Identity, newIdentity)
require.Equal(t, udpatedValidator.Description.Website, newWebsite)
require.Equal(t, udpatedValidator.Description.Details, newDetails)

// unbond a single share
validators := testutil.QueryStakingValidators(f)
require.Len(t, validators, 2)

unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1))
success = testutil.TxStakingUnbond(f, cli.KeyBar, unbondAmt.String(), barVal, "-y")
require.True(t, success)
Expand All @@ -77,11 +116,79 @@ func TestCLICreateValidator(t *testing.T) {
validator = testutil.QueryStakingValidator(f, barVal)
require.Equal(t, remainingTokens, validator.Tokens)

// Query for historical info
historicalInfo := testutil.QueryStakingHistoricalInfo(f, 1)
require.NotEmpty(t, historicalInfo)
alessio marked this conversation as resolved.
Show resolved Hide resolved

// Get unbonding delegations from the validator
validatorUbds := testutil.QueryStakingUnbondingDelegationsFrom(f, barVal)
require.Len(t, validatorUbds, 1)
require.Len(t, validatorUbds[0].Entries, 1)
require.Equal(t, remainingTokens.String(), validatorUbds[0].Entries[0].Balance.String())

// Query staking unbonding delegation
ubd := testutil.QueryStakingUnbondingDelegation(f, barAddr.String(), barVal.String())
require.NotEmpty(t, ubd)

// Query staking unbonding delegations
ubds := testutil.QueryStakingUnbondingDelegations(f, barAddr.String())
require.Len(t, ubds, 1)

fooAddr := f.KeyAddress(cli.KeyFoo)

delegateTokens := sdk.TokensFromConsensusPower(2)
delegateAmount := sdk.NewCoin(cli.Denom, delegateTokens)

// Delegate txn
// Generate a create validator transaction and ensure correctness
success, stdout, stderr = testutil.TxStakingDelegate(f, fooAddr.String(), barVal.String(), delegateAmount, "--generate-only")
require.True(t, success)
require.Empty(t, stderr)

msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

// Delegate
success, _, err := testutil.TxStakingDelegate(f, cli.KeyFoo, barVal.String(), delegateAmount, "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
require.Empty(t, err)
require.True(t, success)

// Query the delegation from foo address to barval
delegation := testutil.QueryStakingDelegation(f, fooAddr.String(), barVal)
require.NotZero(t, delegation.Shares)

// Query the delegations from foo address to barval
delegations := testutil.QueryStakingDelegations(f, barAddr.String())
require.Len(t, delegations, 1)

fooVal := sdk.ValAddress(fooAddr)

// Redelegate
success, stdout, stderr = testutil.TxStakingRedelegate(f, fooAddr.String(), barVal.String(), fooVal.String(), delegateAmount, "--generate-only")
require.True(t, success)
require.Empty(t, stderr)

msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

success, _, err = testutil.TxStakingRedelegate(f, cli.KeyFoo, barVal.String(), fooVal.String(), delegateAmount, "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
require.Empty(t, err)
require.True(t, success)

redelegation := testutil.QueryStakingRedelegation(f, fooAddr.String(), barVal.String(), fooVal.String())
require.Len(t, redelegation, 1)

redelegations := testutil.QueryStakingRedelegations(f, fooAddr.String())
require.Len(t, redelegations, 1)

redelegationsFrom := testutil.QueryStakingRedelegationsFrom(f, barVal.String())
require.Len(t, redelegationsFrom, 1)

f.Cleanup()
}
6 changes: 3 additions & 3 deletions x/staking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7
return err
}

ubd, err := types.UnmarshalUBD(types.ModuleCdc, res)
if err != nil {
var ubd types.UnbondingDelegation
if err = cdc.UnmarshalJSON(res, &ubd); err != nil {
return err
}

Expand All @@ -419,7 +419,7 @@ func GetCmdQueryUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra
fmt.Sprintf(`Query unbonding delegations for an individual delegator.

Example:
$ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
$ %s query staking unbonding-delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
`,
version.ClientName,
),
Expand Down
7 changes: 4 additions & 3 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command {
},
}

cmd.Flags().AddFlagSet(fsDescriptionEdit)
cmd.Flags().AddFlagSet(fsCommissionUpdate)
cmd.Flags().AddFlagSet(FsMinSelfDelegation)

return cmd
}

Expand Down Expand Up @@ -175,9 +179,6 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
cmd.Flags().AddFlagSet(fsDescriptionEdit)
cmd.Flags().AddFlagSet(fsCommissionUpdate)
cmd.Flags().AddFlagSet(FsMinSelfDelegation)

return cmd
}
Expand Down
Loading