-
mergify[bot] authored
Closes: #XXX ## What is the purpose of the change The context parameter in `getProportions` is unused. Removed the unused parameter. ## Documentation and Release Note - Does this pull request introduce a new feature or user-facing behavior changes? no - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? no - How is the feature or change documented? not applicable (cherry picked from commit 03504abd ) Co-authored-by:
Roman <roman@osmosis.team>
Unverified304db139
package keeper_test
import (
"fmt"
"testing"
"time"
"github.com/cosmos/btcutil/bech32"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/osmosis-labs/osmosis/v10/app/apptesting"
"github.com/osmosis-labs/osmosis/v10/osmoutils"
lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types"
"github.com/osmosis-labs/osmosis/v10/x/mint/keeper"
"github.com/osmosis-labs/osmosis/v10/x/mint/types"
poolincentivestypes "github.com/osmosis-labs/osmosis/v10/x/pool-incentives/types"
)
type KeeperTestSuite struct {
apptesting.KeeperTestHelper
queryClient types.QueryClient
}
var (
testAddressOne = sdk.AccAddress([]byte("addr1---------------"))
testAddressTwo = sdk.AccAddress([]byte("addr2---------------"))
testAddressThree = sdk.AccAddress([]byte("addr3---------------"))
testAddressFour = sdk.AccAddress([]byte("addr4---------------"))
)
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
func (suite *KeeperTestSuite) SetupTest() {
suite.Setup()
suite.queryClient = types.NewQueryClient(suite.QueryHelper)
params := suite.App.MintKeeper.GetParams(suite.Ctx)
params.ReductionPeriodInEpochs = 10
suite.App.MintKeeper.SetParams(suite.Ctx, params)
}
// setupDeveloperVestingModuleAccountTest sets up test cases that utilize developer vesting
// module account logic. It reverts some default logic added by suite.Setup()
// Specifically, it removes the developer vesting module account
// from account keeper if isDeveloperModuleAccountCreated is true.
// Additionally, it initializes suite's Ctx with blockHeight
func (suite *KeeperTestSuite) setupDeveloperVestingModuleAccountTest(blockHeight int64, isDeveloperModuleAccountCreated bool) {
suite.Setup()
// Reset height to the desired value since test suite setup initialized
// it to 1.
bankKeeper := suite.App.BankKeeper
accountKeeper := suite.App.AccountKeeper
suite.Ctx = suite.Ctx.WithBlockHeader(tmproto.Header{Height: blockHeight})
if !isDeveloperModuleAccountCreated {
// Remove the developer vesting account since suite setup creates and initializes it.
// This environment w/o the developer vesting account configured is necessary for
// testing edge cases of multiple tests.
developerVestingAccount := accountKeeper.GetAccount(suite.Ctx, accountKeeper.GetModuleAddress(types.DeveloperVestingModuleAcctName))
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
accountKeeper.RemoveAccount(suite.Ctx, developerVestingAccount)
bankKeeper.BurnCoins(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(keeper.DeveloperVestingAmount))))
// If developer module account is created, the suite.Setup() also sets the offset,
// therefore, we should reset it to 0 to set up the environment truly w/o the module account.
supplyOffset := bankKeeper.GetSupplyOffset(suite.Ctx, sdk.DefaultBondDenom)
bankKeeper.AddSupplyOffset(suite.Ctx, sdk.DefaultBondDenom, supplyOffset.Mul(sdk.NewInt(-1)))
suite.Require().Equal(sdk.ZeroInt(), bankKeeper.GetSupplyOffset(suite.Ctx, sdk.DefaultBondDenom))
}
}
// TestGetProportions tests that mint allocations are computed as expected.
func (suite *KeeperTestSuite) TestGetProportions() {
complexRatioDec := sdk.NewDecWithPrec(131, 3).Quo(sdk.NewDecWithPrec(273, 3))
tests := []struct {
name string
ratio sdk.Dec
expectedCoin sdk.Coin
expectedError error
mintedCoin sdk.Coin
}{
{
name: "0 * 0.2 = 0",
mintedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)),
ratio: sdk.NewDecWithPrec(2, 1),
expectedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)),
},
{
name: "100000 * 0.2 = 20000",
mintedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000)),
ratio: sdk.NewDecWithPrec(2, 1),
expectedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000).Quo(sdk.NewInt(5))),
},
{
name: "123456 * 2/3 = 82304",
mintedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(123456)),
ratio: sdk.NewDecWithPrec(2, 1).Quo(sdk.NewDecWithPrec(3, 1)),
expectedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(82304)),
},
{
name: "54617981 * .131/.273 approx = 2.62",
mintedCoin: sdk.NewCoin("uosmo", sdk.NewInt(54617981)),
ratio: complexRatioDec, // .131/.273
// TODO: Should not be truncated. Remove truncation after rounding errors are addressed and resolved.
// Ref: https://github.com/osmosis-labs/osmosis/issues/1917
expectedCoin: sdk.NewCoin("uosmo", sdk.NewInt(54617981).ToDec().Mul(complexRatioDec).TruncateInt()),
},
{
name: "1 * 1 = 1",
mintedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)),
ratio: sdk.NewDec(1),
expectedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)),
},
{
name: "1 * 1.01 - error, ratio must be <= 1",
mintedCoin: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)),
ratio: sdk.NewDecWithPrec(101, 2),
expectedError: keeper.ErrInvalidRatio{ActualRatio: sdk.NewDecWithPrec(101, 2)},
},
}
for _, tc := range tests {
suite.Run(tc.name, func() {
coin, err := keeper.GetProportions(tc.mintedCoin, tc.ratio)
if tc.expectedError != nil {
suite.Require().Equal(tc.expectedError, err)
suite.Require().Equal(sdk.Coin{}, coin)