Skip to content

Commit

Permalink
make test more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown unknown committed Sep 19, 2023
1 parent 954601e commit 5ca0fd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion x/perp/v2/integration/action/dnr.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context,

balanceBefore = balanceBefore.Sub(resp.MarginToVault.TruncateInt())

expectedFee := math.LegacyNewDecFromInt(o.margin).Mul(o.fee)
expectedFee := math.LegacyNewDecFromInt(o.margin).Mul(o.fee.Add(sdk.MustNewDecFromStr("0.001"))) // we add the ecosystem fund fee
balanceAfter := app.BankKeeper.GetBalance(ctx, o.trader, o.pair.QuoteDenom()).Amount
paidFees := balanceBefore.Sub(balanceAfter)
if !paidFees.Equal(expectedFee.TruncateInt()) {
Expand Down
31 changes: 20 additions & 11 deletions x/perp/v2/keeper/dnr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ func TestDiscount(t *testing.T) {
positionSize := sdk.NewInt(10_000)
startBlockTime := time.Now()

ecosystemFee := sdk.MustNewDecFromStr("0.0010") // 0.1%, default fee taken from CreateCustomMarketAction
exchangeFee := sdk.MustNewDecFromStr("0.0010") // 0.1%, default fee taken from CreateCustomMarketAction
exchangeFee := sdk.MustNewDecFromStr("0.0010") // 0.1%, default fee taken from CreateCustomMarketAction
globalFeeDiscount := sdk.MustNewDecFromStr("0.0005") // 0.05%
fauxGlobalFeeDiscount := sdk.MustNewDecFromStr("0.0004") // 0.05%
customFeeDiscount := sdk.MustNewDecFromStr("0.0002") // 0.02%
fauxCustomFeeDiscount := sdk.MustNewDecFromStr("0.0003") // 0.03%

tests := TestCases{
TC("user does not have any past epoch volume: no discount applies").
Expand All @@ -126,7 +129,7 @@ func TestDiscount(t *testing.T) {
DnREpochIs(1),
).
Then(
MarketOrderFeeIs(exchangeFee.Add(ecosystemFee), alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
MarketOrderFeeIs(exchangeFee, alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
),
TC("user has past epoch volume: no discount applies").
Given(
Expand All @@ -143,11 +146,13 @@ func TestDiscount(t *testing.T) {
FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(100_000_000)))),
).
When(
SetGlobalDiscount(exchangeFee.QuoInt64(2), sdk.NewInt(100_000)),
SetCustomDiscount(alice, exchangeFee.QuoInt64(10), sdk.NewInt(100_000)),
SetGlobalDiscount(fauxGlobalFeeDiscount, sdk.NewInt(50_000)),
SetGlobalDiscount(globalFeeDiscount, sdk.NewInt(100_000)),
SetCustomDiscount(alice, fauxCustomFeeDiscount, sdk.NewInt(50_000)),
SetCustomDiscount(alice, customFeeDiscount, sdk.NewInt(100_000)),
SetPreviousEpochUserVolume(alice, sdk.NewInt(10_000)),
).Then(
MarketOrderFeeIs(exchangeFee.Add(ecosystemFee), alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
MarketOrderFeeIs(exchangeFee, alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
),
TC("user has past epoch volume: custom discount applies").
Given(
Expand All @@ -164,12 +169,14 @@ func TestDiscount(t *testing.T) {
FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(100_000_000)))),
).
When(
SetGlobalDiscount(exchangeFee.QuoInt64(2), sdk.NewInt(100_000)),
SetCustomDiscount(alice, exchangeFee.QuoInt64(10), sdk.NewInt(100_000)),
SetGlobalDiscount(sdk.MustNewDecFromStr("0.0004"), sdk.NewInt(50_000)),
SetGlobalDiscount(fauxGlobalFeeDiscount, sdk.NewInt(100_000)),
SetCustomDiscount(alice, fauxCustomFeeDiscount, sdk.NewInt(50_000)),
SetCustomDiscount(alice, customFeeDiscount, sdk.NewInt(100_000)),
SetPreviousEpochUserVolume(alice, sdk.NewInt(100_000)),
).
Then(
MarketOrderFeeIs(ecosystemFee.Add(exchangeFee.QuoInt64(10)), alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
MarketOrderFeeIs(customFeeDiscount, alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
),
TC("user has past epoch volume: global discount applies").
Given(
Expand All @@ -186,11 +193,13 @@ func TestDiscount(t *testing.T) {
FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(100_000_000)))),
).
When(
SetGlobalDiscount(exchangeFee.QuoInt64(2), sdk.NewInt(100_000)),
SetGlobalDiscount(sdk.MustNewDecFromStr("0.0004"), sdk.NewInt(50_000)),
SetGlobalDiscount(globalFeeDiscount, sdk.NewInt(100_000)),
SetCustomDiscount(alice, sdk.MustNewDecFromStr("0.0003"), sdk.NewInt(50_000)),
SetPreviousEpochUserVolume(alice, sdk.NewInt(100_000)),
).
Then(
MarketOrderFeeIs(ecosystemFee.Add(exchangeFee.QuoInt64(2)), alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
MarketOrderFeeIs(globalFeeDiscount, alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()),
),
}
NewTestSuite(t).WithTestCases(tests...).Run()
Expand Down

0 comments on commit 5ca0fd0

Please sign in to comment.