diff --git a/x/protocolpool/types/genesis.go b/x/protocolpool/types/genesis.go index 407b9136d7..2e4aefaa2b 100644 --- a/x/protocolpool/types/genesis.go +++ b/x/protocolpool/types/genesis.go @@ -2,6 +2,7 @@ package types import ( "errors" + "fmt" "cosmossdk.io/math" ) @@ -33,5 +34,17 @@ func (gs *GenesisState) Validate() error { return errors.New("total percentage cannot be greater than 100") } + seenContinuousFunds := make(map[string]struct{}) + for _, fund := range gs.ContinuousFunds { + if err := fund.Validate(); err != nil { + return fmt.Errorf("invalid continuousfund: %w", err) + } + + if _, ok := seenContinuousFunds[fund.Recipient]; ok { + return fmt.Errorf("duplicated continuous fund recipient address: %s", fund.Recipient) + } + seenContinuousFunds[fund.Recipient] = struct{}{} + } + return gs.Params.Validate() } diff --git a/x/protocolpool/types/genesis_test.go b/x/protocolpool/types/genesis_test.go index 3d9531781e..e6567c4366 100644 --- a/x/protocolpool/types/genesis_test.go +++ b/x/protocolpool/types/genesis_test.go @@ -93,6 +93,39 @@ func TestValidateGenesis(t *testing.T) { }, expectedErr: "total percentage cannot be greater than 100", }, + { + name: "invalid genesis state with invalid continuous fund (percentage sum > 1)", + genesisState: &types.GenesisState{ + ContinuousFunds: []types.ContinuousFund{ + { + Recipient: "cosmos1dupaddress", + Percentage: math.LegacyMustNewDecFromStr("1.1"), + Expiry: nil, + }, + }, + Params: types.DefaultParams(), + }, + expectedErr: "percentage cannot be greater than one", + }, + { + name: "invalid genesis state with duplicate recipient addresses", + genesisState: &types.GenesisState{ + ContinuousFunds: []types.ContinuousFund{ + { + Recipient: "cosmos1dupaddress", + Percentage: math.LegacyMustNewDecFromStr("0.4"), + Expiry: nil, + }, + { + Recipient: "cosmos1dupaddress", // duplicate + Percentage: math.LegacyMustNewDecFromStr("0.3"), + Expiry: nil, + }, + }, + Params: types.DefaultParams(), + }, + expectedErr: "duplicated continuous fund recipient address", + }, } for _, tc := range tests {