Skip to content

Commit

Permalink
Int64 to math (quicksilver-zone#1319)
Browse files Browse the repository at this point in the history
* fix zones page with 1e18 decimals

* fix nil reference

* remove int64 output in delegations query

* remove int64s

* add test to validate int64 fix

* lint
  • Loading branch information
Joe Bowman authored Mar 22, 2024
1 parent 47d8bc1 commit 60e77b3
Show file tree
Hide file tree
Showing 40 changed files with 1,261 additions and 1,226 deletions.
8 changes: 5 additions & 3 deletions app/upgrades/v1_5.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"time"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -526,16 +528,16 @@ func collateRequeuedWithdrawals(ctx sdk.Context, appKeepers *keepers.AppKeepers)
}
// merge distributions
newRecord.Distribution = func(dist1, dist2 []*icstypes.Distribution) []*icstypes.Distribution {
distMap := map[string]uint64{}
distMap := map[string]math.Int{}
for _, dist := range dist1 {
distMap[dist.Valoper] = dist.Amount
}

for _, dist := range dist2 {
if _, ok = distMap[dist.Valoper]; !ok {
distMap[dist.Valoper] = 0
distMap[dist.Valoper] = math.ZeroInt()
}
distMap[dist.Valoper] += dist.Amount
distMap[dist.Valoper] = distMap[dist.Valoper].Add(dist.Amount)
}

out := make([]*icstypes.Distribution, 0, len(distMap))
Expand Down
60 changes: 30 additions & 30 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 600,
Amount: math.NewInt(600),
},
{
Valoper: "cosmosvaloper111111111111111111111111111111111111",
Amount: 400,
Amount: math.NewInt(400),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 200,
Amount: math.NewInt(200),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(1000)),
Expand All @@ -440,19 +440,19 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 600,
Amount: math.NewInt(600),
},
{
Valoper: "cosmosvaloper111111111111111111111111111111111111",
Amount: 800,
Amount: math.NewInt(800),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 800,
Amount: math.NewInt(800),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 800,
Amount: math.NewInt(800),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(2000)),
Expand All @@ -471,19 +471,19 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 600,
Amount: math.NewInt(600),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 200,
Amount: math.NewInt(200),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 800,
Amount: math.NewInt(800),
},
{
Valoper: "cosmosvaloper144444444444444444444444444444444444",
Amount: 2000,
Amount: math.NewInt(2000),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(3000)),
Expand All @@ -502,19 +502,19 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 800,
Amount: math.NewInt(800),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 400,
Amount: math.NewInt(400),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 1200,
Amount: math.NewInt(1200),
},
{
Valoper: "cosmosvaloper144444444444444444444444444444444444",
Amount: 2200,
Amount: math.NewInt(2200),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(4000)),
Expand All @@ -532,19 +532,19 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 1000,
Amount: math.NewInt(1000),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 1200,
Amount: math.NewInt(1200),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 1200,
Amount: math.NewInt(1200),
},
{
Valoper: "cosmosvaloper144444444444444444444444444444444444",
Amount: 1600,
Amount: math.NewInt(1600),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(5000)),
Expand All @@ -562,23 +562,23 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 1500,
Amount: math.NewInt(1500),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 1500,
Amount: math.NewInt(1500),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 1500,
Amount: math.NewInt(1500),
},
{
Valoper: "cosmosvaloper144444444444444444444444444444444444",
Amount: 1500,
Amount: math.NewInt(1500),
},
{
Valoper: "cosmosvaloper155555555555555555555555555555555555",
Amount: 1500,
Amount: math.NewInt(1500),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(6000)),
Expand All @@ -596,23 +596,23 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
Distribution: []*icstypes.Distribution{
{
Valoper: "cosmosvaloper100000000000000000000000000000000000",
Amount: 1750,
Amount: math.NewInt(1750),
},
{
Valoper: "cosmosvaloper122222222222222222222222222222222222",
Amount: 1750,
Amount: math.NewInt(1750),
},
{
Valoper: "cosmosvaloper133333333333333333333333333333333333",
Amount: 1750,
Amount: math.NewInt(1750),
},
{
Valoper: "cosmosvaloper144444444444444444444444444444444444",
Amount: 1750,
Amount: math.NewInt(1750),
},
{
Valoper: "cosmosvaloper155555555555555555555555555555555555",
Amount: 1750,
Amount: math.NewInt(1750),
},
},
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(7000)),
Expand Down Expand Up @@ -701,7 +701,7 @@ func (s *AppTestSuite) TestV010500UpgradeHandler() {
s.True(wdr.Requeued)
s.True(wdr.Acknowledged)
s.Equal(wdr.Amount, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(3600))))
s.ElementsMatch(wdr.Distribution, []*icstypes.Distribution{{Valoper: "cosmosvaloper100000000000000000000000000000000000", Amount: 1200}, {Valoper: "cosmosvaloper111111111111111111111111111111111111", Amount: 1200}, {Valoper: "cosmosvaloper122222222222222222222222222222222222", Amount: 1000}, {Valoper: "cosmosvaloper133333333333333333333333333333333333", Amount: 800}})
s.ElementsMatch(wdr.Distribution, []*icstypes.Distribution{{Valoper: "cosmosvaloper100000000000000000000000000000000000", Amount: math.NewInt(1200)}, {Valoper: "cosmosvaloper111111111111111111111111111111111111", Amount: math.NewInt(1200)}, {Valoper: "cosmosvaloper122222222222222222222222222222222222", Amount: math.NewInt(1000)}, {Valoper: "cosmosvaloper133333333333333333333333333333333333", Amount: math.NewInt(800)}})

wdrs := app.InterchainstakingKeeper.AllWithdrawalRecords(ctx)
s.Equal(35, len(wdrs)) // 8 from requeue collation, 27 new records from restituion
Expand Down
Loading

0 comments on commit 60e77b3

Please sign in to comment.