0g-chain/x/committee/keeper/committee_test.go

189 lines
4.3 KiB
Go
Raw Normal View History

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"
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
"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
permissions []types.Permission
pubProposal types.PubProposal
2020-04-27 12:57:47 +00:00
expectHasPermissions bool
}{
{
name: "normal (single permission)",
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)",
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
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",
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
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.
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
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",
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() {
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,
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))
}