Skip to content

Commit

Permalink
add test case for negative fees
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
  • Loading branch information
shrenujb committed Jun 26, 2024
1 parent 3fa5de8 commit bbd93c9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion protocol/x/subaccounts/keeper/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ func TestDistributeFees(t *testing.T) {
marketMapperAccBalance: big.NewInt(0),
quantums: big.NewInt(500),
expectedSubaccountsModuleAccBalance: big.NewInt(100), // 600 - 500
expectedFeeModuleAccBalance: big.NewInt(2950), // 500 + 2500 - 50
expectedFeeModuleAccBalance: big.NewInt(2950), // 2500 + 500 - 50
expectedMarketMapperAccBalance: big.NewInt(50), // 0 + 50
perpetualId: 4,
collateralPoolAddr: authtypes.NewModuleAddress(
Expand Down Expand Up @@ -1344,6 +1344,26 @@ func TestDistributeFees(t *testing.T) {
setRevenueShare: true,
revShareExpiration: -10,
},
"success - negative fees to market mapper and fee collector": {
asset: *constants.Usdc,
feeModuleAccBalance: big.NewInt(2500),
subaccountModuleAccBalance: big.NewInt(600),
marketMapperAccBalance: big.NewInt(100),
quantums: big.NewInt(-500),
expectedSubaccountsModuleAccBalance: big.NewInt(1100), // 600 + 500
expectedFeeModuleAccBalance: big.NewInt(2050), // 2500 - (500 - 50)
expectedMarketMapperAccBalance: big.NewInt(50), // 100 - 50
perpetualId: 4,
collateralPoolAddr: authtypes.NewModuleAddress(
types.ModuleName + ":" + lib.IntToString(4),
),

marketMapperAddr: constants.AliceAccAddress,
revenueSharePpm: 100_000,
validDays: 240,
setRevenueShare: true,
revShareExpiration: 100,
},
// TODO(DEC-715): Add more test for non-USDC assets, after asset update
// is implemented.
}
Expand Down Expand Up @@ -1399,6 +1419,18 @@ func TestDistributeFees(t *testing.T) {
require.NoError(t, err)
}

if tc.marketMapperAccBalance.Sign() > 0 {
err := bank_testutil.FundAccount(
ctx,
tc.marketMapperAddr,
sdk.Coins{
sdk.NewCoin(tc.asset.Denom, sdkmath.NewIntFromBigInt(tc.marketMapperAccBalance)),
},
*bankKeeper,
)
require.NoError(t, err)
}

// Always create USDC as the first asset.
if !tc.skipSetUpUsdc {
err := keepertest.CreateUsdcAsset(ctx, assetsKeeper)
Expand Down

0 comments on commit bbd93c9

Please sign in to comment.