From 4e49c47eaac7ef9a19be365df551ea4d6e56d272 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:01:23 +0100 Subject: [PATCH] fix: adding checks to ensure coin denoms are sorted in `Balance` during `Validate` (backport #9829) (#10849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding checks to ensure denoms are sorted (cherry picked from commit ce1e65083ea7fcbb744a3927de8be80f1f1bf77f) * updating changelog (cherry picked from commit 2cea5e5750d220d476ddc3184d19cdf0a7de52c5) # Conflicts: # CHANGELOG.md * refactoring balance.coin validation (cherry picked from commit 40d22c7ab3a385bde480ce0b10d9920d8646d67e) * adding 0 value coin test case (cherry picked from commit 2468b64cffd889e626ec6b7e047459ed39cafd58) * added valid sorted coin testcase (cherry picked from commit 66b91ee7c7c9f916282d6cd1fffdfebf4cdf74ab) * updating changelog (cherry picked from commit 59b788a3bb4ecf7fc95c062551898e4db505765b) # Conflicts: # CHANGELOG.md * conflicts Co-authored-by: Spoorthi <9302666+spoo-bar@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer --- CHANGELOG.md | 3 +-- x/bank/types/balance_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c985aa0f8cb9..bbf5491b1e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,8 +38,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -## [v0.45.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.0) - 2021-12-07 - ### State Machine Breaking * (auth) [\#10536](https://github.com/cosmos/cosmos-sdk/pull/10536]) Enable `SetSequence` for `ModuleAccount`. @@ -63,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt`. * [#10725](https://github.com/cosmos/cosmos-sdk/pull/10725) populate `ctx.ConsensusParams` for begin/end blockers. +* [\#9829](https://github.com/cosmos/cosmos-sdk/pull/9829) Fixed Coin denom sorting not being checked during `Balance.Validate` check. Refactored the Validation logic to use `Coins.Validate` for `Balance.Coins` ## [v0.44.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.5) - 2021-12-02 diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index 85ed43d035c2..2d035ebdfd06 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -90,6 +90,29 @@ func TestBalanceValidate(t *testing.T) { }, true, }, + { + "0 value coin", + bank.Balance{ + Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", + Coins: sdk.Coins{ + sdk.NewInt64Coin("atom", 0), + sdk.NewInt64Coin("zatom", 2), + }, + }, + true, + }, + { + "unsorted coins", + bank.Balance{ + Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", + Coins: sdk.Coins{ + sdk.NewInt64Coin("atom", 2), + sdk.NewInt64Coin("zatom", 2), + sdk.NewInt64Coin("batom", 12), + }, + }, + true, + }, { "valid sorted coins", bank.Balance{