From 00b4b2c37c9e22899cbffedc90c876357a56bd9d Mon Sep 17 00:00:00 2001 From: "Matt, Park" <45252226+mattverse@users.noreply.github.com> Date: Mon, 14 Mar 2022 13:15:55 +0900 Subject: [PATCH] Test improvisation for Superfluid (#1070) * add utility for SetupGammPoolsAndSuperfluidAssets * remove hardcoded gamm pool denoms * fix for main branch ctx => Ctx, app => App in tests * Test Changes * Add testing packages * Delete fmt * Fix lint * Remove multiple pacakges for apptesting * Add parameter for reward allocation * Improvements on test Co-authored-by: antstalepresh --- app/apptesting/test_suite.go | 110 ++++++++++++++++++ proto/osmosis/incentives/gauge.proto | 1 + x/incentives/types/gauge.pb.go | 5 +- x/superfluid/keeper/distribution_test.go | 20 +--- x/superfluid/keeper/hooks_test.go | 41 ++++--- .../keeper/intermediary_account_test.go | 67 +++++++++++ x/superfluid/keeper/keeper_test.go | 76 +----------- 7 files changed, 209 insertions(+), 111 deletions(-) diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index 261822fc258..ff46f5a2714 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -11,12 +11,19 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/osmosis-labs/osmosis/v7/app" + "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" + gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" + lockupkeeper "github.com/osmosis-labs/osmosis/v7/x/lockup/keeper" + lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types" + "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/crypto/ed25519" ) type KeeperTestHelper struct { @@ -99,3 +106,106 @@ func (keeperTestHelper *KeeperTestHelper) EndBlock() { reqEndBlock := abci.RequestEndBlock{Height: keeperTestHelper.Ctx.BlockHeight()} keeperTestHelper.App.EndBlocker(keeperTestHelper.Ctx, reqEndBlock) } + +func (keeperTestHelper *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdk.Int) { + validator, found := keeperTestHelper.App.StakingKeeper.GetValidator(keeperTestHelper.Ctx, valAddr) + keeperTestHelper.Require().True(found) + + // allocate reward tokens to distribution module + coins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, rewardAmt)} + err := simapp.FundModuleAccount(keeperTestHelper.App.BankKeeper, keeperTestHelper.Ctx, distrtypes.ModuleName, coins) + keeperTestHelper.Require().NoError(err) + + // allocate rewards to validator + keeperTestHelper.Ctx = keeperTestHelper.Ctx.WithBlockHeight(keeperTestHelper.Ctx.BlockHeight() + 1) + decTokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: sdk.NewDec(20000)}} + keeperTestHelper.App.DistrKeeper.AllocateTokensToValidator(keeperTestHelper.Ctx, validator, decTokens) +} + +// SetupGammPoolsWithBondDenomMultiplier uses given multipliers to set initial pool supply of bond denom. +func (keeperTestHelper *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []sdk.Dec) []gammtypes.PoolI { + keeperTestHelper.App.GAMMKeeper.SetParams(keeperTestHelper.Ctx, gammtypes.Params{ + PoolCreationFee: sdk.Coins{}, + }) + + bondDenom := keeperTestHelper.App.StakingKeeper.BondDenom(keeperTestHelper.Ctx) + //TODO: use sdk crypto instead of tendermint to generate address + acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) + + //fund account with pool creation fee + poolCreationFee := keeperTestHelper.App.GAMMKeeper.GetParams(keeperTestHelper.Ctx) + err := simapp.FundAccount(keeperTestHelper.App.BankKeeper, keeperTestHelper.Ctx, acc1, poolCreationFee.PoolCreationFee) + keeperTestHelper.Require().NoError(err) + + pools := []gammtypes.PoolI{} + + for index, multiplier := range multipliers { + token := fmt.Sprintf("token%d", index) + + uosmoAmount := gammtypes.InitPoolSharesSupply.ToDec().Mul(multiplier).RoundInt() + + err := simapp.FundAccount(keeperTestHelper.App.BankKeeper, keeperTestHelper.Ctx, acc1, sdk.NewCoins( + sdk.NewCoin(bondDenom, uosmoAmount.Mul(sdk.NewInt(10))), + sdk.NewInt64Coin(token, 100000), + )) + keeperTestHelper.NoError(err) + + var ( + defaultFutureGovernor = "" + + // pool assets + defaultFooAsset gammtypes.PoolAsset = gammtypes.PoolAsset{ + Weight: sdk.NewInt(100), + Token: sdk.NewCoin(bondDenom, uosmoAmount), + } + defaultBarAsset gammtypes.PoolAsset = gammtypes.PoolAsset{ + Weight: sdk.NewInt(100), + Token: sdk.NewCoin(token, sdk.NewInt(10000)), + } + poolAssets []gammtypes.PoolAsset = []gammtypes.PoolAsset{defaultFooAsset, defaultBarAsset} + ) + + poolId, err := keeperTestHelper.App.GAMMKeeper.CreateBalancerPool(keeperTestHelper.Ctx, acc1, balancer.PoolParams{ + SwapFee: sdk.NewDecWithPrec(1, 2), + ExitFee: sdk.NewDecWithPrec(1, 2), + }, poolAssets, defaultFutureGovernor) + keeperTestHelper.Require().NoError(err) + + pool, err := keeperTestHelper.App.GAMMKeeper.GetPool(keeperTestHelper.Ctx, poolId) + keeperTestHelper.Require().NoError(err) + + pools = append(pools, pool) + } + return pools +} + +// SwapAndSetSpotPrice runs a swap to set Spot price of a pool using arbitrary values +// returns spot price after the arbitrary swap +func (keeperTestHelper *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset gammtypes.PoolAsset, toAsset gammtypes.PoolAsset) sdk.Dec { + // create a dummy account + acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) + + // fund dummy account with tokens to swap + coins := sdk.Coins{sdk.NewInt64Coin(fromAsset.Token.Denom, 100000000000000)} + err := simapp.FundAccount(keeperTestHelper.App.BankKeeper, keeperTestHelper.Ctx, acc1, coins) + keeperTestHelper.Require().NoError(err) + + _, _, err = keeperTestHelper.App.GAMMKeeper.SwapExactAmountOut( + keeperTestHelper.Ctx, acc1, + poolId, fromAsset.Token.Denom, fromAsset.Token.Amount, + sdk.NewCoin(toAsset.Token.Denom, toAsset.Token.Amount.Quo(sdk.NewInt(4)))) + keeperTestHelper.Require().NoError(err) + + spotPrice, err := keeperTestHelper.App.GAMMKeeper.CalculateSpotPrice(keeperTestHelper.Ctx, poolId, toAsset.Token.Denom, fromAsset.Token.Denom) + keeperTestHelper.Require().NoError(err) + return spotPrice +} + +func (keeperTestHelper *KeeperTestHelper) LockTokens(addr sdk.AccAddress, coins sdk.Coins, duration time.Duration) (lockID uint64) { + msgServer := lockupkeeper.NewMsgServerImpl(keeperTestHelper.App.LockupKeeper) + err := simapp.FundAccount(keeperTestHelper.App.BankKeeper, keeperTestHelper.Ctx, addr, coins) + keeperTestHelper.Require().NoError(err) + msgResponse, err := msgServer.LockTokens(sdk.WrapSDKContext(keeperTestHelper.Ctx), lockuptypes.NewMsgLockTokens(addr, duration, coins)) + keeperTestHelper.Require().NoError(err) + return msgResponse.ID +} diff --git a/proto/osmosis/incentives/gauge.proto b/proto/osmosis/incentives/gauge.proto index 6a78f6cf9f0..8622c870be7 100644 --- a/proto/osmosis/incentives/gauge.proto +++ b/proto/osmosis/incentives/gauge.proto @@ -17,6 +17,7 @@ message Gauge { // these queries osmosis.lockup.QueryCondition distribute_to = 3 [ (gogoproto.nullable) = false ]; + // total amount of Coins that has been in the gauge. repeated cosmos.base.v1beta1.Coin coins = 4 [ (gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" diff --git a/x/incentives/types/gauge.pb.go b/x/incentives/types/gauge.pb.go index 4d22ccfff8d..f15ed43e558 100644 --- a/x/incentives/types/gauge.pb.go +++ b/x/incentives/types/gauge.pb.go @@ -37,8 +37,9 @@ type Gauge struct { // distribution incentives by third party // Rewards are distributed to lockups that are are returned by at least one of // these queries - DistributeTo types.QueryCondition `protobuf:"bytes,3,opt,name=distribute_to,json=distributeTo,proto3" json:"distribute_to"` - Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"` + DistributeTo types.QueryCondition `protobuf:"bytes,3,opt,name=distribute_to,json=distributeTo,proto3" json:"distribute_to"` + // total amount of Coins that has been in the gauge. + Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"` // distribution start time StartTime time.Time `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` NumEpochsPaidOver uint64 `protobuf:"varint,6,opt,name=num_epochs_paid_over,json=numEpochsPaidOver,proto3" json:"num_epochs_paid_over,omitempty"` diff --git a/x/superfluid/keeper/distribution_test.go b/x/superfluid/keeper/distribution_test.go index d4631c641dd..50db40f78a2 100644 --- a/x/superfluid/keeper/distribution_test.go +++ b/x/superfluid/keeper/distribution_test.go @@ -2,29 +2,11 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types" - minttypes "github.com/osmosis-labs/osmosis/v7/x/mint/types" "github.com/osmosis-labs/osmosis/v7/x/superfluid/keeper" ) -func (suite *KeeperTestSuite) allocateRewardsToValidator(valAddr sdk.ValAddress) { - validator, found := suite.App.StakingKeeper.GetValidator(suite.Ctx, valAddr) - suite.Require().True(found) - - // allocate reward tokens to distribution module - coins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20000))} - suite.App.BankKeeper.MintCoins(suite.Ctx, minttypes.ModuleName, coins) - suite.App.BankKeeper.SendCoinsFromModuleToModule(suite.Ctx, minttypes.ModuleName, distrtypes.ModuleName, coins) - - // allocate rewards to validator - suite.Ctx = suite.Ctx.WithBlockHeight(suite.Ctx.BlockHeight() + 1) - decTokens := sdk.DecCoins{{Denom: sdk.DefaultBondDenom, Amount: sdk.NewDec(20000)}} - suite.App.DistrKeeper.AllocateTokensToValidator(suite.Ctx, validator, decTokens) - suite.App.DistrKeeper.IncrementValidatorPeriod(suite.Ctx, validator) -} - func (suite *KeeperTestSuite) TestMoveSuperfluidDelegationRewardToGauges() { type gaugeChecker struct { intermediaryAccIndex uint64 @@ -94,7 +76,7 @@ func (suite *KeeperTestSuite) TestMoveSuperfluidDelegationRewardToGauges() { // allocate rewards to first validator for _, valIndex := range tc.rewardedVals { - suite.allocateRewardsToValidator(valAddrs[valIndex]) + suite.AllocateRewardsToValidator(valAddrs[valIndex], sdk.NewInt(20000)) } // move intermediary account delegation rewards to gauges diff --git a/x/superfluid/keeper/hooks_test.go b/x/superfluid/keeper/hooks_test.go index 8016836d8e2..0753ed5cc13 100644 --- a/x/superfluid/keeper/hooks_test.go +++ b/x/superfluid/keeper/hooks_test.go @@ -1,10 +1,8 @@ package keeper_test import ( - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/crypto/ed25519" ) func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { @@ -18,7 +16,7 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { "happy path with single validator and delegator", []stakingtypes.BondStatus{stakingtypes.Bonded}, []superfluidDelegation{{0, 0, 0, 1000000}}, - sdk.Coins{}, + sdk.Coins{{Amount: sdk.NewInt(999990), Denom: "stake"}}, }, } @@ -27,34 +25,39 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { suite.SetupTest() valAddrs := suite.SetupValidators(tc.validatorStats) + // we create two additional pools: total three pools, 10 gauges denoms, poolIds := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) // Generate delegator addresses delAddrs := CreateRandomAccounts(1) - intermediaryAccs, _ := suite.SetupSuperfluidDelegations(delAddrs, valAddrs, tc.superDelegations, denoms) + intermediaryAccs, locks := suite.SetupSuperfluidDelegations(delAddrs, valAddrs, tc.superDelegations, denoms) suite.checkIntermediaryAccountDelegations(intermediaryAccs) - // gamm swap operation before refresh - acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) + // run swap and set spot price pool, err := suite.App.GAMMKeeper.GetPool(suite.Ctx, poolIds[0]) suite.Require().NoError(err) poolAssets := pool.GetAllPoolAssets() - - coins := sdk.Coins{sdk.NewInt64Coin(poolAssets[1].Token.Denom, 100000000000000)} - err = simapp.FundAccount(suite.App.BankKeeper, suite.Ctx, acc1, coins) - suite.Require().NoError(err) - _, _, err = suite.App.GAMMKeeper.SwapExactAmountOut( - suite.Ctx, acc1, - poolIds[0], poolAssets[1].Token.Denom, poolAssets[1].Token.Amount, - sdk.NewCoin(poolAssets[0].Token.Denom, poolAssets[0].Token.Amount.Quo(sdk.NewInt(4)))) - suite.Require().NoError(err) + suite.SwapAndSetSpotPrice(poolIds[0], poolAssets[1], poolAssets[0]) // run epoch actions suite.BeginNewBlock(true) // check lptoken twap value set - newEpochTwap := suite.App.SuperfluidKeeper.GetOsmoEquivalentMultiplier(suite.Ctx, denoms[0]) - suite.Require().Equal(newEpochTwap.String(), "15.000000000000000000") + newEpochMultiplier := suite.App.SuperfluidKeeper.GetOsmoEquivalentMultiplier(suite.Ctx, denoms[0]) + suite.Require().Equal(newEpochMultiplier, sdk.NewDec(15)) + + // check gauge creation in new block + intermediaryAccAddr := suite.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(suite.Ctx, locks[0].ID) + intermediaryAcc := suite.App.SuperfluidKeeper.GetIntermediaryAccount(suite.Ctx, intermediaryAccAddr) + gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, intermediaryAcc.GaugeId) + + suite.Require().NoError(err) + suite.Require().Equal(gauge.Id, intermediaryAcc.GaugeId) + suite.Require().Equal(gauge.IsPerpetual, true) + suite.Require().Equal(gauge.Coins, tc.expRewards) + suite.Require().Equal(gauge.NumEpochsPaidOver, uint64(1)) + suite.Require().Equal(gauge.FilledEpochs, uint64(1)) + suite.Require().Equal(gauge.DistributedCoins, tc.expRewards) // check delegation changes for _, acc := range intermediaryAccs { @@ -63,9 +66,9 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { delegation, found := suite.App.StakingKeeper.GetDelegation(suite.Ctx, acc.GetAccAddress(), valAddr) suite.Require().True(found) suite.Require().Equal(sdk.NewDec(7500000), delegation.Shares) - // TODO: Check reward distribution - // suite.Require().NotEqual(sdk.Coins{}, ) } + balance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, delAddrs[0]) + suite.Require().Equal(tc.expRewards, balance) }) } } diff --git a/x/superfluid/keeper/intermediary_account_test.go b/x/superfluid/keeper/intermediary_account_test.go index 8a806a52c43..d96c7208af9 100644 --- a/x/superfluid/keeper/intermediary_account_test.go +++ b/x/superfluid/keeper/intermediary_account_test.go @@ -2,9 +2,76 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/osmosis-labs/osmosis/v7/x/superfluid/types" ) +func (suite *KeeperTestSuite) TestIntermediaryAccountCreation() { + testCases := []struct { + name string + validatorStats []stakingtypes.BondStatus + delegatorNumber int64 + superDelegations []superfluidDelegation + }{ + { + "test intermediary account with single superfluid delegation", + []stakingtypes.BondStatus{stakingtypes.Bonded}, + 1, + []superfluidDelegation{{0, 0, 0, 1000000}}, + }, + { + "test multiple intermediary accounts with multiple superfluid delegation", + []stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Bonded}, + 2, + []superfluidDelegation{{0, 0, 0, 1000000}, {1, 1, 0, 1000000}}, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + valAddrs := suite.SetupValidators(tc.validatorStats) + delAddrs := CreateRandomAccounts(int(tc.delegatorNumber)) + + // we create two additional pools: total three pools, 10 gauges + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) + + var interAccs []types.SuperfluidIntermediaryAccount + + for _, superDelegation := range tc.superDelegations { + delAddr := delAddrs[superDelegation.delIndex] + valAddr := valAddrs[superDelegation.valIndex] + denom := denoms[superDelegation.lpIndex] + + // check intermediary Account prior to superfluid delegation, should have nil Intermediary Account + expAcc := types.NewSuperfluidIntermediaryAccount(denom, valAddr.String(), 0) + interAcc := suite.App.SuperfluidKeeper.GetIntermediaryAccount(suite.Ctx, expAcc.GetAccAddress()) + suite.Require().NotEqual(expAcc.GetAccAddress(), interAcc.GetAccAddress()) + suite.Require().Equal("", interAcc.Denom) + suite.Require().Equal(uint64(0), interAcc.GaugeId) + suite.Require().Equal("", interAcc.ValAddr) + + lock := suite.SetupSuperfluidDelegate(delAddr, valAddr, denom, superDelegation.lpAmount) + + // check that intermediary Account connection is established + interAccConnection := suite.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(suite.Ctx, lock.ID) + suite.Require().Equal(expAcc.GetAccAddress(), interAccConnection) + + interAcc = suite.App.SuperfluidKeeper.GetIntermediaryAccount(suite.Ctx, interAccConnection) + suite.Require().Equal(expAcc.GetAccAddress(), interAcc.GetAccAddress()) + + // check on interAcc that has been created + suite.Require().Equal(denom, interAcc.Denom) + suite.Require().Equal(valAddr.String(), interAcc.ValAddr) + + interAccs = append(interAccs, interAcc) + } + suite.checkIntermediaryAccountDelegations(interAccs) + }) + } +} + func (suite *KeeperTestSuite) TestIntermediaryAccountsSetGetDeleteFlow() { suite.SetupTest() diff --git a/x/superfluid/keeper/keeper_test.go b/x/superfluid/keeper/keeper_test.go index 0e6b055ec85..54b0444f83b 100644 --- a/x/superfluid/keeper/keeper_test.go +++ b/x/superfluid/keeper/keeper_test.go @@ -1,7 +1,6 @@ package keeper_test import ( - "fmt" "testing" "time" @@ -18,11 +17,8 @@ import ( "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" "github.com/tendermint/tendermint/crypto/ed25519" - lockupkeeper "github.com/osmosis-labs/osmosis/v7/x/lockup/keeper" - epochtypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types" gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" - lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types" minttypes "github.com/osmosis-labs/osmosis/v7/x/mint/types" ) @@ -32,26 +28,11 @@ type KeeperTestSuite struct { queryClient types.QueryClient } -func (suite *KeeperTestSuite) GetSuite() *suite.Suite { - return &suite.Suite -} -func (suite *KeeperTestSuite) GetCtx() sdk.Context { - return suite.Ctx -} -func (suite *KeeperTestSuite) GetApp() *app.OsmosisApp { - return suite.App -} -func (suite *KeeperTestSuite) SetCtx(Ctx sdk.Context) { - suite.Ctx = Ctx -} - func (suite *KeeperTestSuite) SetupTest() { suite.App = app.Setup(false) startTime := time.Unix(1645580000, 0) suite.Ctx = suite.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "osmosis-1", Time: startTime.UTC()}) - a := suite.App.StakingKeeper.GetParams(suite.Ctx).BondDenom - fmt.Println(a) queryHelper := baseapp.NewQueryServerTestHelper(suite.Ctx, suite.App.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, suite.App.SuperfluidKeeper) suite.queryClient = types.NewQueryClient(queryHelper) @@ -139,15 +120,6 @@ func (suite *KeeperTestSuite) createGammPool(denoms []string) uint64 { return poolId } -func (suite *KeeperTestSuite) LockTokens(addr sdk.AccAddress, coins sdk.Coins, duration time.Duration) (lockID uint64) { - msgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) - err := simapp.FundAccount(suite.App.BankKeeper, suite.Ctx, addr, coins) - suite.Require().NoError(err) - msgResponse, err := msgServer.LockTokens(sdk.WrapSDKContext(suite.Ctx), lockuptypes.NewMsgLockTokens(addr, duration, coins)) - suite.Require().NoError(err) - return msgResponse.ID -} - func (suite *KeeperTestSuite) SetupValidators(bondStatuses []stakingtypes.BondStatus) []sdk.ValAddress { valAddrs := []sdk.ValAddress{} for _, status := range bondStatuses { @@ -158,52 +130,13 @@ func (suite *KeeperTestSuite) SetupValidators(bondStatuses []stakingtypes.BondSt } func (suite *KeeperTestSuite) SetupGammPoolsAndSuperfluidAssets(multipliers []sdk.Dec) ([]string, []uint64) { - suite.App.GAMMKeeper.SetParams(suite.Ctx, gammtypes.Params{ - PoolCreationFee: sdk.Coins{}, - }) - - bondDenom := suite.App.StakingKeeper.BondDenom(suite.Ctx) + pools := suite.SetupGammPoolsWithBondDenomMultiplier(multipliers) - acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()) denoms := []string{} poolIds := []uint64{} - - for index, multiplier := range multipliers { - token := fmt.Sprintf("token%d", index) - - uosmoAmount := gammtypes.InitPoolSharesSupply.ToDec().Mul(multiplier).RoundInt() - - err := simapp.FundAccount(suite.App.BankKeeper, suite.Ctx, acc1, sdk.NewCoins( - sdk.NewCoin(bondDenom, uosmoAmount.Mul(sdk.NewInt(10))), - sdk.NewInt64Coin(token, 100000), - )) - suite.NoError(err) - - var ( - defaultFutureGovernor = "" - - // pool assets - defaultFooAsset gammtypes.PoolAsset = gammtypes.PoolAsset{ - Weight: sdk.NewInt(100), - Token: sdk.NewCoin(bondDenom, uosmoAmount), - } - defaultBarAsset gammtypes.PoolAsset = gammtypes.PoolAsset{ - Weight: sdk.NewInt(100), - Token: sdk.NewCoin(token, sdk.NewInt(10000)), - } - poolAssets []gammtypes.PoolAsset = []gammtypes.PoolAsset{defaultFooAsset, defaultBarAsset} - ) - - poolId, err := suite.App.GAMMKeeper.CreateBalancerPool(suite.Ctx, acc1, balancer.PoolParams{ - SwapFee: sdk.NewDecWithPrec(1, 2), - ExitFee: sdk.NewDecWithPrec(1, 2), - }, poolAssets, defaultFutureGovernor) - suite.Require().NoError(err) - - pool, err := suite.App.GAMMKeeper.GetPool(suite.Ctx, poolId) - suite.Require().NoError(err) - + for _, pool := range pools { denom := pool.GetTotalShares().Denom + suite.App.SuperfluidKeeper.AddNewSuperfluidAsset(suite.Ctx, types.SuperfluidAsset{ Denom: denom, AssetType: types.SuperfluidAssetTypeLPShare, @@ -215,9 +148,10 @@ func (suite *KeeperTestSuite) SetupGammPoolsAndSuperfluidAssets(multipliers []sd AssetType: types.SuperfluidAssetTypeLPShare, }) - poolIds = append(poolIds, poolId) denoms = append(denoms, denom) + poolIds = append(poolIds, pool.GetId()) } + return denoms, poolIds }