Skip to content

Commit

Permalink
Feature/86_avoid-panic-in-ibc-begin-end (#90)
Browse files Browse the repository at this point in the history
* feature: Fixes #86 Avoid panic in ibc begin/end block (FundCommunityPoolFromModule)

* test(gov): add testcase

* docs: update CHANGELOG.md

* fix(golint): gosec G115

---------

Co-authored-by: Doan Phi Hung <[email protected]>
  • Loading branch information
InnerPeace080 and hugjobk authored Oct 21, 2024
1 parent 73fbf92 commit 7b800b9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Ref: https://keepachangelog.com/en/1.1.0/

- (amino) [#73](https://github.com/titantkx/titan/issues/73) Add regis amino codec of `nftmint` and `validatorreward` module for `gov`,`authz`,`group`.

### Bug Fixes

- (distribution) [#86](https://github.com/titantkx/titan/issues/86) Avoid panic in abci endblocker from `gov` module.

### Miscellaneous

- (Makefile) Update to use fork version of ignite cli.
Expand Down
2 changes: 0 additions & 2 deletions testutil/nullify/nullify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func Fill(x interface{}) interface{} {
case reflect.Slice:
for i := 0; i < v.Len(); i++ {
obj := v.Index(i)
//nolint:gosec
objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface()
objPt = Fill(objPt)
obj.Set(reflect.ValueOf(objPt))
Expand All @@ -47,7 +46,6 @@ func Fill(x interface{}) interface{} {
s := reflect.ValueOf(coins).Elem()
f.Set(s)
default:
//nolint:gosec
objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface()
s := Fill(objPt)
f.Set(reflect.ValueOf(s))
Expand Down
8 changes: 5 additions & 3 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func NewKeeper(
// The amount is first added to the distribution module account and then directly
// added to the pool. An error is returned if the amount cannot be sent to the
// module account.
func (k Keeper) FundCommunityPoolFromModule(ctx sdk.Context, amount sdk.Coins, senderModule string) error {
if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, senderModule, types.ModuleName, amount); err != nil {
func (k Keeper) FundCommunityPoolFromModule(ctx sdk.Context, amounts sdk.Coins, senderModule string) error {
// ensure amount not contains zero
amounts = sdk.NewCoins(amounts...)
if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, senderModule, types.ModuleName, amounts); err != nil {
return err
}

feePool := k.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...)
feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amounts...)...)
k.SetFeePool(ctx, feePool)

return nil
Expand Down
8 changes: 8 additions & 0 deletions x/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ func TestValidateInitialDeposit(t *testing.T) {
minInitialDepositPercent: 0,
initialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount*baseDepositTestPercent/100))),
},
"0 initial percent, with zero amount of another token: success": {
minDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount))),
minInitialDepositPercent: 0,
initialDeposit: []sdk.Coin{
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount*baseDepositTestPercent/100)),
sdk.NewCoin("test", sdk.NewInt(0)),
},
},
}

for name, tc := range testcases {
Expand Down
2 changes: 2 additions & 0 deletions x/nftmint/client/cli/query_minting_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestListMintingInfo(t *testing.T) {
t.Run("ByOffset", func(t *testing.T) {
step := 2
for i := 0; i < len(objs); i += step {
//nolint:gosec // G115
args := request(nil, uint64(i), uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListMintingInfo(), args)
require.NoError(t, err)
Expand All @@ -134,6 +135,7 @@ func TestListMintingInfo(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(objs); i += step {
//nolint:gosec // G115
args := request(next, 0, uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListMintingInfo(), args)
require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions x/nftmint/keeper/query_minting_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestMintingInfoQueryPaginated(t *testing.T) {
t.Run("ByOffset", func(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
//nolint:gosec // G115
resp, err := keeper.MintingInfos(wctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.MintingInfo), step)
Expand All @@ -101,6 +102,7 @@ func TestMintingInfoQueryPaginated(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
//nolint:gosec // G115
resp, err := keeper.MintingInfos(wctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.MintingInfo), step)
Expand Down
6 changes: 3 additions & 3 deletions x/tokenfactory/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
var (
KeyDenomCreationFee = []byte("DenomCreationFee")
KeyDenomCreationGasConsume = []byte("DenomCreationGasConsume")

// chosen as an arbitrary large number, less than the max_gas_wanted_per_tx in config.
DefaultCreationGasFee = 1_000_000
)

// chosen as an arbitrary large number, less than the max_gas_wanted_per_tx in config.
const DefaultCreationGasFee = 1_000_000

// ParamTable for gamm module.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
Expand Down

0 comments on commit 7b800b9

Please sign in to comment.