Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
  • Loading branch information
shrenujb committed Mar 4, 2024
1 parent 8372175 commit 84786cb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
67 changes: 34 additions & 33 deletions protocol/x/clob/keeper/process_operations_liquidations_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package keeper_test

import (
storetypes "cosmossdk.io/store/types"
"errors"
"fmt"
"math"
"testing"

storetypes "cosmossdk.io/store/types"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -199,10 +200,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(10_000_000)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Subaccount pays $250 to insurance fund for liquidating 1 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(250_000_000)),
).Return(nil).Once()
Expand Down Expand Up @@ -283,10 +284,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.Anything,
).Return(sdk.NewCoin("USDC", sdkmath.NewIntFromUint64(math.MaxUint64)))
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
perptypes.InsuranceFundName,
satypes.ModuleName,
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
authtypes.NewModuleAddress(satypes.ModuleName),
// Insurance fund covers $1 loss for liquidating 1 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(1_000_000)),
).Return(nil).Once()
Expand Down Expand Up @@ -363,10 +364,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(2_500_000)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Subaccount pays $62.5 to insurance fund for liquidating 0.25 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(62_500_000)),
).Return(nil).Twice()
Expand Down Expand Up @@ -467,10 +468,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.Anything,
).Return(sdk.NewCoin("USDC", sdkmath.NewIntFromUint64(math.MaxUint64)))
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
perptypes.InsuranceFundName,
satypes.ModuleName,
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
authtypes.NewModuleAddress(satypes.ModuleName),
// Insurance fund covers $0.25 loss for liquidating 0.25 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(250_000)),
).Return(nil).Twice()
Expand Down Expand Up @@ -572,18 +573,18 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.Anything,
).Return(sdk.NewCoin("USDC", sdkmath.NewIntFromUint64(math.MaxUint64)))
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Pays insurance fund $0.75 for liquidating 0.75 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(750_000)),
).Return(nil).Once()
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
perptypes.InsuranceFundName,
satypes.ModuleName,
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
authtypes.NewModuleAddress(satypes.ModuleName),
// Insurance fund covers $0.25 loss for liquidating 0.25 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(250_000)),
).Return(nil).Once()
Expand Down Expand Up @@ -676,19 +677,19 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.Anything,
).Return(sdk.NewCoin("USDC", sdkmath.NewIntFromUint64(math.MaxUint64)))
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Pays insurance fund $0.378735 (capped by MaxLiquidationFeePpm)
// for liquidating 0.75 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(378_735)),
).Return(nil).Once()
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Pays insurance fund $0.121265.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(121_265)),
).Return(nil).Once()
Expand Down Expand Up @@ -783,10 +784,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(5_000_000)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Subaccount pays $125 to insurance fund for liquidating 0.5 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(125_000_000)),
).Return(nil).Once()
Expand Down Expand Up @@ -896,10 +897,10 @@ func TestProcessProposerMatches_Liquidation_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(1)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(25)),
).Return(nil)
},
Expand Down Expand Up @@ -1269,10 +1270,10 @@ func TestProcessProposerMatches_Liquidation_Failure(t *testing.T) {
mock.Anything,
).Return(fmt.Errorf("transfer failed"))
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
mock.Anything,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
mock.Anything,
).Return(nil)
},
Expand Down
12 changes: 6 additions & 6 deletions protocol/x/clob/keeper/process_operations_long_term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ func TestProcessProposerMatches_LongTerm_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(10_000_000)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Subaccount pays $250 to insurance fund for liquidating 1 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(250_000_000)),
).Return(nil).Once()
Expand Down Expand Up @@ -666,10 +666,10 @@ func TestProcessProposerMatches_LongTerm_Success(t *testing.T) {
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(10_000_000)),
).Return(nil)
bk.On(
"SendCoinsFromModuleToModule",
"SendCoins",
mock.Anything,
satypes.ModuleName,
perptypes.InsuranceFundName,
authtypes.NewModuleAddress(satypes.ModuleName),
authtypes.NewModuleAddress(perptypes.InsuranceFundName),
// Subaccount pays $250 to insurance fund for liquidating 1 BTC.
mock.MatchedBy(testutil_bank.MatchUsdcOfAmount(250_000_000)),
).Return(nil).Once()
Expand Down
7 changes: 7 additions & 0 deletions protocol/x/clob/keeper/process_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,13 @@ func setupProcessProposerOperationsTestCase(
mock.Anything,
mock.Anything,
).Return(nil)
mockBankKeeper.On(
"SendCoins",
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
).Return(nil)
mockBankKeeper.On(
"GetBalance",
mock.Anything,
Expand Down

0 comments on commit 84786cb

Please sign in to comment.