diff --git a/CHANGELOG.md b/CHANGELOG.md index ec743c031..e1fb031e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - fix(sudo): Make blank sudoers root invalid at genesis time. * [#1710](https://github.com/NibiruChain/nibiru/pull/1710) - refactor(perp): Clean and organize module errors for x/perp * [#1714](https://github.com/NibiruChain/nibiru/pull/1714) - ci(localnet.sh): Fix script, simplify, and test in CI. +* [#1719](https://github.com/NibiruChain/nibiru/pull/1719) - refactor(test): add is not mandatory interface to action ### Dependencies diff --git a/x/common/testutil/action/account.go b/x/common/testutil/action/account.go index 2cfb74291..9670faf6c 100644 --- a/x/common/testutil/action/account.go +++ b/x/common/testutil/action/account.go @@ -16,18 +16,18 @@ func FundAccount(account sdk.AccAddress, amount sdk.Coins) Action { return &fundAccount{Account: account, Amount: amount} } -func (c fundAccount) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c fundAccount) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.BankKeeper.MintCoins(ctx, inflationtypes.ModuleName, c.Amount) if err != nil { - return ctx, err, true + return ctx, err } err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, inflationtypes.ModuleName, c.Account, c.Amount) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } type fundModule struct { @@ -39,16 +39,16 @@ func FundModule(module string, amount sdk.Coins) Action { return fundModule{Module: module, Amount: amount} } -func (c fundModule) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c fundModule) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.BankKeeper.MintCoins(ctx, inflationtypes.ModuleName, c.Amount) if err != nil { - return ctx, err, true + return ctx, err } err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, inflationtypes.ModuleName, c.Module, c.Amount) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } diff --git a/x/common/testutil/action/block.go b/x/common/testutil/action/block.go index 614ef2b8f..bb19c4629 100644 --- a/x/common/testutil/action/block.go +++ b/x/common/testutil/action/block.go @@ -14,12 +14,12 @@ type increaseBlockNumberBy struct { numBlocks int64 } -func (i increaseBlockNumberBy) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (i increaseBlockNumberBy) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.EndBlocker(ctx, types.RequestEndBlock{Height: ctx.BlockHeight()}) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + i.numBlocks) - return ctx, nil, true + return ctx, nil } // IncreaseBlockNumberBy increases the block number by the given number of blocks @@ -31,10 +31,10 @@ type increaseBlockTimeBy struct { seconds time.Duration } -func (i increaseBlockTimeBy) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (i increaseBlockTimeBy) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Second * i.seconds)) - return ctx, nil, true + return ctx, nil } func IncreaseBlockTimeBy(seconds time.Duration) Action { @@ -45,8 +45,8 @@ type setBlockTime struct { blockTime time.Time } -func (s setBlockTime) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - return ctx.WithBlockTime(s.blockTime), nil, true +func (s setBlockTime) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { + return ctx.WithBlockTime(s.blockTime), nil } // SetBlockTime sets the block time to the given value @@ -58,8 +58,8 @@ type setBlockNumber struct { blockNumber int64 } -func (s setBlockNumber) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - return ctx.WithBlockHeight(s.blockNumber), nil, true +func (s setBlockNumber) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { + return ctx.WithBlockHeight(s.blockNumber), nil } // SetBlockNumber sets the block number to the given value @@ -69,7 +69,7 @@ func SetBlockNumber(blockNumber int64) Action { type moveToNextBlock struct{} -func (m moveToNextBlock) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m moveToNextBlock) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.EndBlock(types.RequestEndBlock{}) app.Commit() @@ -85,7 +85,7 @@ func (m moveToNextBlock) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, e return app.NewContext( false, newHeader, - ).WithBlockTime(newHeader.Time), nil, true + ).WithBlockTime(newHeader.Time), nil } func MoveToNextBlock() Action { @@ -96,7 +96,7 @@ type moveToNextBlockWithDuration struct { blockDuration time.Duration } -func (m moveToNextBlockWithDuration) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m moveToNextBlockWithDuration) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.EndBlock(types.RequestEndBlock{Height: ctx.BlockHeight()}) app.Commit() @@ -112,7 +112,7 @@ func (m moveToNextBlockWithDuration) Do(app *app.NibiruApp, ctx sdk.Context) (sd return app.NewContext( false, newHeader, - ).WithBlockTime(newHeader.Time), nil, true + ).WithBlockTime(newHeader.Time), nil } func MoveToNextBlockWithDuration(blockDuration time.Duration) Action { @@ -125,7 +125,7 @@ type moveToNextBlockWithTime struct { blockTime time.Time } -func (m moveToNextBlockWithTime) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m moveToNextBlockWithTime) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.EndBlock(types.RequestEndBlock{Height: ctx.BlockHeight()}) app.Commit() @@ -141,7 +141,7 @@ func (m moveToNextBlockWithTime) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Co return app.NewContext( false, newHeader, - ).WithBlockTime(newHeader.Time), nil, true + ).WithBlockTime(newHeader.Time), nil } func MoveToNextBlockWithTime(blockTime time.Time) Action { diff --git a/x/common/testutil/action/testcase.go b/x/common/testutil/action/testcase.go index cf094d57e..4deb15952 100644 --- a/x/common/testutil/action/testcase.go +++ b/x/common/testutil/action/testcase.go @@ -13,10 +13,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// `Action` is a type of operation or task that can be performed in the +// Action is a type of operation or task that can be performed in the // Nibiru application. type Action interface { - // `Do` is a specific implementation of the `Action`. When `Do` is called, + // Do is a specific implementation of the `Action`. When `Do` is called, // the action is performed and some feedback is provided about the action's // success. `Do` can mutate the app. // @@ -25,12 +25,17 @@ type Action interface { // - err: The error if one was raised. // - isMandatory: Whether an error should have been raised. Do(app *app.NibiruApp, ctx sdk.Context) ( - outCtx sdk.Context, err error, isMandatory bool, + outCtx sdk.Context, err error, ) } -func ActionResp(ctx sdk.Context, respErr error) (outCtx sdk.Context, err error, isMandatory bool) { - return ctx, respErr, false +// IsNotMandatory is a marker interface for actions that are not mandatory, and it does not stop the test when there is an error. +type IsNotMandatory interface { + IsNotMandatory() +} + +func ActionResp(ctx sdk.Context, respErr error) (outCtx sdk.Context, err error) { + return ctx, respErr } type TestCases []TestCase @@ -67,32 +72,38 @@ func (tc TestCase) Run(t *testing.T) { t.Run(tc.Name, func(t *testing.T) { app, ctx := testapp.NewNibiruTestAppAndContextAtTime(time.UnixMilli(0)) var err error - var isMandatory bool + var isNotMandatory bool for _, action := range tc.given { - ctx, err, isMandatory = action.Do(app, ctx) - if isMandatory { - require.NoError(t, err, "failed to execute given action: %s", tc.Name) - } else { + _, isNotMandatory = action.(IsNotMandatory) + + ctx, err = action.Do(app, ctx) + if isNotMandatory { assert.NoError(t, err, "failed to execute given action: %s", tc.Name) + } else { + require.NoError(t, err, "failed to execute given action: %s", tc.Name) } } for _, action := range tc.when { - ctx, err, isMandatory = action.Do(app, ctx) - if isMandatory { - require.NoError(t, err, "failed to execute when action: %s", tc.Name) - } else { + _, isNotMandatory = action.(IsNotMandatory) + + ctx, err = action.Do(app, ctx) + if isNotMandatory { assert.NoError(t, err, "failed to execute when action: %s", tc.Name) + } else { + require.NoError(t, err, "failed to execute when action: %s", tc.Name) } } for _, action := range tc.then { - ctx, err, isMandatory = action.Do(app, ctx) - if isMandatory { - require.NoError(t, err, "failed to execute then action: %s", tc.Name) - } else { + _, isNotMandatory = action.(IsNotMandatory) + + ctx, err = action.Do(app, ctx) + if isNotMandatory { assert.NoError(t, err, "failed to execute then action: %s", tc.Name) + } else { + require.NoError(t, err, "failed to execute then action: %s", tc.Name) } } }) diff --git a/x/common/testutil/assertion/balances.go b/x/common/testutil/assertion/balances.go index 9cf61ff34..309505c4c 100644 --- a/x/common/testutil/assertion/balances.go +++ b/x/common/testutil/assertion/balances.go @@ -3,6 +3,8 @@ package assertion import ( "fmt" + "github.com/NibiruChain/nibiru/x/common/testutil/action" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -10,7 +12,7 @@ import ( "github.com/NibiruChain/nibiru/app" ) -func AllBalancesEqual(account sdk.AccAddress, amount sdk.Coins) *allBalancesEqual { +func AllBalancesEqual(account sdk.AccAddress, amount sdk.Coins) action.Action { return &allBalancesEqual{Account: account, Amount: amount} } @@ -19,7 +21,7 @@ type allBalancesEqual struct { Amount sdk.Coins } -func (b allBalancesEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (b allBalancesEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { coins := app.BankKeeper.GetAllBalances(ctx, b.Account) if !coins.IsEqual(b.Amount) { return ctx, fmt.Errorf( @@ -27,13 +29,13 @@ func (b allBalancesEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, b.Account.String(), b.Amount.String(), coins.String(), - ), false + ) } - return ctx, nil, false + return ctx, nil } -func BalanceEqual(account sdk.AccAddress, denom string, amount sdkmath.Int) *balanceEqual { +func BalanceEqual(account sdk.AccAddress, denom string, amount sdkmath.Int) action.Action { return &balanceEqual{Account: account, Denom: denom, Amount: amount} } @@ -43,7 +45,9 @@ type balanceEqual struct { Amount sdkmath.Int } -func (b balanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (b balanceEqual) IsNotMandatory() {} + +func (b balanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { coin := app.BankKeeper.GetBalance(ctx, b.Account, b.Denom) if !coin.Amount.Equal(b.Amount) { return ctx, fmt.Errorf( @@ -51,13 +55,13 @@ func (b balanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, erro b.Account.String(), b.Amount.String(), coin.String(), - ), false + ) } - return ctx, nil, false + return ctx, nil } -func ModuleBalanceEqual(moduleName string, denom string, amount sdkmath.Int) *moduleBalanceEqual { +func ModuleBalanceEqual(moduleName string, denom string, amount sdkmath.Int) action.Action { return &moduleBalanceEqual{ModuleName: moduleName, Denom: denom, Amount: amount} } @@ -67,7 +71,9 @@ type moduleBalanceEqual struct { Amount sdkmath.Int } -func (b moduleBalanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (b moduleBalanceEqual) IsNotMandatory() {} + +func (b moduleBalanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { coin := app.BankKeeper.GetBalance(ctx, app.AccountKeeper.GetModuleAddress(b.ModuleName), b.Denom) if !coin.Amount.Equal(b.Amount) { return ctx, fmt.Errorf( @@ -75,8 +81,8 @@ func (b moduleBalanceEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context b.ModuleName, b.Amount.String(), coin.String(), - ), false + ) } - return ctx, nil, false + return ctx, nil } diff --git a/x/common/testutil/assertion/gas.go b/x/common/testutil/assertion/gas.go index 960d87be6..98419320e 100644 --- a/x/common/testutil/assertion/gas.go +++ b/x/common/testutil/assertion/gas.go @@ -13,13 +13,13 @@ type gasConsumedShouldBe struct { gasConsumed uint64 } -func (g gasConsumedShouldBe) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (g gasConsumedShouldBe) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { gasUsed := ctx.GasMeter().GasConsumed() if g.gasConsumed != gasUsed { - return ctx, fmt.Errorf("gas consumed should be %d, but got %d", g.gasConsumed, gasUsed), true + return ctx, fmt.Errorf("gas consumed should be %d, but got %d", g.gasConsumed, gasUsed) } - return ctx, nil, true + return ctx, nil } func GasConsumedShouldBe(gasConsumed uint64) action.Action { diff --git a/x/epochs/integration/action/epoch.go b/x/epochs/integration/action/epoch.go index 77173a469..daacf217c 100644 --- a/x/epochs/integration/action/epoch.go +++ b/x/epochs/integration/action/epoch.go @@ -11,10 +11,12 @@ type startEpoch struct { epochIdentifier string } -func (s startEpoch) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (s startEpoch) IsNotMandatory() {} + +func (s startEpoch) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { epochInfo, err := app.EpochsKeeper.GetEpochInfo(ctx, s.epochIdentifier) if err != nil { - return ctx, err, false + return ctx, err } epochInfo.EpochCountingStarted = true epochInfo.CurrentEpoch = 1 @@ -24,7 +26,7 @@ func (s startEpoch) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, app.EpochsKeeper.Epochs.Insert(ctx, epochInfo.Identifier, epochInfo) - return ctx, nil, false + return ctx, nil } func StartEpoch(epochIdentifier string) action.Action { diff --git a/x/oracle/integration/action/price.go b/x/oracle/integration/action/price.go index ef2741cb6..0d80f5e10 100644 --- a/x/oracle/integration/action/price.go +++ b/x/oracle/integration/action/price.go @@ -25,10 +25,10 @@ type setPairPrice struct { Price sdk.Dec } -func (s setPairPrice) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (s setPairPrice) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.OracleKeeper.SetPrice(ctx, s.Pair, s.Price) - return ctx, nil, true + return ctx, nil } func InsertOraclePriceSnapshot(pair asset.Pair, time time.Time, price sdk.Dec) action.Action { @@ -45,12 +45,12 @@ type insertOraclePriceSnapshot struct { Price sdk.Dec } -func (s insertOraclePriceSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (s insertOraclePriceSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.OracleKeeper.PriceSnapshots.Insert(ctx, collections.Join(s.Pair, s.Time), types.PriceSnapshot{ Pair: s.Pair, Price: s.Price, TimestampMs: s.Time.UnixMilli(), }) - return ctx, nil, true + return ctx, nil } diff --git a/x/perp/v2/integration/action/dnr.go b/x/perp/v2/integration/action/dnr.go index 96f17b929..7940f4795 100644 --- a/x/perp/v2/integration/action/dnr.go +++ b/x/perp/v2/integration/action/dnr.go @@ -26,9 +26,9 @@ type setEpochAction struct { Epoch uint64 } -func (s setEpochAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (s setEpochAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { app.PerpKeeperV2.DnREpoch.Set(ctx, s.Epoch) - return ctx, nil, true + return ctx, nil } func DnRCurrentVolumeIs(user sdk.AccAddress, wantVolume math.Int) action.Action { @@ -43,19 +43,19 @@ type expectVolumeAction struct { Volume math.Int } -func (e expectVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (e expectVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { currentEpoch, err := app.PerpKeeperV2.DnREpoch.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } volume, err := app.PerpKeeperV2.TraderVolumes.Get(ctx, collections.Join(e.User, currentEpoch)) if err != nil { - return ctx, err, true + return ctx, err } if !volume.Equal(e.Volume) { - return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, volume), true + return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, volume) } - return ctx, nil, true + return ctx, nil } func DnRPreviousVolumeIs(user sdk.AccAddress, wantVolume math.Int) action.Action { @@ -70,17 +70,17 @@ type expectPreviousVolumeAction struct { Volume math.Int } -func (e expectPreviousVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (e expectPreviousVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { currentEpoch, err := app.PerpKeeperV2.DnREpoch.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } v := app.PerpKeeperV2.GetTraderVolumeLastEpoch(ctx, currentEpoch, e.User) if !v.Equal(e.Volume) { - return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, v), true + return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, v) } - return ctx, nil, true + return ctx, nil } func DnRVolumeNotExist(user sdk.AccAddress, epoch uint64) action.Action { @@ -95,12 +95,12 @@ type expectVolumeNotExistAction struct { User sdk.AccAddress } -func (e expectVolumeNotExistAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (e expectVolumeNotExistAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { v, err := app.PerpKeeperV2.TraderVolumes.Get(ctx, collections.Join(e.User, e.Epoch)) if err == nil { - return ctx, fmt.Errorf("unexpected user dnr volume, got %s", v), true + return ctx, fmt.Errorf("unexpected user dnr volume, got %s", v) } - return ctx, nil, true + return ctx, nil } type marketOrderFeeIs struct { @@ -133,10 +133,10 @@ func MarketOrderFeeIs( } } -func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } balanceBefore := app.BankKeeper.GetBalance(ctx, o.trader, collateral).Amount @@ -145,7 +145,7 @@ func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, o.margin, o.leverage, o.baseAssetLimit, ) if err != nil { - return ctx, err, true + return ctx, err } balanceBefore = balanceBefore.Sub(resp.MarginToVault.TruncateInt()) @@ -154,9 +154,9 @@ func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, balanceAfter := app.BankKeeper.GetBalance(ctx, o.trader, collateral).Amount paidFees := balanceBefore.Sub(balanceAfter) if !paidFees.Equal(expectedFee.TruncateInt()) { - return ctx, fmt.Errorf("unexpected fee, wanted %s, got %s", expectedFee, paidFees), true + return ctx, fmt.Errorf("unexpected fee, wanted %s, got %s", expectedFee, paidFees) } - return ctx, nil, true + return ctx, nil } func SetPreviousEpochUserVolume(user sdk.AccAddress, volume math.Int) action.Action { @@ -171,13 +171,13 @@ type setPreviousEpochUserVolumeAction struct { volume math.Int } -func (s setPreviousEpochUserVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (s setPreviousEpochUserVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { currentEpoch, err := app.PerpKeeperV2.DnREpoch.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } app.PerpKeeperV2.TraderVolumes.Insert(ctx, collections.Join(s.user, currentEpoch-1), s.volume) - return ctx, nil, true + return ctx, nil } func SetGlobalDiscount(fee sdk.Dec, volume math.Int) action.Action { @@ -192,9 +192,9 @@ type setGlobalDiscountAction struct { volume math.Int } -func (s setGlobalDiscountAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (s setGlobalDiscountAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { app.PerpKeeperV2.GlobalDiscounts.Insert(ctx, s.volume, s.fee) - return ctx, nil, true + return ctx, nil } func SetCustomDiscount(user sdk.AccAddress, fee sdk.Dec, volume math.Int) action.Action { @@ -211,20 +211,20 @@ type setCustomDiscountAction struct { user sdk.AccAddress } -func (s *setCustomDiscountAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (s *setCustomDiscountAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { app.PerpKeeperV2.TraderDiscounts.Insert(ctx, collections.Join(s.user, s.volume), s.fee) - return ctx, nil, true + return ctx, nil } type fundDnREpoch struct { funds sdk.Coins } -func (f fundDnREpoch) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (f fundDnREpoch) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { tmpAcc := testutil.AccAddress() - ctx, err, _ = action.FundAccount(tmpAcc, f.funds).Do(app, ctx) + ctx, err = action.FundAccount(tmpAcc, f.funds).Do(app, ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = perpkeeper.NewMsgServerImpl(app.PerpKeeperV2).AllocateEpochRebates( ctx, &types.MsgAllocateEpochRebates{ @@ -232,9 +232,9 @@ func (f fundDnREpoch) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Contex Rebates: f.funds, }) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } func FundDnREpoch(amt sdk.Coins) action.Action { @@ -243,16 +243,16 @@ func FundDnREpoch(amt sdk.Coins) action.Action { type startNewDnRepochAction struct{} -func (s startNewDnRepochAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (s startNewDnRepochAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { currentEpoch, err := app.PerpKeeperV2.DnREpoch.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } err = app.PerpKeeperV2.StartNewEpoch(ctx, currentEpoch+1) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } func StartNewDnREpoch() action.Action { @@ -265,20 +265,20 @@ type dnrRebateIsAction struct { expectedRewards sdk.Coins } -func (d dnrRebateIsAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (d dnrRebateIsAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { resp, err := perpkeeper.NewMsgServerImpl(app.PerpKeeperV2).WithdrawEpochRebates( ctx, &types.MsgWithdrawEpochRebates{ Sender: d.user.String(), Epochs: []uint64{d.epoch}, }) if err != nil { - return ctx, err, true + return ctx, err } withdrawn := resp.WithdrawnRebates if !withdrawn.IsEqual(d.expectedRewards) { - return ctx, fmt.Errorf("expected %s, got %s", d.expectedRewards, withdrawn), true + return ctx, fmt.Errorf("expected %s, got %s", d.expectedRewards, withdrawn) } - return ctx, nil, true + return ctx, nil } func DnRRebateIs(user sdk.AccAddress, epoch uint64, expectedRewards sdk.Coins) action.Action { @@ -303,7 +303,7 @@ type dnrRebateFailsAction struct { func (d dnrRebateFailsAction) Do( app *app.NibiruApp, ctx sdk.Context, -) (outCtx sdk.Context, err error, isMandatory bool) { +) (outCtx sdk.Context, err error) { resp, err := perpkeeper.NewMsgServerImpl(app.PerpKeeperV2).WithdrawEpochRebates( ctx, &types.MsgWithdrawEpochRebates{ Sender: d.user.String(), @@ -311,7 +311,7 @@ func (d dnrRebateFailsAction) Do( }) if err == nil { withdrawn := resp.WithdrawnRebates - return ctx, fmt.Errorf("expected withdrawal error but got instead: %s rewards", withdrawn.String()), true + return ctx, fmt.Errorf("expected withdrawal error but got instead: %s rewards", withdrawn.String()) } - return ctx, nil, true + return ctx, nil } diff --git a/x/perp/v2/integration/action/liquidation.go b/x/perp/v2/integration/action/liquidation.go index 1c7f397f0..cf0360cd1 100644 --- a/x/perp/v2/integration/action/liquidation.go +++ b/x/perp/v2/integration/action/liquidation.go @@ -23,7 +23,7 @@ type multiLiquidate struct { shouldAllFail bool } -func (m multiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m multiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { liquidationRequests := make([]*types.MsgMultiLiquidate_Liquidation, len(m.pairTraderTuples)) for i, pairTraderTuple := range m.pairTraderTuples { @@ -38,30 +38,30 @@ func (m multiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, er if m.shouldAllFail { // we check if all liquidations failed if err == nil { - return ctx, fmt.Errorf("multi liquidations should have all failed, but instead some succeeded"), true + return ctx, fmt.Errorf("multi liquidations should have all failed, but instead some succeeded") } for i, response := range responses { if response.Success { - return ctx, fmt.Errorf("multi liquidations should have all failed, but instead some succeeded, index %d", i), true + return ctx, fmt.Errorf("multi liquidations should have all failed, but instead some succeeded, index %d", i) } } - return ctx, nil, true + return ctx, nil } // otherwise, some succeeded and some may have failed if err != nil { - return ctx, err, true + return ctx, err } for i, response := range responses { if response.Success != m.pairTraderTuples[i].Successful { - return ctx, fmt.Errorf("MultiLiquidate wrong assertion, expected %v, got %v, index %d", m.pairTraderTuples[i].Successful, response.Success, i), false + return ctx, fmt.Errorf("MultiLiquidate wrong assertion, expected %v, got %v, index %d", m.pairTraderTuples[i].Successful, response.Success, i) } } - return ctx, nil, true + return ctx, nil } func MultiLiquidate(liquidator sdk.AccAddress, shouldAllFail bool, pairTraderTuples ...PairTraderTuple) action.Action { diff --git a/x/perp/v2/integration/action/margin.go b/x/perp/v2/integration/action/margin.go index 1aee0732b..b83f31dda 100644 --- a/x/perp/v2/integration/action/margin.go +++ b/x/perp/v2/integration/action/margin.go @@ -31,20 +31,20 @@ type addMarginAction struct { Margin sdkmath.Int } -func (a addMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (a addMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = app.PerpKeeperV2.AddMargin( ctx, a.Pair, a.Account, sdk.NewCoin(collateral, a.Margin), ) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } // AddMarginFail adds margin to the position expecting a fail @@ -69,20 +69,20 @@ type addMarginFailAction struct { ExpectedErr error } -func (a addMarginFailAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (a addMarginFailAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = app.PerpKeeperV2.AddMargin( ctx, a.Pair, a.Account, sdk.NewCoin(collateral, a.Margin), ) if !errors.Is(err, a.ExpectedErr) { - return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err), false + return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err) } - return ctx, nil, false + return ctx, nil } func RemoveMargin( @@ -103,20 +103,20 @@ type removeMarginAction struct { Margin sdkmath.Int } -func (a removeMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (a removeMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = app.PerpKeeperV2.RemoveMargin( ctx, a.Pair, a.Account, sdk.NewCoin(collateral, a.Margin), ) if err != nil { - return ctx, err, false + return ctx, err } - return ctx, nil, false + return ctx, nil } func RemoveMarginFail( @@ -140,18 +140,18 @@ type removeMarginActionFail struct { ExpectedErr error } -func (a removeMarginActionFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (a removeMarginActionFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = app.PerpKeeperV2.RemoveMargin( ctx, a.Pair, a.Account, sdk.NewCoin(collateral, a.Margin), ) if !errors.Is(err, a.ExpectedErr) { - return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err), false + return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err) } - return ctx, nil, false + return ctx, nil } diff --git a/x/perp/v2/integration/action/market.go b/x/perp/v2/integration/action/market.go index 150286f74..896479ef3 100644 --- a/x/perp/v2/integration/action/market.go +++ b/x/perp/v2/integration/action/market.go @@ -16,27 +16,13 @@ import ( "github.com/NibiruChain/nibiru/x/perp/v2/types" ) -type logger struct { - log string -} - -func (e logger) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { - return ctx, nil, true -} - -func Log(log string) action.Action { - return logger{ - log: log, - } -} - // createMarketAction creates a market type createMarketAction struct { Market types.Market AMM types.AMM } -func (c createMarketAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c createMarketAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { app.PerpKeeperV2.MarketLastVersion.Insert( ctx, c.Market.Pair, types.MarketLastVersion{Version: c.Market.Version}) app.PerpKeeperV2.SaveMarket(ctx, c.Market) @@ -49,7 +35,7 @@ func (c createMarketAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context app.PerpKeeperV2.Collateral.Set(ctx, types.TestingCollateralDenomNUSD) - return ctx, nil, true + return ctx, nil } // CreateCustomMarket creates a market with custom parameters @@ -140,11 +126,11 @@ type shiftPegMultiplier struct { newValue sdk.Dec } -func (e shiftPegMultiplier) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (e shiftPegMultiplier) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.PerpKeeperV2.Admin.ShiftPegMultiplier( ctx, e.pair, e.newValue, testapp.DefaultSudoRoot(), ) - return ctx, err, true + return ctx, err } func ShiftPegMultiplier(pair asset.Pair, newValue sdk.Dec) action.Action { @@ -159,11 +145,11 @@ type shiftSwapInvariant struct { newValue sdkmath.Int } -func (e shiftSwapInvariant) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (e shiftSwapInvariant) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.PerpKeeperV2.Admin.ShiftSwapInvariant( ctx, e.pair, e.newValue, testapp.DefaultSudoRoot(), ) - return ctx, err, true + return ctx, err } func ShiftSwapInvariant(pair asset.Pair, newValue sdkmath.Int) action.Action { @@ -179,14 +165,14 @@ type createPool struct { amm types.AMM } -func (c createPool) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c createPool) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.PerpKeeperV2.Admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: c.pair, PriceMultiplier: c.amm.PriceMultiplier, SqrtDepth: c.amm.SqrtDepth, Market: &c.market, }) - return ctx, err, true + return ctx, err } func CreateMarket(pair asset.Pair, market types.Market, amm types.AMM) action.Action { @@ -202,20 +188,20 @@ type setCollateral struct { Sender string } -func (c setCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c setCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { sudoers, err := app.SudoKeeper.Sudoers.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } sudoers.Root = common.NIBIRU_TEAM app.SudoKeeper.Sudoers.Set(ctx, sudoers) senderAddr, err := sdk.AccAddressFromBech32(c.Sender) if err != nil { - return ctx, err, true + return ctx, err } err = app.PerpKeeperV2.Admin.ChangeCollateralDenom(ctx, c.Denom, senderAddr) - return ctx, err, true + return ctx, err } func SetCollateral(denom string) action.Action { diff --git a/x/perp/v2/integration/action/params.go b/x/perp/v2/integration/action/params.go index 47d27d927..c629361e2 100644 --- a/x/perp/v2/integration/action/params.go +++ b/x/perp/v2/integration/action/params.go @@ -11,10 +11,10 @@ type changeLiquidationFeeRatio struct { LiquidationFeeRatio sdk.Dec } -func (c changeLiquidationFeeRatio) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c changeLiquidationFeeRatio) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { // TODO(k-yang): implement - return ctx, nil, true + return ctx, nil } func ChangeLiquidationFeeRatio(liquidationFeeRatio sdk.Dec) action.Action { diff --git a/x/perp/v2/integration/action/position.go b/x/perp/v2/integration/action/position.go index 3a87d8496..d10483c96 100644 --- a/x/perp/v2/integration/action/position.go +++ b/x/perp/v2/integration/action/position.go @@ -51,25 +51,25 @@ type openPositionAction struct { responseCheckers []MarketOrderResponseChecker } -func (o openPositionAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (o openPositionAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { resp, err := app.PerpKeeperV2.MarketOrder( ctx, o.pair, o.dir, o.trader, o.margin, o.leverage, o.baseAssetLimit, ) if err != nil { - return ctx, err, true + return ctx, err } if o.responseCheckers != nil { for _, check := range o.responseCheckers { err = check(resp) if err != nil { - return ctx, err, false + return ctx, err } } } - return ctx, nil, true + return ctx, nil } type openPositionFailsAction struct { @@ -82,17 +82,17 @@ type openPositionFailsAction struct { expectedErr error } -func (o openPositionFailsAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (o openPositionFailsAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.MarketOrder( ctx, o.pair, o.dir, o.trader, o.margin, o.leverage, o.baseAssetLimit, ) if !errors.Is(err, o.expectedErr) { - return ctx, fmt.Errorf("expected error %s, got %s", o.expectedErr, err), true + return ctx, fmt.Errorf("expected error %s, got %s", o.expectedErr, err) } - return ctx, nil, true + return ctx, nil } func MarketOrderFails( @@ -220,13 +220,13 @@ type closePositionAction struct { Pair asset.Pair } -func (c closePositionAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c closePositionAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.ClosePosition(ctx, c.Pair, c.Account) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } // ClosePosition closes a position for the given account and pair. @@ -244,14 +244,14 @@ type closePositionFailsAction struct { expectedErr error } -func (c closePositionFailsAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c closePositionFailsAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.ClosePosition(ctx, c.Pair, c.Account) if !errors.Is(err, c.expectedErr) { - return ctx, fmt.Errorf("expected error %s, got %s", c.expectedErr, err), true + return ctx, fmt.Errorf("expected error %s, got %s", c.expectedErr, err) } - return ctx, nil, true + return ctx, nil } func ClosePositionFails(account sdk.AccAddress, pair asset.Pair, expectedErr error) action.Action { @@ -267,10 +267,10 @@ type insertPosition struct { position types.Position } -func (i insertPosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (i insertPosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { traderAddr := sdk.MustAccAddressFromBech32(i.position.TraderAddress) app.PerpKeeperV2.SavePosition(ctx, i.position.Pair, 1, traderAddr, i.position) - return ctx, nil, true + return ctx, nil } // InsertPosition: Adds a position into state without a corresponding market @@ -345,7 +345,7 @@ type partialClose struct { amount sdk.Dec } -func (p partialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p partialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { txMsg := &types.MsgPartialClose{ Sender: p.trader.String(), Pair: p.pair, @@ -355,10 +355,10 @@ func (p partialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, erro _, err := perpkeeper.NewMsgServerImpl(app.PerpKeeperV2).PartialClose( goCtx, txMsg) if err != nil { - return ctx, err, true + return ctx, err } - return ctx, nil, true + return ctx, nil } func PartialClose(trader sdk.AccAddress, pair asset.Pair, amount sdk.Dec) action.Action { @@ -377,7 +377,9 @@ type partialCloseFails struct { expectedErr error } -func (p partialCloseFails) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p partialCloseFails) IsNotMandatory() {} + +func (p partialCloseFails) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { txMsg := &types.MsgPartialClose{ Sender: p.trader.String(), Pair: p.pair, @@ -389,10 +391,10 @@ func (p partialCloseFails) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, ) if !errors.Is(err, p.expectedErr) { - return ctx, fmt.Errorf("expected error %s, got %s", p.expectedErr, err), false + return ctx, fmt.Errorf("expected error %s, got %s", p.expectedErr, err) } - return ctx, nil, false + return ctx, nil } func PartialCloseFails(trader sdk.AccAddress, pair asset.Pair, amount sdk.Dec, expectedErr error) action.Action { diff --git a/x/perp/v2/integration/action/query.go b/x/perp/v2/integration/action/query.go index 23d2340c9..465f8eead 100644 --- a/x/perp/v2/integration/action/query.go +++ b/x/perp/v2/integration/action/query.go @@ -20,7 +20,9 @@ type queryPosition struct { responseCheckers []QueryPositionChecker } -func (q queryPosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryPosition) IsNotMandatory() {} + +func (q queryPosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) resp, err := queryServer.QueryPosition(sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ @@ -28,16 +30,16 @@ func (q queryPosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, err Trader: q.traderAddress.String(), }) if err != nil { - return ctx, err, false + return ctx, err } for _, checker := range q.responseCheckers { if err := checker(*resp); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } func QueryPosition(pair asset.Pair, traderAddress sdk.AccAddress, responseCheckers ...QueryPositionChecker) action.Action { @@ -88,25 +90,27 @@ type queryAllPositions struct { allResponseCheckers [][]QueryPositionChecker } -func (q queryAllPositions) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryAllPositions) IsNotMandatory() {} + +func (q queryAllPositions) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) resp, err := queryServer.QueryPositions(sdk.WrapSDKContext(ctx), &types.QueryPositionsRequest{ Trader: q.traderAddress.String(), }) if err != nil { - return ctx, err, false + return ctx, err } for i, positionCheckers := range q.allResponseCheckers { for _, checker := range positionCheckers { if err := checker(resp.Positions[i]); err != nil { - return ctx, err, false + return ctx, err } } } - return ctx, nil, false + return ctx, nil } func QueryPositions(traderAddress sdk.AccAddress, responseCheckers ...[]QueryPositionChecker) action.Action { @@ -121,7 +125,9 @@ type queryPositionNotFound struct { traderAddress sdk.AccAddress } -func (q queryPositionNotFound) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryPositionNotFound) IsNotMandatory() {} + +func (q queryPositionNotFound) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) _, err := queryServer.QueryPosition(sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ @@ -133,10 +139,10 @@ func (q queryPositionNotFound) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Cont "expected position not found, but found a position for pair %s, trader %s", q.pair, q.traderAddress, - ), false + ) } - return ctx, nil, false + return ctx, nil } func QueryPositionNotFound(pair asset.Pair, traderAddress sdk.AccAddress) action.Action { @@ -151,23 +157,25 @@ type queryMarkets struct { allResponseCheckers []QueryMarketsChecker } -func (q queryMarkets) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryMarkets) IsNotMandatory() {} + +func (q queryMarkets) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) resp, err := queryServer.QueryMarkets(sdk.WrapSDKContext(ctx), &types.QueryMarketsRequest{ Versioned: q.versioned, }) if err != nil { - return ctx, err, false + return ctx, err } for _, marketsCheckers := range q.allResponseCheckers { if err := marketsCheckers(resp.AmmMarkets); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } // QueryMarkets queries all markets, versioned contains active and inactive markets @@ -209,21 +217,23 @@ type queryModuleAccounts struct { allResponseCheckers []QueryModuleAccountsChecker } -func (q queryModuleAccounts) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryModuleAccounts) IsNotMandatory() {} + +func (q queryModuleAccounts) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) resp, err := queryServer.ModuleAccounts(sdk.WrapSDKContext(ctx), &types.QueryModuleAccountsRequest{}) if err != nil { - return ctx, err, false + return ctx, err } for _, accountsCheckers := range q.allResponseCheckers { if err := accountsCheckers(resp.Accounts); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } func QueryModuleAccounts(responseCheckers ...QueryModuleAccountsChecker) action.Action { @@ -266,9 +276,11 @@ func QueryPositionStore( } } +func (q queryPositionStore) IsNotMandatory() {} + func (q queryPositionStore) Do( app *app.NibiruApp, ctx sdk.Context, -) (newCtx sdk.Context, err error, isMandatory bool) { +) (newCtx sdk.Context, err error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) gotResp, err := queryServer.QueryPositionStore( @@ -315,7 +327,9 @@ type queryCollateral struct { wantDenom string } -func (q queryCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (q queryCollateral) IsNotMandatory() {} + +func (q queryCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { queryServer := keeper.NewQuerier(app.PerpKeeperV2) resp, _ := queryServer.QueryCollateral(sdk.WrapSDKContext(ctx), &types.QueryCollateralRequest{}) @@ -324,10 +338,10 @@ func (q queryCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, e "expected collateral denom %s, got %s", q.wantDenom, resp.CollateralDenom, - ), false + ) } - return ctx, nil, false + return ctx, nil } // QueryCollateral: Action for the Query/Collateral gRPC query. diff --git a/x/perp/v2/integration/action/settlement.go b/x/perp/v2/integration/action/settlement.go index c297093fa..62cafc869 100644 --- a/x/perp/v2/integration/action/settlement.go +++ b/x/perp/v2/integration/action/settlement.go @@ -16,13 +16,13 @@ type closeMarket struct { pair asset.Pair } -func (c closeMarket) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c closeMarket) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) if err != nil { - return ctx, err, false + return ctx, err } - return ctx, nil, true + return ctx, nil } func CloseMarket(pair asset.Pair) action.Action { @@ -34,13 +34,13 @@ type closeMarketShouldFail struct { pair asset.Pair } -func (c closeMarketShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c closeMarketShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) if err == nil { - return ctx, err, false + return ctx, err } - return ctx, nil, true + return ctx, nil } func CloseMarketShouldFail(pair asset.Pair) action.Action { @@ -55,19 +55,19 @@ type settlePosition struct { responseCheckers []SettlePositionChecker } -func (c settlePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c settlePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { resp, err := app.PerpKeeperV2.SettlePosition(ctx, c.pair, c.version, c.trader) if err != nil { - return ctx, err, false + return ctx, err } for _, checker := range c.responseCheckers { if err := checker(*resp); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, true + return ctx, nil } func SettlePosition(pair asset.Pair, version uint64, trader sdk.AccAddress, responseCheckers ...SettlePositionChecker) action.Action { @@ -109,13 +109,13 @@ type settlePositionShouldFail struct { trader sdk.AccAddress } -func (c settlePositionShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c settlePositionShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.SettlePosition(ctx, c.pair, c.version, c.trader) if err == nil { - return ctx, err, false + return ctx, err } - return ctx, nil, true + return ctx, nil } func SettlePositionShouldFail(pair asset.Pair, version uint64, trader sdk.AccAddress) action.Action { diff --git a/x/perp/v2/integration/action/snapshot.go b/x/perp/v2/integration/action/snapshot.go index 8d51a7954..c123907b5 100644 --- a/x/perp/v2/integration/action/snapshot.go +++ b/x/perp/v2/integration/action/snapshot.go @@ -19,7 +19,7 @@ type insertReserveSnapshot struct { modifiers []reserveSnapshotModifier } -func (i insertReserveSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (i insertReserveSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { amm := app.PerpKeeperV2.AMMs.GetOr(ctx, collections.Join(i.pair, uint64(1)), types.AMM{ Pair: i.pair, Version: uint64(1), @@ -40,7 +40,7 @@ func (i insertReserveSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Cont Amm: amm, }) - return ctx, nil, true + return ctx, nil } func InsertReserveSnapshot(pair asset.Pair, time time.Time, modifiers ...reserveSnapshotModifier) action.Action { diff --git a/x/perp/v2/integration/action/tx.go b/x/perp/v2/integration/action/tx.go index 1b37c0d81..81af0d908 100644 --- a/x/perp/v2/integration/action/tx.go +++ b/x/perp/v2/integration/action/tx.go @@ -22,7 +22,7 @@ type msgServerMarketOrder struct { baseAssetAmtLimit sdkmath.Int } -func (m msgServerMarketOrder) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerMarketOrder) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) // don't need to check response because it's already checked in clearing_house tests @@ -35,7 +35,7 @@ func (m msgServerMarketOrder) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Conte BaseAssetAmountLimit: m.baseAssetAmtLimit, }) - return ctx, err, true + return ctx, err } func MsgServerMarketOrder( @@ -61,7 +61,7 @@ type msgServerClosePosition struct { traderAddress sdk.AccAddress } -func (m msgServerClosePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerClosePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) // don't need to check response because it's already checked in clearing_house tests @@ -70,7 +70,7 @@ func (m msgServerClosePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Con Sender: m.traderAddress.String(), }) - return ctx, err, true + return ctx, err } func MsgServerClosePosition( @@ -89,7 +89,7 @@ type msgServerPartialClose struct { size sdk.Dec } -func (m msgServerPartialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerPartialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) // don't need to check response because it's already checked in clearing_house tests @@ -99,7 +99,7 @@ func (m msgServerPartialClose) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Cont Size_: m.size, }) - return ctx, err, true + return ctx, err } func MsgServerPartialClosePosition( @@ -120,12 +120,12 @@ type msgServerAddmargin struct { amount sdkmath.Int } -func (m msgServerAddmargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerAddmargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } // don't need to check response because it's already checked in clearing_house tests @@ -135,7 +135,7 @@ func (m msgServerAddmargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context Margin: sdk.NewCoin(collateral, m.amount), }) - return ctx, err, true + return ctx, err } func MsgServerAddMargin( @@ -156,12 +156,12 @@ type msgServerRemoveMargin struct { amount sdkmath.Int } -func (m msgServerRemoveMargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerRemoveMargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } // don't need to check response because it's already checked in clearing_house tests @@ -171,7 +171,7 @@ func (m msgServerRemoveMargin) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Cont Margin: sdk.NewCoin(collateral, m.amount), }) - return ctx, err, true + return ctx, err } func MsgServerRemoveMargin( @@ -192,7 +192,7 @@ type msgServerSettlePosition struct { Version uint64 } -func (m msgServerSettlePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerSettlePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) // don't need to check response because it's already checked in clearing_house tests @@ -202,7 +202,7 @@ func (m msgServerSettlePosition) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Co Version: m.Version, }) - return ctx, err, true + return ctx, err } func MsgServerSettlePosition( @@ -223,7 +223,7 @@ type msgServerSettlePositionShouldFail struct { Version uint64 } -func (m msgServerSettlePositionShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerSettlePositionShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) // don't need to check response because it's already checked in clearing_house tests @@ -233,10 +233,10 @@ func (m msgServerSettlePositionShouldFail) Do(app *app.NibiruApp, ctx sdk.Contex Version: m.Version, }) if err == nil { - return ctx, fmt.Errorf("should fail but no error returned"), true + return ctx, fmt.Errorf("should fail but no error returned") } - return ctx, nil, true + return ctx, nil } func MsgServerSettlePositionShouldFail( @@ -256,12 +256,12 @@ type msgServerDonateToPerpEf struct { amount sdkmath.Int } -func (m msgServerDonateToPerpEf) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerDonateToPerpEf) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) collateral, err := app.PerpKeeperV2.Collateral.Get(ctx) if err != nil { - return ctx, err, true + return ctx, err } _, err = msgServer.DonateToEcosystemFund(sdk.WrapSDKContext(ctx), &types.MsgDonateToEcosystemFund{ @@ -269,7 +269,7 @@ func (m msgServerDonateToPerpEf) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Co Donation: sdk.NewCoin(collateral, m.amount), }) - return ctx, err, true + return ctx, err } func MsgServerDonateToPerpEf( @@ -288,7 +288,7 @@ type msgServerMultiLiquidate struct { shouldAllFail bool } -func (m msgServerMultiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m msgServerMultiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { msgServer := keeper.NewMsgServerImpl(app.PerpKeeperV2) liquidateMsgs := make([]*types.MsgMultiLiquidate_Liquidation, len(m.pairTraderTuples)) @@ -304,7 +304,7 @@ func (m msgServerMultiLiquidate) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Co Liquidations: liquidateMsgs, }) - return ctx, err, m.shouldAllFail + return ctx, err } func MsgServerMultiLiquidate(liquidator sdk.AccAddress, shouldAllFail bool, pairTraderTuples ...PairTraderTuple) action.Action { diff --git a/x/perp/v2/integration/action/withdraw.go b/x/perp/v2/integration/action/withdraw.go index 6c8742e7e..22cd28891 100644 --- a/x/perp/v2/integration/action/withdraw.go +++ b/x/perp/v2/integration/action/withdraw.go @@ -16,15 +16,15 @@ type withdraw struct { } func (w withdraw) Do(app *app.NibiruApp, ctx sdk.Context) ( - outCtx sdk.Context, err error, isMandatory bool, + outCtx sdk.Context, err error, ) { market, err := app.PerpKeeperV2.GetMarket(ctx, w.Pair) if err != nil { - return ctx, err, true + return ctx, err } err = app.PerpKeeperV2.WithdrawFromVault(ctx, market, w.Account, w.Amount) - return ctx, err, true + return ctx, err } func WithdrawFromVault(pair asset.Pair, account sdk.AccAddress, amount sdkmath.Int) action.Action { diff --git a/x/perp/v2/integration/assertion/bank.go b/x/perp/v2/integration/assertion/bank.go index a0ee34478..53b5955c9 100644 --- a/x/perp/v2/integration/assertion/bank.go +++ b/x/perp/v2/integration/assertion/bank.go @@ -14,14 +14,16 @@ type moduleBalanceShouldBeEqual struct { expectedBalance sdk.Coins } -func (p moduleBalanceShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p moduleBalanceShouldBeEqual) IsNotMandatory() {} + +func (p moduleBalanceShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { balance := app.BankKeeper.GetAllBalances(ctx, app.AccountKeeper.GetModuleAddress(p.module)) if !balance.IsEqual(p.expectedBalance) { - return ctx, fmt.Errorf("balance expected for %s to be %s, received %s", p.module, p.expectedBalance.String(), balance.String()), false + return ctx, fmt.Errorf("balance expected for %s to be %s, received %s", p.module, p.expectedBalance.String(), balance.String()) } - return ctx, nil, false + return ctx, nil } func ModuleBalanceShouldBeEqualTo(module string, expectedBalance sdk.Coins) action.Action { diff --git a/x/perp/v2/integration/assertion/event.go b/x/perp/v2/integration/assertion/event.go index 4142a40f5..888a11d23 100644 --- a/x/perp/v2/integration/assertion/event.go +++ b/x/perp/v2/integration/assertion/event.go @@ -31,7 +31,7 @@ type containsLiquidateEvent struct { } func (act containsLiquidateEvent) Do(_ *app.NibiruApp, ctx sdk.Context) ( - outCtx sdk.Context, err error, isMandatory bool, + outCtx sdk.Context, err error, ) { foundEvent := false matchingEvents := []abci.Event{} @@ -48,14 +48,13 @@ func (act containsLiquidateEvent) Do(_ *app.NibiruApp, ctx sdk.Context) ( typedEvent, err := sdk.ParseTypedEvent(abciEvent) if err != nil { - return ctx, err, false + return ctx, err } liquidationFailedEvent, ok := typedEvent.(*types.LiquidationFailedEvent) if !ok { return ctx, - fmt.Errorf("expected event of type %s, got %s", proto.MessageName(act.expectedEvent), abciEvent.Type), - false + fmt.Errorf("expected event of type %s, got %s", proto.MessageName(act.expectedEvent), abciEvent.Type) } if reflect.DeepEqual(act.expectedEvent, liquidationFailedEvent) { @@ -68,7 +67,7 @@ func (act containsLiquidateEvent) Do(_ *app.NibiruApp, ctx sdk.Context) ( if foundEvent { // happy path - return ctx, nil, true + return ctx, nil } // Show descriptive error messages if the expected event is missing @@ -79,7 +78,7 @@ func (act containsLiquidateEvent) Do(_ *app.NibiruApp, ctx sdk.Context) ( fmt.Sprintf("found %v events:", len(ctx.EventManager().Events())), fmt.Sprintf("events of matching type:\n%v", sdk.StringifyEvents(matchingEvents).String()), }, "\n"), - ), false + ) } // ContainsLiquidateEvent checks if a typed event (proto.Message) is contained in the @@ -96,7 +95,9 @@ type positionChangedEventShouldBeEqual struct { expectedEvent *types.PositionChangedEvent } -func (p positionChangedEventShouldBeEqual) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p positionChangedEventShouldBeEqual) IsNotMandatory() {} + +func (p positionChangedEventShouldBeEqual) Do(_ *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { for _, sdkEvent := range ctx.EventManager().Events() { if sdkEvent.Type != proto.MessageName(p.expectedEvent) { continue @@ -109,16 +110,16 @@ func (p positionChangedEventShouldBeEqual) Do(_ *app.NibiruApp, ctx sdk.Context) typedEvent, err := sdk.ParseTypedEvent(abciEvent) if err != nil { - return ctx, err, false + return ctx, err } positionChangedEvent, ok := typedEvent.(*types.PositionChangedEvent) if !ok { - return ctx, fmt.Errorf("expected event is not of type PositionChangedEvent"), false + return ctx, fmt.Errorf("expected event is not of type PositionChangedEvent") } if err := types.PositionsAreEqual(&p.expectedEvent.FinalPosition, &positionChangedEvent.FinalPosition); err != nil { - return ctx, err, false + return ctx, err } if !reflect.DeepEqual(p.expectedEvent, positionChangedEvent) { @@ -127,13 +128,13 @@ func (p positionChangedEventShouldBeEqual) Do(_ *app.NibiruApp, ctx sdk.Context) want: %+v got: -%+v`, sdk.StringifyEvents([]abci.Event{abci.Event(expected)}), sdk.StringifyEvents([]abci.Event{abciEvent})), false +%+v`, sdk.StringifyEvents([]abci.Event{abci.Event(expected)}), sdk.StringifyEvents([]abci.Event{abciEvent})) } - return ctx, nil, false + return ctx, nil } - return ctx, fmt.Errorf("unable to find desired event of type %s", proto.MessageName(p.expectedEvent)), false + return ctx, fmt.Errorf("unable to find desired event of type %s", proto.MessageName(p.expectedEvent)) } // PositionChangedEventShouldBeEqual checks that the position changed event is diff --git a/x/perp/v2/integration/assertion/market.go b/x/perp/v2/integration/assertion/market.go index 4ab24b76b..d18ddcc11 100644 --- a/x/perp/v2/integration/assertion/market.go +++ b/x/perp/v2/integration/assertion/market.go @@ -21,19 +21,21 @@ type marketShouldBeEqual struct { Checkers []MarketChecker } -func (m marketShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (m marketShouldBeEqual) IsNotMandatory() {} + +func (m marketShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { market, err := app.PerpKeeperV2.GetMarket(ctx, m.Pair) if err != nil { - return ctx, err, false + return ctx, err } for _, checker := range m.Checkers { if err := checker(market); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } func MarketShouldBeEqual(pair asset.Pair, marketCheckers ...MarketChecker) action.Action { @@ -78,19 +80,21 @@ type ammShouldBeEqual struct { type AMMChecker func(amm types.AMM) error -func (a ammShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (a ammShouldBeEqual) IsNotMandatory() {} + +func (a ammShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { amm, err := app.PerpKeeperV2.GetAMM(ctx, a.Pair) if err != nil { - return ctx, err, false + return ctx, err } for _, checker := range a.Checkers { if err := checker(amm); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } func AMMShouldBeEqual(pair asset.Pair, ammCheckers ...AMMChecker) action.Action { diff --git a/x/perp/v2/integration/assertion/notional.go b/x/perp/v2/integration/assertion/notional.go index fed39d2a1..8fe14fc8a 100644 --- a/x/perp/v2/integration/assertion/notional.go +++ b/x/perp/v2/integration/assertion/notional.go @@ -18,22 +18,24 @@ type positionNotionalTwapShouldBeEqualTo struct { expectedNotionalValue sdk.Dec } -func (p positionNotionalTwapShouldBeEqualTo) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p positionNotionalTwapShouldBeEqualTo) IsNotMandatory() {} + +func (p positionNotionalTwapShouldBeEqualTo) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { position, err := app.PerpKeeperV2.GetPosition(ctx, p.pair, 1, p.trader) if err != nil { - return ctx, err, false + return ctx, err } notionalValue, err := app.PerpKeeperV2.PositionNotionalTWAP(ctx, position, p.twapLookbackWindow) if err != nil { - return ctx, err, false + return ctx, err } if !notionalValue.Equal(p.expectedNotionalValue) { - return ctx, fmt.Errorf("notional value expected to be %s, received %s", p.expectedNotionalValue, notionalValue), false + return ctx, fmt.Errorf("notional value expected to be %s, received %s", p.expectedNotionalValue, notionalValue) } - return ctx, nil, false + return ctx, nil } func PositionNotionalTWAPShouldBeEqualTo(pair asset.Pair, trader sdk.AccAddress, twapLookbackWindow time.Duration, expectedNotionalValue sdk.Dec) action.Action { diff --git a/x/perp/v2/integration/assertion/position.go b/x/perp/v2/integration/assertion/position.go index 1b601d969..f37b939f5 100644 --- a/x/perp/v2/integration/assertion/position.go +++ b/x/perp/v2/integration/assertion/position.go @@ -20,18 +20,20 @@ type positionShouldBeEqual struct { PositionCheckers []PositionChecker } -func (p positionShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p positionShouldBeEqual) IsNotMandatory() {} + +func (p positionShouldBeEqual) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { position, err := app.PerpKeeperV2.GetPosition(ctx, p.Pair, 1, p.Account) if err != nil { - return ctx, err, false + return ctx, err } for _, checker := range p.PositionCheckers { if err := checker(position); err != nil { - return ctx, err, false + return ctx, err } } - return ctx, nil, false + return ctx, nil } func PositionShouldBeEqual( @@ -64,13 +66,15 @@ type positionShouldNotExist struct { Version uint64 } -func (p positionShouldNotExist) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p positionShouldNotExist) IsNotMandatory() {} + +func (p positionShouldNotExist) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.GetPosition(ctx, p.Pair, p.Version, p.Account) if err == nil { - return ctx, fmt.Errorf("position should not exist, but it does with pair %s", p.Pair), false + return ctx, fmt.Errorf("position should not exist, but it does with pair %s", p.Pair) } - return ctx, nil, false + return ctx, nil } func PositionShouldNotExist(account sdk.AccAddress, pair asset.Pair, version uint64) action.Action { @@ -87,13 +91,15 @@ type positionShouldExist struct { Version uint64 } -func (p positionShouldExist) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (p positionShouldExist) IsNotMandatory() {} + +func (p positionShouldExist) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { _, err := app.PerpKeeperV2.GetPosition(ctx, p.Pair, p.Version, p.Account) if err != nil { - return ctx, fmt.Errorf("position should exist, but it does not with pair %s", p.Pair), false + return ctx, fmt.Errorf("position should exist, but it does not with pair %s", p.Pair) } - return ctx, nil, false + return ctx, nil } func PositionShouldExist(account sdk.AccAddress, pair asset.Pair, version uint64) action.Action { diff --git a/x/perp/v2/integration/assertion/twap.go b/x/perp/v2/integration/assertion/twap.go index 09dd9b706..124d04d46 100644 --- a/x/perp/v2/integration/assertion/twap.go +++ b/x/perp/v2/integration/assertion/twap.go @@ -22,17 +22,19 @@ type twalShouldBe struct { expectedTwap sdk.Dec } -func (c twalShouldBe) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) { +func (c twalShouldBe) IsNotMandatory() {} + +func (c twalShouldBe) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { twap, err := app.PerpKeeperV2.CalcTwap(ctx, c.pair, c.twapCalcOpt, c.dir, c.assetAmt, c.twapLookbackWindow) if err != nil { - return ctx, err, false + return ctx, err } if !twap.Equal(c.expectedTwap) { - return ctx, fmt.Errorf("invalid twap, expected %s, received %s", c.expectedTwap, twap), false + return ctx, fmt.Errorf("invalid twap, expected %s, received %s", c.expectedTwap, twap) } - return ctx, nil, false + return ctx, nil } func TwapShouldBe(pair asset.Pair, twapCalcOpt types.TwapCalcOption, dir types.Direction, assetAmt sdk.Dec, twapLookbackWindow time.Duration, expectedTwap sdk.Dec) action.Action { diff --git a/x/perp/v2/keeper/dnr_test.go b/x/perp/v2/keeper/dnr_test.go index 89f38c07c..1dcab9e46 100644 --- a/x/perp/v2/keeper/dnr_test.go +++ b/x/perp/v2/keeper/dnr_test.go @@ -255,31 +255,31 @@ func TestRebates(t *testing.T) { NewTestSuite(t).WithTestCases(tests...).Run() } -type actionFn func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) +type actionFn func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) -func (f actionFn) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { +func (f actionFn) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { return f(app, ctx) } func TestDnREpoch(t *testing.T) { dnrEpochIdentifierIs := func(identifier string) actionFn { - return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { + return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { app.PerpKeeperV2.DnREpochName.Set(ctx, identifier) - return ctx, nil, false + return ctx, nil } } triggerEpoch := func(identifier string, epoch uint64) actionFn { - return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { + return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { app.PerpKeeperV2.AfterEpochEnd(ctx, identifier, epoch) - return ctx, nil, false + return ctx, nil } } expectDnREpoch := func(epoch uint64) actionFn { - return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) { + return func(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error) { require.Equal(t, epoch, app.PerpKeeperV2.DnREpoch.GetOr(ctx, 0)) - return ctx, nil, false + return ctx, nil } }