get rid of candidacy references

This commit is contained in:
rigelrozanski 2018-05-31 12:22:46 -07:00
parent afc2bbfe09
commit 952aedc4f1
15 changed files with 96 additions and 96 deletions

View File

@ -100,7 +100,7 @@ FEATURES
* [gaiacli] Support queries for candidates, delegator-bonds * [gaiacli] Support queries for candidates, delegator-bonds
* [gaiad] Added `gaiad export` command to export current state to JSON * [gaiad] Added `gaiad export` command to export current state to JSON
* [x/bank] Tx tags with sender/recipient for indexing & later retrieval * [x/bank] Tx tags with sender/recipient for indexing & later retrieval
* [x/stake] Tx tags with delegator/candidate for delegation & unbonding, and candidate info for declare candidate / edit candidacy * [x/stake] Tx tags with delegator/candidate for delegation & unbonding, and candidate info for declare candidate / edit validator
IMPROVEMENTS IMPROVEMENTS
@ -134,7 +134,7 @@ BREAKING CHANGES
FEATURES: FEATURES:
* Gaia stake commands include, DeclareCandidacy, EditCandidacy, Delegate, Unbond * Gaia stake commands include, CreateValidator, EditValidator, Delegate, Unbond
* MountStoreWithDB without providing a custom store works. * MountStoreWithDB without providing a custom store works.
* Repo is now lint compliant / GoMetaLinter with tendermint-lint integrated into CI * Repo is now lint compliant / GoMetaLinter with tendermint-lint integrated into CI
* Better key output, pubkey go-amino hex bytes now output by default * Better key output, pubkey go-amino hex bytes now output by default

View File

@ -394,13 +394,13 @@ func TestStakeMsgs(t *testing.T) {
require.Equal(t, acc1, res1) require.Equal(t, acc1, res1)
require.Equal(t, acc2, res2) require.Equal(t, acc2, res2)
// Declare Candidacy // Create Validator
description := stake.NewDescription("foo_moniker", "", "", "") description := stake.NewDescription("foo_moniker", "", "", "")
declareCandidacyMsg := stake.NewMsgDeclareCandidacy( createValidatorMsg := stake.NewMsgCreateValidator(
addr1, priv1.PubKey(), bondCoin, description, addr1, priv1.PubKey(), bondCoin, description,
) )
SignCheckDeliver(t, gapp, declareCandidacyMsg, []int64{0}, true, priv1) SignCheckDeliver(t, gapp, createValidatorMsg, []int64{0}, true, priv1)
ctxDeliver := gapp.BaseApp.NewContext(false, abci.Header{}) ctxDeliver := gapp.BaseApp.NewContext(false, abci.Header{})
res1 = gapp.accountMapper.GetAccount(ctxDeliver, addr1) res1 = gapp.accountMapper.GetAccount(ctxDeliver, addr1)
@ -415,13 +415,13 @@ func TestStakeMsgs(t *testing.T) {
bond, found := gapp.stakeKeeper.GetDelegation(ctxDeliver, addr1, addr1) bond, found := gapp.stakeKeeper.GetDelegation(ctxDeliver, addr1, addr1)
require.True(sdk.RatEq(t, sdk.NewRat(10), bond.Shares)) require.True(sdk.RatEq(t, sdk.NewRat(10), bond.Shares))
// Edit Candidacy // Edit Validator
description = stake.NewDescription("bar_moniker", "", "", "") description = stake.NewDescription("bar_moniker", "", "", "")
editCandidacyMsg := stake.NewMsgEditCandidacy( editValidatorMsg := stake.NewMsgEditValidator(
addr1, description, addr1, description,
) )
SignDeliver(t, gapp, editCandidacyMsg, []int64{1}, true, priv1) SignDeliver(t, gapp, editValidatorMsg, []int64{1}, true, priv1)
validator, found = gapp.stakeKeeper.GetValidator(ctxDeliver, addr1) validator, found = gapp.stakeKeeper.GetValidator(ctxDeliver, addr1)
require.True(t, found) require.True(t, found)

View File

@ -105,7 +105,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
//valAddr := sdk.Address((valPrivkey.PubKey().Address())) //valAddr := sdk.Address((valPrivkey.PubKey().Address()))
//bechVal, err := sdk.Bech32CosmosifyVal(valAddr) //bechVal, err := sdk.Bech32CosmosifyVal(valAddr)
// declare candidacy // create validator
cvStr := fmt.Sprintf("gaiacli create-validator %v", flags) cvStr := fmt.Sprintf("gaiacli create-validator %v", flags)
cvStr += fmt.Sprintf(" --name=%v", "bar") cvStr += fmt.Sprintf(" --name=%v", "bar")
cvStr += fmt.Sprintf(" --validator-address=%v", barCech) cvStr += fmt.Sprintf(" --validator-address=%v", barCech)

View File

@ -59,8 +59,8 @@ func main() {
bankcmd.SendTxCmd(cdc), bankcmd.SendTxCmd(cdc),
ibccmd.IBCTransferCmd(cdc), ibccmd.IBCTransferCmd(cdc),
ibccmd.IBCRelayCmd(cdc), ibccmd.IBCRelayCmd(cdc),
stakecmd.GetCmdDeclareCandidacy(cdc), stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditCandidacy(cdc), stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc), stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond(cdc), stakecmd.GetCmdUnbond(cdc),
)...) )...)

View File

@ -26,7 +26,7 @@ func NewMsgBond(addr sdk.Address, stake sdk.Coin, pubKey crypto.PubKey) MsgBond
} }
//nolint //nolint
func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/declarecandidacy" func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/createvalidator"
func (msg MsgBond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} } func (msg MsgBond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
// basic validation of the bond message // basic validation of the bond message
@ -65,7 +65,7 @@ func NewMsgUnbond(addr sdk.Address) MsgUnbond {
} }
//nolint //nolint
func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/declarecandidacy" func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/createvalidator"
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} } func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil } func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil }

View File

@ -16,7 +16,7 @@ func TestHandleDoubleSign(t *testing.T) {
// initial setup // initial setup
ctx, ck, sk, keeper := createTestInput(t) ctx, ck, sk, keeper := createTestInput(t)
addr, val, amt := addrs[0], pks[0], int64(100) addr, val, amt := addrs[0], pks[0], int64(100)
got := stake.NewHandler(sk)(ctx, newTestMsgDeclareCandidacy(addr, val, amt)) got := stake.NewHandler(sk)(ctx, newTestMsgCreateValidator(addr, val, amt))
require.True(t, got.IsOK()) require.True(t, got.IsOK())
sk.Tick(ctx) sk.Tick(ctx)
require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}}) require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}})
@ -39,7 +39,7 @@ func TestHandleAbsentValidator(t *testing.T) {
addr, val, amt := addrs[0], pks[0], int64(100) addr, val, amt := addrs[0], pks[0], int64(100)
sh := stake.NewHandler(sk) sh := stake.NewHandler(sk)
slh := NewHandler(keeper) slh := NewHandler(keeper)
got := sh(ctx, newTestMsgDeclareCandidacy(addr, val, amt)) got := sh(ctx, newTestMsgCreateValidator(addr, val, amt))
require.True(t, got.IsOK()) require.True(t, got.IsOK())
sk.Tick(ctx) sk.Tick(ctx)
require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}}) require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}})

View File

@ -85,8 +85,8 @@ func testAddr(addr string) sdk.Address {
return res return res
} }
func newTestMsgDeclareCandidacy(address sdk.Address, pubKey crypto.PubKey, amt int64) stake.MsgDeclareCandidacy { func newTestMsgCreateValidator(address sdk.Address, pubKey crypto.PubKey, amt int64) stake.MsgCreateValidator {
return stake.MsgDeclareCandidacy{ return stake.MsgCreateValidator{
Description: stake.Description{}, Description: stake.Description{},
ValidatorAddr: address, ValidatorAddr: address,
PubKey: pubKey, PubKey: pubKey,

View File

@ -13,7 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake"
) )
// create declare candidacy command // create create validator command
func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command { func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "create-validator", Use: "create-validator",
@ -47,7 +47,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
Website: viper.GetString(FlagWebsite), Website: viper.GetString(FlagWebsite),
Details: viper.GetString(FlagDetails), Details: viper.GetString(FlagDetails),
} }
msg := stake.NewMsgDeclareCandidacy(validatorAddr, pk, amount, description) msg := stake.NewMsgCreateValidator(validatorAddr, pk, amount, description)
// build and sign the transaction, then broadcast to Tendermint // build and sign the transaction, then broadcast to Tendermint
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc) res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
@ -67,7 +67,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
return cmd return cmd
} }
// create edit candidacy command // create edit validator command
func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command { func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "edit-validator", Use: "edit-validator",
@ -84,7 +84,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
Website: viper.GetString(FlagWebsite), Website: viper.GetString(FlagWebsite),
Details: viper.GetString(FlagDetails), Details: viper.GetString(FlagDetails),
} }
msg := stake.NewMsgEditCandidacy(validatorAddr, description) msg := stake.NewMsgEditValidator(validatorAddr, description)
// build and sign the transaction, then broadcast to Tendermint // build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc)) ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
@ -104,7 +104,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
return cmd return cmd
} }
// create edit candidacy command // create edit validator command
func GetCmdDelegate(cdc *wire.Codec) *cobra.Command { func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "delegate", Use: "delegate",
@ -142,7 +142,7 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
return cmd return cmd
} }
// create edit candidacy command // create edit validator command
func GetCmdUnbond(cdc *wire.Codec) *cobra.Command { func GetCmdUnbond(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "unbond", Use: "unbond",

View File

@ -73,10 +73,10 @@ func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidValidator, "Delegator does not exist for that address") return newError(codespace, CodeInvalidValidator, "Delegator does not exist for that address")
} }
func ErrValidatorExistsAddr(codespace sdk.CodespaceType) sdk.Error { func ErrValidatorExistsAddr(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidValidator, "Validator already exist, cannot re-declare candidacy") return newError(codespace, CodeInvalidValidator, "Validator already exist, cannot re-create validator")
} }
func ErrValidatorRevoked(codespace sdk.CodespaceType) sdk.Error { func ErrValidatorRevoked(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidValidator, "Candidacy for this address is currently revoked") return newError(codespace, CodeInvalidValidator, "Validator for this address is currently revoked")
} }
func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error { func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidValidator, "Missing signature") return newError(codespace, CodeInvalidValidator, "Missing signature")

View File

@ -11,10 +11,10 @@ func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
// NOTE msg already has validate basic run // NOTE msg already has validate basic run
switch msg := msg.(type) { switch msg := msg.(type) {
case MsgDeclareCandidacy: case MsgCreateValidator:
return handleMsgDeclareCandidacy(ctx, msg, k) return handleMsgCreateValidator(ctx, msg, k)
case MsgEditCandidacy: case MsgEditValidator:
return handleMsgEditCandidacy(ctx, msg, k) return handleMsgEditValidator(ctx, msg, k)
case MsgDelegate: case MsgDelegate:
return handleMsgDelegate(ctx, msg, k) return handleMsgDelegate(ctx, msg, k)
case MsgUnbond: case MsgUnbond:
@ -39,7 +39,7 @@ func NewEndBlocker(k Keeper) sdk.EndBlocker {
// These functions assume everything has been authenticated, // These functions assume everything has been authenticated,
// now we just perform action and save // now we just perform action and save
func handleMsgDeclareCandidacy(ctx sdk.Context, msg MsgDeclareCandidacy, k Keeper) sdk.Result { func handleMsgCreateValidator(ctx sdk.Context, msg MsgCreateValidator, k Keeper) sdk.Result {
// check to see if the pubkey or sender has been registered before // check to see if the pubkey or sender has been registered before
_, found := k.GetValidator(ctx, msg.ValidatorAddr) _, found := k.GetValidator(ctx, msg.ValidatorAddr)
@ -57,7 +57,7 @@ func handleMsgDeclareCandidacy(ctx sdk.Context, msg MsgDeclareCandidacy, k Keepe
k.setValidator(ctx, validator) k.setValidator(ctx, validator)
k.setValidatorByPubKeyIndex(ctx, validator) k.setValidatorByPubKeyIndex(ctx, validator)
tags := sdk.NewTags( tags := sdk.NewTags(
"action", []byte("declareCandidacy"), "action", []byte("createValidator"),
"validator", msg.ValidatorAddr.Bytes(), "validator", msg.ValidatorAddr.Bytes(),
"moniker", []byte(msg.Description.Moniker), "moniker", []byte(msg.Description.Moniker),
"identity", []byte(msg.Description.Identity), "identity", []byte(msg.Description.Identity),
@ -75,7 +75,7 @@ func handleMsgDeclareCandidacy(ctx sdk.Context, msg MsgDeclareCandidacy, k Keepe
} }
} }
func handleMsgEditCandidacy(ctx sdk.Context, msg MsgEditCandidacy, k Keeper) sdk.Result { func handleMsgEditValidator(ctx sdk.Context, msg MsgEditValidator, k Keeper) sdk.Result {
// validator must already be registered // validator must already be registered
validator, found := k.GetValidator(ctx, msg.ValidatorAddr) validator, found := k.GetValidator(ctx, msg.ValidatorAddr)
@ -95,7 +95,7 @@ func handleMsgEditCandidacy(ctx sdk.Context, msg MsgEditCandidacy, k Keeper) sdk
k.updateValidator(ctx, validator) k.updateValidator(ctx, validator)
tags := sdk.NewTags( tags := sdk.NewTags(
"action", []byte("editCandidacy"), "action", []byte("editValidator"),
"validator", msg.ValidatorAddr.Bytes(), "validator", msg.ValidatorAddr.Bytes(),
"moniker", []byte(msg.Description.Moniker), "moniker", []byte(msg.Description.Moniker),
"identity", []byte(msg.Description.Identity), "identity", []byte(msg.Description.Identity),
@ -207,14 +207,14 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
bond.Shares = bond.Shares.Sub(delShares) bond.Shares = bond.Shares.Sub(delShares)
// remove the bond // remove the bond
revokeCandidacy := false revokeValidator := false
if bond.Shares.IsZero() { if bond.Shares.IsZero() {
// if the bond is the owner of the validator then // if the bond is the owner of the validator then
// trigger a revoke candidacy // trigger a revoke validator
if bytes.Equal(bond.DelegatorAddr, validator.Owner) && if bytes.Equal(bond.DelegatorAddr, validator.Owner) &&
validator.Revoked == false { validator.Revoked == false {
revokeCandidacy = true revokeValidator = true
} }
k.removeDelegation(ctx, bond) k.removeDelegation(ctx, bond)
@ -233,7 +233,7 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
///////////////////////////////////// /////////////////////////////////////
// revoke validator if necessary // revoke validator if necessary
if revokeCandidacy { if revokeValidator {
validator.Revoked = true validator.Revoked = true
} }

View File

@ -14,8 +14,8 @@ import (
//______________________________________________________________________ //______________________________________________________________________
func newTestMsgDeclareCandidacy(address sdk.Address, pubKey crypto.PubKey, amt int64) MsgDeclareCandidacy { func newTestMsgCreateValidator(address sdk.Address, pubKey crypto.PubKey, amt int64) MsgCreateValidator {
return MsgDeclareCandidacy{ return MsgCreateValidator{
Description: Description{}, Description: Description{},
ValidatorAddr: address, ValidatorAddr: address,
PubKey: pubKey, PubKey: pubKey,
@ -33,13 +33,13 @@ func newTestMsgDelegate(delegatorAddr, validatorAddr sdk.Address, amt int64) Msg
//______________________________________________________________________ //______________________________________________________________________
func TestDuplicatesMsgDeclareCandidacy(t *testing.T) { func TestDuplicatesMsgCreateValidator(t *testing.T) {
ctx, _, keeper := createTestInput(t, false, 1000) ctx, _, keeper := createTestInput(t, false, 1000)
validatorAddr := addrs[0] validatorAddr := addrs[0]
pk := pks[0] pk := pks[0]
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pk, 10) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pk, 10)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
assert.True(t, got.IsOK(), "%v", got) assert.True(t, got.IsOK(), "%v", got)
validator, found := keeper.GetValidator(ctx, validatorAddr) validator, found := keeper.GetValidator(ctx, validatorAddr)
require.True(t, found) require.True(t, found)
@ -51,8 +51,8 @@ func TestDuplicatesMsgDeclareCandidacy(t *testing.T) {
assert.Equal(t, Description{}, validator.Description) assert.Equal(t, Description{}, validator.Description)
// one validator cannot bond twice // one validator cannot bond twice
msgDeclareCandidacy.PubKey = pks[1] msgCreateValidator.PubKey = pks[1]
got = handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
assert.False(t, got.IsOK(), "%v", got) assert.False(t, got.IsOK(), "%v", got)
} }
@ -64,10 +64,10 @@ func TestIncrementsMsgDelegate(t *testing.T) {
bondAmount := int64(10) bondAmount := int64(10)
validatorAddr, delegatorAddr := addrs[0], addrs[1] validatorAddr, delegatorAddr := addrs[0], addrs[1]
// first declare candidacy // first create validator
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pks[0], bondAmount) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pks[0], bondAmount)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
assert.True(t, got.IsOK(), "expected declare candidacy msg to be ok, got %v", got) assert.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got)
validator, found := keeper.GetValidator(ctx, validatorAddr) validator, found := keeper.GetValidator(ctx, validatorAddr)
require.True(t, found) require.True(t, found)
@ -134,12 +134,12 @@ func TestIncrementsMsgUnbond(t *testing.T) {
ctx, accMapper, keeper := createTestInput(t, false, initBond) ctx, accMapper, keeper := createTestInput(t, false, initBond)
params := keeper.GetParams(ctx) params := keeper.GetParams(ctx)
// declare candidacy, delegate // create validator, delegate
validatorAddr, delegatorAddr := addrs[0], addrs[1] validatorAddr, delegatorAddr := addrs[0], addrs[1]
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pks[0], initBond) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pks[0], initBond)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
assert.True(t, got.IsOK(), "expected declare-candidacy to be ok, got %v", got) assert.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got)
msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, initBond) msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, initBond)
got = handleMsgDelegate(ctx, msgDelegate, keeper) got = handleMsgDelegate(ctx, msgDelegate, keeper)
@ -216,7 +216,7 @@ func TestIncrementsMsgUnbond(t *testing.T) {
"got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgUnbond, unbondSharesStr, leftBonded) "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgUnbond, unbondSharesStr, leftBonded)
} }
func TestMultipleMsgDeclareCandidacy(t *testing.T) { func TestMultipleMsgCreateValidator(t *testing.T) {
initBond := int64(1000) initBond := int64(1000)
ctx, accMapper, keeper := createTestInput(t, false, initBond) ctx, accMapper, keeper := createTestInput(t, false, initBond)
params := keeper.GetParams(ctx) params := keeper.GetParams(ctx)
@ -224,8 +224,8 @@ func TestMultipleMsgDeclareCandidacy(t *testing.T) {
// bond them all // bond them all
for i, validatorAddr := range validatorAddrs { for i, validatorAddr := range validatorAddrs {
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pks[i], 10) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pks[i], 10)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
//Check that the account is bonded //Check that the account is bonded
@ -266,8 +266,8 @@ func TestMultipleMsgDelegate(t *testing.T) {
validatorAddr, delegatorAddrs := addrs[0], addrs[1:] validatorAddr, delegatorAddrs := addrs[0], addrs[1:]
//first make a validator //first make a validator
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pks[0], 10) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pks[0], 10)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.True(t, got.IsOK(), "expected msg to be ok, got %v", got) require.True(t, got.IsOK(), "expected msg to be ok, got %v", got)
// delegate multiple parties // delegate multiple parties
@ -294,14 +294,14 @@ func TestMultipleMsgDelegate(t *testing.T) {
} }
} }
func TestVoidCandidacy(t *testing.T) { func TestRevokeValidator(t *testing.T) {
ctx, _, keeper := createTestInput(t, false, 1000) ctx, _, keeper := createTestInput(t, false, 1000)
validatorAddr, delegatorAddr := addrs[0], addrs[1] validatorAddr, delegatorAddr := addrs[0], addrs[1]
// create the validator // create the validator
msgDeclareCandidacy := newTestMsgDeclareCandidacy(validatorAddr, pks[0], 10) msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pks[0], 10)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy") require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")
// bond a delegator // bond a delegator
msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, 10) msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, 10)
@ -311,7 +311,7 @@ func TestVoidCandidacy(t *testing.T) {
// unbond the validators bond portion // unbond the validators bond portion
msgUnbondValidator := NewMsgUnbond(validatorAddr, validatorAddr, "10") msgUnbondValidator := NewMsgUnbond(validatorAddr, validatorAddr, "10")
got = handleMsgUnbond(ctx, msgUnbondValidator, keeper) got = handleMsgUnbond(ctx, msgUnbondValidator, keeper)
require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy") require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")
validator, found := keeper.GetValidator(ctx, validatorAddr) validator, found := keeper.GetValidator(ctx, validatorAddr)
require.True(t, found) require.True(t, found)
require.True(t, validator.Revoked) require.True(t, validator.Revoked)
@ -323,9 +323,9 @@ func TestVoidCandidacy(t *testing.T) {
// test that the delegator can still withdraw their bonds // test that the delegator can still withdraw their bonds
msgUnbondDelegator := NewMsgUnbond(delegatorAddr, validatorAddr, "10") msgUnbondDelegator := NewMsgUnbond(delegatorAddr, validatorAddr, "10")
got = handleMsgUnbond(ctx, msgUnbondDelegator, keeper) got = handleMsgUnbond(ctx, msgUnbondDelegator, keeper)
require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy") require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")
// verify that the pubkey can now be reused // verify that the pubkey can now be reused
got = handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
assert.True(t, got.IsOK(), "expected ok, got %v", got) assert.True(t, got.IsOK(), "expected ok, got %v", got)
} }

View File

@ -15,21 +15,21 @@ const MsgType = "stake"
const StakingToken = "steak" const StakingToken = "steak"
//Verify interface at compile time //Verify interface at compile time
var _, _, _, _ sdk.Msg = &MsgDeclareCandidacy{}, &MsgEditCandidacy{}, &MsgDelegate{}, &MsgUnbond{} var _, _, _, _ sdk.Msg = &MsgCreateValidator{}, &MsgEditValidator{}, &MsgDelegate{}, &MsgUnbond{}
//______________________________________________________________________ //______________________________________________________________________
// MsgDeclareCandidacy - struct for unbonding transactions // MsgCreateValidator - struct for unbonding transactions
type MsgDeclareCandidacy struct { type MsgCreateValidator struct {
Description Description
ValidatorAddr sdk.Address `json:"address"` ValidatorAddr sdk.Address `json:"address"`
PubKey crypto.PubKey `json:"pubkey"` PubKey crypto.PubKey `json:"pubkey"`
Bond sdk.Coin `json:"bond"` Bond sdk.Coin `json:"bond"`
} }
func NewMsgDeclareCandidacy(validatorAddr sdk.Address, pubkey crypto.PubKey, func NewMsgCreateValidator(validatorAddr sdk.Address, pubkey crypto.PubKey,
bond sdk.Coin, description Description) MsgDeclareCandidacy { bond sdk.Coin, description Description) MsgCreateValidator {
return MsgDeclareCandidacy{ return MsgCreateValidator{
Description: description, Description: description,
ValidatorAddr: validatorAddr, ValidatorAddr: validatorAddr,
PubKey: pubkey, PubKey: pubkey,
@ -38,18 +38,18 @@ func NewMsgDeclareCandidacy(validatorAddr sdk.Address, pubkey crypto.PubKey,
} }
//nolint //nolint
func (msg MsgDeclareCandidacy) Type() string { return MsgType } //TODO update "stake/declarecandidacy" func (msg MsgCreateValidator) Type() string { return MsgType }
func (msg MsgDeclareCandidacy) GetSigners() []sdk.Address { func (msg MsgCreateValidator) GetSigners() []sdk.Address {
return []sdk.Address{msg.ValidatorAddr} return []sdk.Address{msg.ValidatorAddr}
} }
// get the bytes for the message signer to sign on // get the bytes for the message signer to sign on
func (msg MsgDeclareCandidacy) GetSignBytes() []byte { func (msg MsgCreateValidator) GetSignBytes() []byte {
return msgCdc.MustMarshalBinary(msg) return msgCdc.MustMarshalBinary(msg)
} }
// quick validity check // quick validity check
func (msg MsgDeclareCandidacy) ValidateBasic() sdk.Error { func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
if msg.ValidatorAddr == nil { if msg.ValidatorAddr == nil {
return ErrValidatorEmpty(DefaultCodespace) return ErrValidatorEmpty(DefaultCodespace)
} }
@ -68,27 +68,27 @@ func (msg MsgDeclareCandidacy) ValidateBasic() sdk.Error {
//______________________________________________________________________ //______________________________________________________________________
// MsgEditCandidacy - struct for editing a validator // MsgEditValidator - struct for editing a validator
type MsgEditCandidacy struct { type MsgEditValidator struct {
Description Description
ValidatorAddr sdk.Address `json:"address"` ValidatorAddr sdk.Address `json:"address"`
} }
func NewMsgEditCandidacy(validatorAddr sdk.Address, description Description) MsgEditCandidacy { func NewMsgEditValidator(validatorAddr sdk.Address, description Description) MsgEditValidator {
return MsgEditCandidacy{ return MsgEditValidator{
Description: description, Description: description,
ValidatorAddr: validatorAddr, ValidatorAddr: validatorAddr,
} }
} }
//nolint //nolint
func (msg MsgEditCandidacy) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy" func (msg MsgEditValidator) Type() string { return MsgType }
func (msg MsgEditCandidacy) GetSigners() []sdk.Address { func (msg MsgEditValidator) GetSigners() []sdk.Address {
return []sdk.Address{msg.ValidatorAddr} return []sdk.Address{msg.ValidatorAddr}
} }
// get the bytes for the message signer to sign on // get the bytes for the message signer to sign on
func (msg MsgEditCandidacy) GetSignBytes() []byte { func (msg MsgEditValidator) GetSignBytes() []byte {
b, err := msgCdc.MarshalJSON(msg) b, err := msgCdc.MarshalJSON(msg)
if err != nil { if err != nil {
panic(err) panic(err)
@ -97,7 +97,7 @@ func (msg MsgEditCandidacy) GetSignBytes() []byte {
} }
// quick validity check // quick validity check
func (msg MsgEditCandidacy) ValidateBasic() sdk.Error { func (msg MsgEditValidator) ValidateBasic() sdk.Error {
if msg.ValidatorAddr == nil { if msg.ValidatorAddr == nil {
return ErrValidatorEmpty(DefaultCodespace) return ErrValidatorEmpty(DefaultCodespace)
} }
@ -126,7 +126,7 @@ func NewMsgDelegate(delegatorAddr, validatorAddr sdk.Address, bond sdk.Coin) Msg
} }
//nolint //nolint
func (msg MsgDelegate) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy" func (msg MsgDelegate) Type() string { return MsgType }
func (msg MsgDelegate) GetSigners() []sdk.Address { func (msg MsgDelegate) GetSigners() []sdk.Address {
return []sdk.Address{msg.DelegatorAddr} return []sdk.Address{msg.DelegatorAddr}
} }
@ -175,7 +175,7 @@ func NewMsgUnbond(delegatorAddr, validatorAddr sdk.Address, shares string) MsgUn
} }
//nolint //nolint
func (msg MsgUnbond) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy" func (msg MsgUnbond) Type() string { return MsgType }
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} } func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
// get the bytes for the message signer to sign on // get the bytes for the message signer to sign on

View File

@ -18,8 +18,8 @@ var (
coinNegNotAtoms = sdk.Coin{"foo", -10000} coinNegNotAtoms = sdk.Coin{"foo", -10000}
) )
// test ValidateBasic for MsgDeclareCandidacy // test ValidateBasic for MsgCreateValidator
func TestMsgDeclareCandidacy(t *testing.T) { func TestMsgCreateValidator(t *testing.T) {
tests := []struct { tests := []struct {
name, moniker, identity, website, details string name, moniker, identity, website, details string
validatorAddr sdk.Address validatorAddr sdk.Address
@ -40,7 +40,7 @@ func TestMsgDeclareCandidacy(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details)
msg := NewMsgDeclareCandidacy(tc.validatorAddr, tc.pubkey, tc.bond, description) msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description)
if tc.expectPass { if tc.expectPass {
assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name)
} else { } else {
@ -49,8 +49,8 @@ func TestMsgDeclareCandidacy(t *testing.T) {
} }
} }
// test ValidateBasic for MsgEditCandidacy // test ValidateBasic for MsgEditValidator
func TestMsgEditCandidacy(t *testing.T) { func TestMsgEditValidator(t *testing.T) {
tests := []struct { tests := []struct {
name, moniker, identity, website, details string name, moniker, identity, website, details string
validatorAddr sdk.Address validatorAddr sdk.Address
@ -64,7 +64,7 @@ func TestMsgEditCandidacy(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details)
msg := NewMsgEditCandidacy(tc.validatorAddr, description) msg := NewMsgEditValidator(tc.validatorAddr, description)
if tc.expectPass { if tc.expectPass {
assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name)
} else { } else {
@ -139,8 +139,8 @@ func TestMsgUnbond(t *testing.T) {
//tests := []struct { //tests := []struct {
//tx sdk.Msg //tx sdk.Msg
//}{ //}{
//{NewMsgDeclareCandidacy(addrs[0], pks[0], bond, Description{})}, //{NewMsgCreateValidator(addrs[0], pks[0], bond, Description{})},
//{NewMsgEditCandidacy(addrs[0], Description{})}, //{NewMsgEditValidator(addrs[0], Description{})},
//{NewMsgDelegate(addrs[0], addrs[1], bond)}, //{NewMsgDelegate(addrs[0], addrs[1], bond)},
//{NewMsgUnbond(addrs[0], addrs[1], strconv.Itoa(bondAmt))}, //{NewMsgUnbond(addrs[0], addrs[1], strconv.Itoa(bondAmt))},
//} //}

View File

@ -68,8 +68,8 @@ func makeTestCodec() *wire.Codec {
cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/stake/Send", nil) cdc.RegisterConcrete(bank.MsgSend{}, "test/stake/Send", nil)
cdc.RegisterConcrete(bank.MsgIssue{}, "test/stake/Issue", nil) cdc.RegisterConcrete(bank.MsgIssue{}, "test/stake/Issue", nil)
cdc.RegisterConcrete(MsgDeclareCandidacy{}, "test/stake/DeclareCandidacy", nil) cdc.RegisterConcrete(MsgCreateValidator{}, "test/stake/CreateValidator", nil)
cdc.RegisterConcrete(MsgEditCandidacy{}, "test/stake/EditCandidacy", nil) cdc.RegisterConcrete(MsgEditValidator{}, "test/stake/EditValidator", nil)
cdc.RegisterConcrete(MsgUnbond{}, "test/stake/Unbond", nil) cdc.RegisterConcrete(MsgUnbond{}, "test/stake/Unbond", nil)
// Register AppAccount // Register AppAccount

View File

@ -6,8 +6,8 @@ import (
// Register concrete types on wire codec // Register concrete types on wire codec
func RegisterWire(cdc *wire.Codec) { func RegisterWire(cdc *wire.Codec) {
cdc.RegisterConcrete(MsgDeclareCandidacy{}, "cosmos-sdk/MsgDeclareCandidacy", nil) cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil)
cdc.RegisterConcrete(MsgEditCandidacy{}, "cosmos-sdk/MsgEditCandidacy", nil) cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil)
cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil)
cdc.RegisterConcrete(MsgUnbond{}, "cosmos-sdk/MsgUnbond", nil) cdc.RegisterConcrete(MsgUnbond{}, "cosmos-sdk/MsgUnbond", nil)
} }