Skip to content

Commit

Permalink
Problem: negative coin amount error when query supply liquid of non B…
Browse files Browse the repository at this point in the history
…aseCoinUnit
  • Loading branch information
mmsqe committed Dec 30, 2024
1 parent d1d09c9 commit 7d46453
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [#1088](https://github.com/crypto-org-chain/chain-main/pull/1088) Upgrade solomachine to `v0.1.4` and ibc-go to `v8.5.1`.
* [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Update cometbft to `0.38.13`, sdk to `v0.50.10` and memiavl to latest.
- [#1091](https://github.com/crypto-org-chain/chain-main/pull/1091) Upgrade cometbft to v0.38.13, cosmos-sdk to `v0.50.10`.
- [#1099](https://github.com/crypto-org-chain/chain-main/pull/1099) Avoid negative coin amount error when query supply liquid of non BaseCoinUnit.

*Dec 6, 2023*

Expand Down
35 changes: 35 additions & 0 deletions integration_tests/test_ibc_extended.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hashlib
import json
from pathlib import Path

import pytest
Expand All @@ -19,6 +20,26 @@ def cluster(worker_index, pytestconfig, tmp_path_factory):
)


def fund_community_pool(self, amt, event_query_tx=True, **kwargs):
rsp = json.loads(
self.raw(
"tx",
"distribution",
"fund-community-pool",
amt,
"-y",
home=self.data_dir,
keyring_backend="test",
chain_id=self.chain_id,
node=self.node_rpc,
**kwargs,
)
)
if rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp


# 3 accounts ibc test
# ibc-0 (A,B) ibc-1 (C)
# EscrowAddress: sha256-hash of ibc-version,port-id,channel-id
Expand Down Expand Up @@ -74,3 +95,17 @@ def check_balance_change():

wait_for_fn("balance change", check_balance_change)
assert new_src_balance == amt2 + old_src_balance, new_src_balance

amt3 = 1
fund_community_pool(
cluster["ibc-1"].cosmos_cli(), f"{amt3}{ibc_denom}", from_=addr_1
)
cluster["ibc-1"].distribution_community()
res = cluster["ibc-1"].supply("liquid")
assert res == {
"supply": [
{"denom": denom, "amount": "260000000000"},
{"denom": ibc_denom, "amount": f"{amt - amt2 - amt3}"},
{"denom": "ibcfee", "amount": "100000000000"},
]
}
8 changes: 6 additions & 2 deletions x/supply/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/crypto-org-chain/chain-main/v4/config"
"github.com/crypto-org-chain/chain-main/v4/x/supply/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -92,7 +91,12 @@ func (k Keeper) GetVestingAccounts(ctx sdk.Context) types.VestingAccounts {

// GetTotalSupply returns the current total supply in the system
func (k Keeper) GetTotalSupply(ctx sdk.Context) sdk.Coins {
return sdk.NewCoins(k.bankKeeper.GetSupply(ctx, config.BaseCoinUnit))
var totalSupply sdk.Coins
k.bankKeeper.IterateTotalSupply(ctx, func(coin sdk.Coin) bool {
totalSupply = totalSupply.Add(coin)
return false
})
return totalSupply

Check warning on line 99 in x/supply/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/supply/keeper/keeper.go#L94-L99

Added lines #L94 - L99 were not covered by tests
}

// GetUnvestedSupply returns total unvested supply
Expand Down
2 changes: 1 addition & 1 deletion x/supply/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// creating a x/supply keeper.
type BankKeeper interface {
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetSupply(ctx context.Context, denom string) sdk.Coin
IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool)
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}

Expand Down

0 comments on commit 7d46453

Please sign in to comment.