only import types pkgs within types

This commit is contained in:
rhuairahrighairigh 2020-04-28 01:28:00 +01:00
parent 307ecd54e2
commit d1c0dd18b1
5 changed files with 43 additions and 43 deletions

View File

@ -4,15 +4,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/cosmos/cosmos-sdk/x/gov" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
var _ PubProposal = UnregisteredPubProposal{} var _ PubProposal = UnregisteredPubProposal{}
type UnregisteredPubProposal struct { type UnregisteredPubProposal struct {
gov.TextProposal govtypes.TextProposal
} }
func (UnregisteredPubProposal) ProposalRoute() string { return "unregistered" } func (UnregisteredPubProposal) ProposalRoute() string { return "unregistered" }
@ -39,10 +39,10 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
Key: "DebtThreshold", Key: "DebtThreshold",
}, },
}}}, }}},
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description of this proposal.", "A description of this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -65,7 +65,7 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
}}, }},
TextPermission{}, TextPermission{},
}, },
pubProposal: gov.NewTextProposal("A Proposal Title", "A description of this proposal"), pubProposal: govtypes.NewTextProposal("A Proposal Title", "A description of this proposal"),
expectHasPermissions: true, expectHasPermissions: true,
}, },
{ {
@ -80,10 +80,10 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
}}, }},
GodPermission{}, GodPermission{},
}, },
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description of this proposal.", "A description of this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "CollateralParams", Key: "CollateralParams",
@ -97,10 +97,10 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
{ {
name: "no permissions", name: "no permissions",
permissions: nil, permissions: nil,
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description of this proposal.", "A description of this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "CollateralParams", Key: "CollateralParams",
@ -130,10 +130,10 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
}, },
}}, }},
}, },
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description of this proposal.", "A description of this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -161,7 +161,7 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
}, },
}}, }},
}, },
pubProposal: UnregisteredPubProposal{gov.TextProposal{"A Title", "A description."}}, pubProposal: UnregisteredPubProposal{govtypes.TextProposal{"A Title", "A description."}},
expectHasPermissions: false, expectHasPermissions: false,
}, },
} }

View File

@ -4,7 +4,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
) )
// TODO nums ok?
var ( var (
ErrUnknownCommittee = sdkerrors.Register(ModuleName, 2, "committee not found") ErrUnknownCommittee = sdkerrors.Register(ModuleName, 2, "committee not found")
ErrInvalidCommittee = sdkerrors.Register(ModuleName, 3, "invalid committee") ErrInvalidCommittee = sdkerrors.Register(ModuleName, 3, "invalid committee")

View File

@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
) )
@ -42,7 +42,7 @@ func TestGenesisState_Validate(t *testing.T) {
}, },
}, },
Proposals: []Proposal{ Proposals: []Proposal{
{ID: 1, CommitteeID: 1, PubProposal: gov.NewTextProposal("A Title", "A description of this proposal."), Deadline: testTime.Add(7 * 24 * time.Hour)}, {ID: 1, CommitteeID: 1, PubProposal: govtypes.NewTextProposal("A Title", "A description of this proposal."), Deadline: testTime.Add(7 * 24 * time.Hour)},
}, },
Votes: []Vote{ Votes: []Vote{
{ProposalID: 1, Voter: addresses[0]}, {ProposalID: 1, Voter: addresses[0]},
@ -114,7 +114,7 @@ func TestGenesisState_Validate(t *testing.T) {
testGenesis.Proposals, testGenesis.Proposals,
Proposal{ Proposal{
ID: testGenesis.NextProposalID, ID: testGenesis.NextProposalID,
PubProposal: gov.NewTextProposal("A Title", "A description of this proposal."), PubProposal: govtypes.NewTextProposal("A Title", "A description of this proposal."),
CommitteeID: 247, // doesn't exist CommitteeID: 247, // doesn't exist
}), }),
Votes: testGenesis.Votes, Votes: testGenesis.Votes,

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
) )
func TestMsgSubmitProposal_ValidateBasic(t *testing.T) { func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
@ -18,17 +18,17 @@ func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
}{ }{
{ {
name: "normal", name: "normal",
msg: MsgSubmitProposal{gov.NewTextProposal("A Title", "A proposal description."), addr, 3}, msg: MsgSubmitProposal{govtypes.NewTextProposal("A Title", "A proposal description."), addr, 3},
expectPass: true, expectPass: true,
}, },
{ {
name: "empty address", name: "empty address",
msg: MsgSubmitProposal{gov.NewTextProposal("A Title", "A proposal description."), nil, 3}, msg: MsgSubmitProposal{govtypes.NewTextProposal("A Title", "A proposal description."), nil, 3},
expectPass: false, expectPass: false,
}, },
{ {
name: "invalid proposal", name: "invalid proposal",
msg: MsgSubmitProposal{gov.TextProposal{}, addr, 3}, msg: MsgSubmitProposal{govtypes.TextProposal{}, addr, 3},
expectPass: false, expectPass: false,
}, },
} }

View File

@ -3,8 +3,8 @@ package types
import ( import (
"testing" "testing"
"github.com/cosmos/cosmos-sdk/x/gov" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
@ -45,10 +45,10 @@ func (suite *PermissionsTestSuite) TestParamChangePermission_Allows() {
{ {
name: "normal (single param)", name: "normal (single param)",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -62,10 +62,10 @@ func (suite *PermissionsTestSuite) TestParamChangePermission_Allows() {
{ {
name: "normal (multiple params)", name: "normal (multiple params)",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -85,10 +85,10 @@ func (suite *PermissionsTestSuite) TestParamChangePermission_Allows() {
{ {
name: "not allowed (not in list)", name: "not allowed (not in list)",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "GlobalDebtLimit", Key: "GlobalDebtLimit",
@ -102,10 +102,10 @@ func (suite *PermissionsTestSuite) TestParamChangePermission_Allows() {
{ {
name: "not allowed (nil allowed params)", name: "not allowed (nil allowed params)",
allowedParams: nil, allowedParams: nil,
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -119,7 +119,7 @@ func (suite *PermissionsTestSuite) TestParamChangePermission_Allows() {
{ {
name: "not allowed (mismatched pubproposal type)", name: "not allowed (mismatched pubproposal type)",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
pubProposal: gov.NewTextProposal("A Title", "A description of this proposal."), pubProposal: govtypes.NewTextProposal("A Title", "A description of this proposal."),
expectAllowed: false, expectAllowed: false,
}, },
{ {
@ -147,13 +147,13 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
testcases := []struct { testcases := []struct {
name string name string
allowedParams AllowedParams allowedParams AllowedParams
testParam params.ParamChange testParam paramstypes.ParamChange
expectContained bool expectContained bool
}{ }{
{ {
name: "normal", name: "normal",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
testParam: params.ParamChange{ testParam: paramstypes.ParamChange{
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -164,7 +164,7 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
{ {
name: "missing subspace", name: "missing subspace",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
testParam: params.ParamChange{ testParam: paramstypes.ParamChange{
Subspace: "", Subspace: "",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -175,7 +175,7 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
{ {
name: "missing key", name: "missing key",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
testParam: params.ParamChange{ testParam: paramstypes.ParamChange{
Subspace: "cdp", Subspace: "cdp",
Key: "", Key: "",
@ -186,7 +186,7 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
{ {
name: "empty list", name: "empty list",
allowedParams: AllowedParams{}, allowedParams: AllowedParams{},
testParam: params.ParamChange{ testParam: paramstypes.ParamChange{
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -197,7 +197,7 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
{ {
name: "nil list", name: "nil list",
allowedParams: nil, allowedParams: nil,
testParam: params.ParamChange{ testParam: paramstypes.ParamChange{
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -208,13 +208,13 @@ func (suite *PermissionsTestSuite) TestAllowedParams_Contains() {
{ {
name: "no param change", name: "no param change",
allowedParams: suite.exampleAllowedParams, allowedParams: suite.exampleAllowedParams,
testParam: params.ParamChange{}, testParam: paramstypes.ParamChange{},
expectContained: false, expectContained: false,
}, },
{ {
name: "empty list and no param change", name: "empty list and no param change",
allowedParams: AllowedParams{}, allowedParams: AllowedParams{},
testParam: params.ParamChange{}, testParam: paramstypes.ParamChange{},
expectContained: false, expectContained: false,
}, },
} }
@ -237,7 +237,7 @@ func (suite *PermissionsTestSuite) TestTextPermission_Allows() {
}{ }{
{ {
name: "normal", name: "normal",
pubProposal: gov.NewTextProposal( pubProposal: govtypes.NewTextProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
), ),
@ -245,10 +245,10 @@ func (suite *PermissionsTestSuite) TestTextPermission_Allows() {
}, },
{ {
name: "not allowed (wrong pubproposal type)", name: "not allowed (wrong pubproposal type)",
pubProposal: params.NewParameterChangeProposal( pubProposal: paramstypes.NewParameterChangeProposal(
"A Title", "A Title",
"A description for this proposal.", "A description for this proposal.",
[]params.ParamChange{ []paramstypes.ParamChange{
{ {
Subspace: "cdp", Subspace: "cdp",
Key: "DebtThreshold", Key: "DebtThreshold",
@ -280,6 +280,7 @@ func (suite *PermissionsTestSuite) TestTextPermission_Allows() {
}) })
} }
} }
func TestPermissionsTestSuite(t *testing.T) { func TestPermissionsTestSuite(t *testing.T) {
suite.Run(t, new(PermissionsTestSuite)) suite.Run(t, new(PermissionsTestSuite))
} }