2020-05-15 19:25:49 +00:00
|
|
|
package keeper_test
|
2020-04-27 12:57:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-04-30 14:23:41 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-05-15 19:25:49 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2020-04-28 00:28:00 +00:00
|
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
2020-04-27 12:57:47 +00:00
|
|
|
|
2020-05-15 19:25:49 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
|
|
|
)
|
2020-04-27 12:57:47 +00:00
|
|
|
|
|
|
|
type TypesTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
|
|
|
|
|
|
|
|
testcases := []struct {
|
|
|
|
name string
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions []types.Permission
|
|
|
|
pubProposal types.PubProposal
|
2020-04-27 12:57:47 +00:00
|
|
|
expectHasPermissions bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "normal (single permission)",
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions: []types.Permission{types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
|
|
|
},
|
|
|
|
}}},
|
2020-04-28 00:28:00 +00:00
|
|
|
pubProposal: paramstypes.NewParameterChangeProposal(
|
2020-04-27 12:57:47 +00:00
|
|
|
"A Title",
|
|
|
|
"A description of this proposal.",
|
2020-04-28 00:28:00 +00:00
|
|
|
[]paramstypes.ParamChange{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
Value: `{"denom": "usdx", "amount": "1000000"}`,
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
expectHasPermissions: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "normal (multiple permissions)",
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions: []types.Permission{
|
|
|
|
types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
|
|
|
},
|
|
|
|
}},
|
2020-05-15 19:25:49 +00:00
|
|
|
types.TextPermission{},
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
2020-04-28 00:28:00 +00:00
|
|
|
pubProposal: govtypes.NewTextProposal("A Proposal Title", "A description of this proposal"),
|
2020-04-27 12:57:47 +00:00
|
|
|
expectHasPermissions: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "overruling permission",
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions: []types.Permission{
|
|
|
|
types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
|
|
|
},
|
|
|
|
}},
|
2020-05-15 19:25:49 +00:00
|
|
|
types.GodPermission{},
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
2020-04-28 00:28:00 +00:00
|
|
|
pubProposal: paramstypes.NewParameterChangeProposal(
|
2020-04-27 12:57:47 +00:00
|
|
|
"A Title",
|
|
|
|
"A description of this proposal.",
|
2020-04-28 00:28:00 +00:00
|
|
|
[]paramstypes.ParamChange{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "CollateralParams",
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
Value: `[]`,
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
expectHasPermissions: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no permissions",
|
|
|
|
permissions: nil,
|
2020-04-28 00:28:00 +00:00
|
|
|
pubProposal: paramstypes.NewParameterChangeProposal(
|
2020-04-27 12:57:47 +00:00
|
|
|
"A Title",
|
|
|
|
"A description of this proposal.",
|
2020-04-28 00:28:00 +00:00
|
|
|
[]paramstypes.ParamChange{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "CollateralParams",
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
Value: `[]`,
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
expectHasPermissions: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "split permissions",
|
|
|
|
// These permissions looks like they allow the param change proposal, however a proposal must pass a single permission independently of others.
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions: []types.Permission{
|
|
|
|
types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
|
|
|
},
|
|
|
|
}},
|
2020-05-15 19:25:49 +00:00
|
|
|
types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtParams",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
2020-04-28 00:28:00 +00:00
|
|
|
pubProposal: paramstypes.NewParameterChangeProposal(
|
2020-04-27 12:57:47 +00:00
|
|
|
"A Title",
|
|
|
|
"A description of this proposal.",
|
2020-04-28 00:28:00 +00:00
|
|
|
[]paramstypes.ParamChange{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
Value: `{"denom": "usdx", "amount": "1000000"}`,
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtParams",
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
Value: `[]`,
|
2020-04-27 12:57:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
expectHasPermissions: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unregistered proposal",
|
2020-05-15 19:25:49 +00:00
|
|
|
permissions: []types.Permission{
|
|
|
|
types.SimpleParamChangePermission{
|
|
|
|
AllowedParams: types.AllowedParams{
|
2020-04-27 12:57:47 +00:00
|
|
|
{
|
|
|
|
Subspace: "cdp",
|
|
|
|
Key: "DebtThreshold",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
2020-04-30 15:33:10 +00:00
|
|
|
pubProposal: UnregisteredPubProposal{govtypes.TextProposal{Title: "A Title", Description: "A description."}},
|
2020-04-27 12:57:47 +00:00
|
|
|
expectHasPermissions: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testcases {
|
|
|
|
suite.Run(tc.name, func() {
|
2020-05-15 19:25:49 +00:00
|
|
|
tApp := app.NewTestApp()
|
|
|
|
ctx := tApp.NewContext(true, abci.Header{})
|
|
|
|
tApp.InitializeFromGenesisStates()
|
|
|
|
com := types.NewCommittee(
|
2020-04-27 12:57:47 +00:00
|
|
|
12,
|
|
|
|
"a description of this committee",
|
|
|
|
nil,
|
|
|
|
tc.permissions,
|
|
|
|
d("0.5"),
|
|
|
|
24*time.Hour,
|
|
|
|
)
|
|
|
|
suite.Equal(
|
|
|
|
tc.expectHasPermissions,
|
2020-05-15 19:25:49 +00:00
|
|
|
com.HasPermissionsFor(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
|
2020-04-27 12:57:47 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTypesTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(TypesTestSuite))
|
|
|
|
}
|