Skip to content

Commit

Permalink
Check for invalid addresses in SetAffiliateWhitelist (#2594)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding authored Nov 22, 2024
1 parent e3d812e commit 395f448
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit 395f448

Please sign in to comment.