Skip to content

Commit

Permalink
flight #2, the long one
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 20, 2019
1 parent 9cc5ec8 commit eb73a81
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 68 deletions.
34 changes: 17 additions & 17 deletions x/poa/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package keeper

import (
"testing"
// import (
// "testing"

"github.com/stretchr/testify/require"
// "github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/x/poa/internal/types"
)
// "github.com/cosmos/cosmos-sdk/x/poa/internal/types"
// )

func TestParams(t *testing.T) {
ctx, _, keeper, _ := CreateTestInput(t, false)
expParams := types.DefaultParams()
// func TestParams(t *testing.T) {
// ctx, _, keeper, _ := CreateTestInput(t, false)
// expParams := types.DefaultParams()

//check that the empty keeper loads the default
resParams := keeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
// //check that the empty keeper loads the default
// resParams := keeper.GetParams(ctx)
// require.True(t, expParams.Equal(resParams))

//modify a params, save, and retrieve
expParams.MaxValidators = 777
keeper.SetParams(ctx, expParams)
resParams = keeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
}
// //modify a params, save, and retrieve
// expParams.MaxValidators = 777
// keeper.SetParams(ctx, expParams)
// resParams = keeper.GetParams(ctx)
// require.True(t, expParams.Equal(resParams))
// }
63 changes: 12 additions & 51 deletions x/poa/internal/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ var _ govtypes.Content = MsgProposeCreateValidator{}
type MsgProposeCreateValidator struct {
Title string `json:"title" yaml:"title"` // title of the validator
Description string `json:"description" yaml:"description"` // description of validator
Validator NewValidatorCreatation `json:"validator" yaml:"validator"`
Validator MsgCreateValidator `json:"validator" yaml:"validator"`
}

func NewMsgProposeCreateValidaor(title, description string, va NewValidatorCreatation) MsgProposeCreateValidator {
func NewMsgProposeCreateValidator(title, description string, valAddr sdk.ValAddress,
pubKey crypto.PubKey, valDescription stakingtypes.Description,) MsgProposeCreateValidator {
newValidator := NewMsgCreateValidator(valAddr, pubKey, valDescription)
return MsgProposeCreateValidator{
Title: title,
Description: description,
Validator: va,
Validator: newValidator,
}
}

Expand Down Expand Up @@ -82,36 +84,6 @@ func ValidateChanges(cVA MsgProposeCreateValidator) sdk.Error {
return nil
}

type NewValidatorCreatation struct {
Description stakingtypes.Description `json:"description" yaml:"description"` // description of validator
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"`
}

func CreateNewValidator(d stakingtypes.Description, va sdk.ValAddress, pb crypto.PubKey) NewValidatorCreatation {
return NewValidatorCreatation{
Description: d,
ValidatorAddress: va,
PubKey: pb,
}
}

func (nvc NewValidatorCreatation) String() string {
des := nvc.Description
d := fmt.Sprintf(`
Moinker: %s,
Identity: %s,
Website: %s,
SecruityContract: %s,
Details: %s,
ValidatorAddress: %s,
PubKey: %s
`, des.Moniker, des.Identity, des.Website,
des.SecurityContact, des.Details, nvc.ValidatorAddress.String(),
nvc.PubKey.Address().String())
return d
}

// --------------------------------

type MsgProposeIncreaseWeight struct {
Expand Down Expand Up @@ -142,18 +114,12 @@ func (mpi MsgProposeIncreaseWeight) ProposalType() string { return ProposeCreate

// String implements the stringer interface
func (mpi MsgProposeIncreaseWeight) String() string {
des := mpi.Validator.Description
val := mpi.Validator
d := fmt.Sprintf(`
Title: %s,
Moinker: %s,
Identity: %s,
Website: %s,
SecruityContract: %s,
Details: %s,
ValidatorAddress: %s,
PubKey: %s
`, mpi.Title, des.Moniker, des.Identity, des.Website,
des.SecurityContact, des.Details, mpi.Validator.ValidatorAddress.String(), mpi.Validator.PubKey.Address().String())
New Weight: %v
`,
val.ValidatorAddress.String(), val.NewWeight)
return d
}

Expand All @@ -167,27 +133,22 @@ func (mpi MsgProposeIncreaseWeight) ValidateBasic() sdk.Error {
if len(mpi.Title) == 0 {
return params.ErrEmptyChanges(DefaultCodeSpace)
}
if mpi.Validator.Description == (stakingtypes.Description{}) {
return sdk.NewError(stakingtypes.DefaultCodespace, stakingtypes.CodeInvalidInput, "description must be included")
}
if mpi.Validator.ValidatorAddress.Empty() {
return stakingtypes.ErrNilValidatorAddr(DefaultCodeSpace)
}
return nil
}

type ValidatorIncreaseWeight struct {
Description stakingtypes.Description `json:"description" yaml:"description"` // description of validator
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"`
NewWeight sdk.Int `json:"new_weight" yaml:"new_weight"`
}

func ValidatorWeightIncrease(d stakingtypes.Description, va sdk.ValAddress, pb crypto.PubKey, nw sdk.Int) ValidatorIncreaseWeight {
func ValidatorWeightIncrease(va sdk.ValAddress, pb crypto.PubKey, nw sdk.Int) ValidatorIncreaseWeight {
return ValidatorIncreaseWeight{
Description: d,
ValidatorAddress: va,
PubKey: pb,
NewWeight: nw,
}
}


36 changes: 36 additions & 0 deletions x/poa/internal/types/proposal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package types

import (
"testing"

"github.com/stretchr/testify/require"
// tmtypes "github.com/tendermint/tendermint/types"

// sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)


func TestMsgProposeCreateValidator(t *testing.T) {
tests := []struct{
title, description string
newValidator MsgCreateValidator
expectPass bool
}{
{"foo", "bar",MsgCreateValidator{stakingtypes.Description{"basic good", "a", "b", "c", "d"}, valAddr1, pk1}, true},
{"bar","foo",MsgCreateValidator{stakingtypes.Description{"partial description", "", "", "c", ""}, valAddr1, pk1}, true},
{"","Alcie",MsgCreateValidator{stakingtypes.Description{"empty description", "", "", "", ""}, valAddr1, pk1}, false},
{"bob","",MsgCreateValidator{stakingtypes.Description{"empty address", "a", "b", "c", "d"}, emptyAddr, pk1}, false},
{"","simon",MsgCreateValidator{stakingtypes.Description{"empty pubkey", "a", "b", "c", "d"}, valAddr1, emptyPubkey}, false},
}
for _, tc := range tests {
msg := NewMsgProposeCreateValidator(tc.title, tc.description,tc.newValidator.ValidatorAddress, tc.newValidator.PubKey, tc.newValidator.Description)
if tc.expectPass {
require.Nil(t, msg.ValidateBasic(), "test: %v", tc.title)
} else {
require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.title)
}
}
}

// func TestMsg

0 comments on commit eb73a81

Please sign in to comment.