Skip to content

Commit

Permalink
remove osmoutils method for coins to coin array
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jan 7, 2024
1 parent 6d6cd16 commit ba0c68e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 63 deletions.
3 changes: 1 addition & 2 deletions app/upgrades/v21/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/osmosis/osmoutils"
v21 "github.com/osmosis-labs/osmosis/v21/app/upgrades/v21"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -56,7 +55,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal([]sdk.Coin{}, allProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool)
s.Require().Equal([]sdk.Coin{}, allProtocolRevenue.TakerFeesTracker.TakerFeesToStakers)
// s.Require().Equal(sdk.Coins(nil), allProtocolRevenue.TxFeesTracker.TxFees)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfits), allProtocolRevenue.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(cyclicArbProfits), allProtocolRevenue.CyclicArbTracker.CyclicArb)

}

Expand Down
13 changes: 0 additions & 13 deletions osmoutils/coin_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,3 @@ func ConvertCoinArrayToCoins(coinArray []sdk.Coin) sdk.Coins {
}
return coins
}

func ConvertCoinsToCoinArray(coins sdk.Coins) []sdk.Coin {
if coins == nil {
return []sdk.Coin(nil)
}

coinArray := make([]sdk.Coin, len(coins))
for i := len(coins) - 1; i >= 0; i-- {
coinArray[i] = coins[i]
}

return coinArray
}
32 changes: 0 additions & 32 deletions osmoutils/coin_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,35 +323,3 @@ func TestConvertCoinArrayToCoins(t *testing.T) {
})
}
}

func TestConvertCoinsToCoinArray(t *testing.T) {
tests := []struct {
name string
coins sdk.Coins
expectedCoinArray []sdk.Coin
}{
{
name: "Empty input",
coins: sdk.NewCoins(),
expectedCoinArray: []sdk.Coin{},
},
{
name: "Single coin",
coins: sdk.NewCoins(sdk.NewCoin("atom", osmomath.NewInt(100000000))),
expectedCoinArray: []sdk.Coin{sdk.NewCoin("atom", osmomath.NewInt(100000000))},
},
{
name: "Multiple coins",
coins: sdk.NewCoins(sdk.NewCoin("atom", osmomath.NewInt(100000000)), sdk.NewCoin("usdc", osmomath.NewInt(500000000))),
expectedCoinArray: []sdk.Coin{sdk.NewCoin("atom", osmomath.NewInt(100000000)), sdk.NewCoin("usdc", osmomath.NewInt(500000000))},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := osmoutils.ConvertCoinsToCoinArray(test.coins)
require.Equal(t, result, test.expectedCoinArray)

})
}
}
4 changes: 2 additions & 2 deletions x/protorev/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package keeper_test

import "github.com/osmosis-labs/osmosis/osmoutils"
import sdk "github.com/cosmos/cosmos-sdk/types"

// TestInitGenesis tests the initialization and export of the module's genesis state.
func (s *KeeperTestSuite) TestInitGenesis() {
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *KeeperTestSuite) TestInitGenesis() {
s.Require().Equal(profits, exportedGenesis.Profits)

cyclicArbProfit := s.App.ProtoRevKeeper.GetCyclicArbProfitTrackerValue(s.Ctx)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfit), exportedGenesis.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(cyclicArbProfit), exportedGenesis.CyclicArbTracker.CyclicArb)

cyclicArbProfitAccountingHeight := s.App.ProtoRevKeeper.GetCyclicArbProfitTrackerStartHeight(s.Ctx)
s.Require().Equal(cyclicArbProfitAccountingHeight, exportedGenesis.CyclicArbTracker.HeightAccountingStartsFrom)
Expand Down
13 changes: 6 additions & 7 deletions x/protorev/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v21/app/apptesting"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"

Expand Down Expand Up @@ -419,9 +418,9 @@ func (s *KeeperTestSuite) TestGetAllProtocolRevenueGRPCQuery() {
// Check protocol revenue
res, err = s.queryClient.GetAllProtocolRevenue(sdk.WrapSDKContext(s.Ctx), req)
s.Require().NoError(err)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfits), res.AllProtocolRevenue.CyclicArbTracker.CyclicArb)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToStakers), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToCommunityPool), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool)
s.Require().Equal([]sdk.Coin(cyclicArbProfits), res.AllProtocolRevenue.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToStakers), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToCommunityPool), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool)

// A second round of the same thing
// Swap on a pool to charge taker fee
Expand All @@ -441,7 +440,7 @@ func (s *KeeperTestSuite) TestGetAllProtocolRevenueGRPCQuery() {
// Check protocol revenue
res, err = s.queryClient.GetAllProtocolRevenue(sdk.WrapSDKContext(s.Ctx), req)
s.Require().NoError(err)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfits.Add(cyclicArbProfits...)), res.AllProtocolRevenue.CyclicArbTracker.CyclicArb)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToStakers.Add(expectedTakerFeeToStakers...)), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToCommunityPool.Add(expectedTakerFeeToCommunityPool...)), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool)
s.Require().Equal([]sdk.Coin(cyclicArbProfits.Add(cyclicArbProfits...)), res.AllProtocolRevenue.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToStakers.Add(expectedTakerFeeToStakers...)), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToCommunityPool.Add(expectedTakerFeeToCommunityPool...)), res.AllProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool)
}
13 changes: 6 additions & 7 deletions x/protorev/keeper/protorev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/osmoutils"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"
"github.com/osmosis-labs/osmosis/v21/x/protorev/types"
)
Expand Down Expand Up @@ -369,9 +368,9 @@ func (s *KeeperTestSuite) TestGetAllProtocolRevenue() {

// Check protocol revenue
allProtoRev = s.App.ProtoRevKeeper.GetAllProtocolRevenue(s.Ctx)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfits), allProtoRev.CyclicArbTracker.CyclicArb)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToStakers), allProtoRev.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToCommunityPool), allProtoRev.TakerFeesTracker.TakerFeesToCommunityPool)
s.Require().Equal([]sdk.Coin(cyclicArbProfits), allProtoRev.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToStakers), allProtoRev.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToCommunityPool), allProtoRev.TakerFeesTracker.TakerFeesToCommunityPool)

// A second round of the same thing
// Swap on a pool to charge taker fee
Expand All @@ -390,7 +389,7 @@ func (s *KeeperTestSuite) TestGetAllProtocolRevenue() {

// Check protocol revenue
allProtoRev = s.App.ProtoRevKeeper.GetAllProtocolRevenue(s.Ctx)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(cyclicArbProfits.Add(cyclicArbProfits...)), allProtoRev.CyclicArbTracker.CyclicArb)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToStakers.Add(expectedTakerFeeToStakers...)), allProtoRev.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal(osmoutils.ConvertCoinsToCoinArray(expectedTakerFeeToCommunityPool.Add(expectedTakerFeeToCommunityPool...)), allProtoRev.TakerFeesTracker.TakerFeesToCommunityPool)
s.Require().Equal([]sdk.Coin(cyclicArbProfits.Add(cyclicArbProfits...)), allProtoRev.CyclicArbTracker.CyclicArb)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToStakers.Add(expectedTakerFeeToStakers...)), allProtoRev.TakerFeesTracker.TakerFeesToStakers)
s.Require().Equal([]sdk.Coin(expectedTakerFeeToCommunityPool.Add(expectedTakerFeeToCommunityPool...)), allProtoRev.TakerFeesTracker.TakerFeesToCommunityPool)
}

0 comments on commit ba0c68e

Please sign in to comment.