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

feat(x/distribution): panic on set community pool #23507

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions x/distribution/types/fee_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (f FeePool) ValidateGenesis() error {
return fmt.Errorf("negative DecimalPool in distribution fee pool, is %v", f.DecimalPool)
}

if f.CommunityPool.IsAnyNegative() { // TODO(@julienrbrt) in v0.53, panic if the community pool is set
return fmt.Errorf("negative CommunityPool in distribution fee pool, is %v", f.CommunityPool)
if !f.CommunityPool.IsZero() {
panic(fmt.Sprintf("CommunityPool must be zero in distribution fee pool as it should be specified in protocolpool, current value: %v", f.CommunityPool))
}

return nil
Expand Down
57 changes: 50 additions & 7 deletions x/distribution/types/fee_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,55 @@ import (
)

func TestValidateGenesis(t *testing.T) {
fp := types.InitialFeePool()
require.Nil(t, fp.ValidateGenesis())
testCases := []struct {
name string
feePool types.FeePool
shouldPanic bool
}{
{
name: "valid fee pool",
feePool: types.FeePool{
DecimalPool: sdk.DecCoins{},
CommunityPool: sdk.DecCoins{},
},
shouldPanic: false,
},
{
name: "negative decimal pool",
feePool: types.FeePool{
DecimalPool: sdk.DecCoins{
sdk.DecCoin{Denom: "stake", Amount: sdk.NewDec(-1)},
},
CommunityPool: sdk.DecCoins{},
},
shouldPanic: false,
},
{
name: "non-zero community pool",
feePool: types.FeePool{
DecimalPool: sdk.DecCoins{},
CommunityPool: sdk.DecCoins{
sdk.DecCoin{Denom: "stake", Amount: sdk.NewDec(1)},
},
},
shouldPanic: true,
},
}

fp2 := types.FeePool{CommunityPool: sdk.DecCoins{{Denom: "stake", Amount: math.LegacyNewDec(-1)}}}
require.NotNil(t, fp2.ValidateGenesis())

fp3 := types.FeePool{DecimalPool: sdk.DecCoins{{Denom: "stake", Amount: math.LegacyNewDec(-1)}}}
require.NotNil(t, fp3.ValidateGenesis())
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.shouldPanic {
require.Panics(t, func() {
tc.feePool.ValidateGenesis()
}, "expected ValidateGenesis to panic with non-zero community pool")
} else {
err := tc.feePool.ValidateGenesis()
if tc.feePool.DecimalPool.IsAnyNegative() {
require.Error(t, err)
} else {
require.NoError(t, err)
}
}
})
}
}
Loading