fix: add check for duplicate continuous fund in x/protocolpool genesis (#24559)
This commit is contained in:
parent
6a54aaa90e
commit
bb91d18a01
@ -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()
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user