Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for invalid addresses in SetAffiliateWhitelist #2594

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion protocol/x/affiliates/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,12 @@ func (k Keeper) SetAffiliateWhitelist(ctx sdk.Context, whitelist types.Affiliate
"taker fee share ppm %d is greater than the cap %d",
tier.TakerFeeSharePpm, types.AffiliatesRevSharePpmCap)
}
// Check for duplicate addresses.
for _, address := range tier.Addresses {
// Check for invalid addresses.
if _, err := sdk.AccAddressFromBech32(address); err != nil {
return errorsmod.Wrapf(types.ErrInvalidAddress, "address to whitelist: %s", address)
}
// Check for duplicate addresses.
if addressSet[address] {
return errorsmod.Wrapf(types.ErrDuplicateAffiliateAddressForWhitelist,
"address %s is duplicated in affiliate whitelist", address)
Expand Down
30 changes: 30 additions & 0 deletions protocol/x/affiliates/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,36 @@ func TestSetAffiliateWhitelist(t *testing.T) {
},
expectedError: types.ErrRevShareSafetyViolation,
},
{
name: "Invalid bech32 address present",
whitelist: types.AffiliateWhitelist{
Tiers: []types.AffiliateWhitelist_Tier{
{
Addresses: []string{
constants.AliceAccAddress.String(),
"dydxinvalidaddress",
},
TakerFeeSharePpm: 500_000, // 50%
},
},
},
expectedError: types.ErrInvalidAddress,
},
{
name: "Validator operator address not accepted",
whitelist: types.AffiliateWhitelist{
Tiers: []types.AffiliateWhitelist_Tier{
{
Addresses: []string{
constants.AliceAccAddress.String(),
"dydxvaloper1et2kxktzr6tav65uhrxsyr8gx82xvan6gl78xd",
},
TakerFeeSharePpm: 500_000, // 50%
},
},
},
expectedError: types.ErrInvalidAddress,
},
}

for _, tc := range testCases {
Expand Down
Loading