Skip to content

Commit

Permalink
switch to use the helper method to create positions (#1787)
Browse files Browse the repository at this point in the history
jayy04 authored Jun 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d1e89a4 commit 2d2d0f3
Showing 28 changed files with 2,288 additions and 2,263 deletions.
78 changes: 40 additions & 38 deletions protocol/daemons/liquidation/client/sub_task_runner_test.go
Original file line number Diff line number Diff line change
@@ -2,16 +2,18 @@ package client_test

import (
"context"
"cosmossdk.io/log"
"math/big"
"testing"

"cosmossdk.io/log"

"github.com/dydxprotocol/v4-chain/protocol/daemons/flags"
"github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/api"
"github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/client"
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/mocks"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"github.com/dydxprotocol/v4-chain/protocol/testutil/grpc"
testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util"
blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
@@ -283,17 +285,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) {
{
Id: &constants.Carl_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(55_000_000_000), // $55,000
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(55_000_000_000), // $55,000
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(-100_000_000), // -1 BTC
FundingIndex: dtypes.NewInt(10_000),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(-100_000_000), // -1 BTC
big.NewInt(10_000),
),
},
},
},
@@ -363,17 +365,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) {
{
Id: &constants.Dave_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(-45_000_000_000), // -$45,000
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(-45_000_000_000), // -$45,000
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(100_000_000), // 1 BTC
FundingIndex: dtypes.NewInt(-10_000),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(100_000_000), // 1 BTC
big.NewInt(-10_000),
),
},
},
},
@@ -443,17 +445,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) {
{
Id: &constants.Carl_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(54_999_000_000), // $54,999
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(54_999_000_000), // $54,999
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(-100_000_000), // -1 BTC
FundingIndex: dtypes.NewInt(-10_000),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(-100_000_000), // -1 BTC
big.NewInt(-10_000),
),
},
},
},
@@ -521,17 +523,17 @@ func TestRunLiquidationDaemonTaskLoop(t *testing.T) {
{
Id: &constants.Dave_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(-44_999_000_000), // -$44,999
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(-44_999_000_000), // -$44,999
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(100_000_000), // 1 BTC
FundingIndex: dtypes.NewInt(10_000),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(100_000_000), // 1 BTC
big.NewInt(10_000),
),
},
},
},
28 changes: 15 additions & 13 deletions protocol/x/clob/client/cli/liquidations_cli_test.go
Original file line number Diff line number Diff line change
@@ -6,18 +6,19 @@ import (
"fmt"
"math"

appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags"
"math/big"
"testing"

appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags"

networktestutil "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/lib"
testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util"
assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil"
clob_testutil "github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
epochstypes "github.com/dydxprotocol/v4-chain/protocol/x/epochs/types"
feetierstypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types"
@@ -128,7 +129,7 @@ func (s *LiquidationsIntegrationTestSuite) SetupSuite() {
s.cfg.GenesisState[types.ModuleName] = buf

// Set the balances in the genesis state.
s.cfg.GenesisState[banktypes.ModuleName] = testutil.CreateBankGenesisState(
s.cfg.GenesisState[banktypes.ModuleName] = clob_testutil.CreateBankGenesisState(
s.T(),
s.cfg,
liqTestInitialSubaccountModuleAccBalance,
@@ -147,16 +148,17 @@ func (s *LiquidationsIntegrationTestSuite) SetupSuite() {
satypes.Subaccount{
Id: &satypes.SubaccountId{Owner: s.validatorAddress.String(), Number: liqTestSubaccountNumberOne},
AssetPositions: []*satypes.AssetPosition{
{
AssetId: assettypes.AssetUsdc.Id,
Quantums: dtypes.NewInt(-45_001_000_000), // -$45,001
},
testutil.CreateSingleAssetPosition(
assettypes.AssetUsdc.Id,
big.NewInt(-45_001_000_000), // -$45,001
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(100_000_000), // 1 BTC
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(100_000_000), // 1 BTC
big.NewInt(0),
),
},
},
)
@@ -211,7 +213,7 @@ func (s *LiquidationsIntegrationTestSuite) TestCLILiquidations() {
subticks := types.Subticks(50_000_000_000)

// Place the maker order that should be filled by the liquidation order.
_, err = testutil.MsgPlaceOrderExec(
_, err = clob_testutil.MsgPlaceOrderExec(
ctx,
s.validatorAddress,
liqTestSubaccountNumberZero,
39 changes: 20 additions & 19 deletions protocol/x/clob/e2e/app_test.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package clob_test

import (
"fmt"
"math/big"
"sync"
"testing"
"time"
@@ -15,7 +16,6 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/dydxprotocol/v4-chain/protocol/app/config"
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/testutil/rand"
"gopkg.in/typ.v4/slices"

@@ -25,6 +25,7 @@ import (
clobtestutils "github.com/dydxprotocol/v4-chain/protocol/testutil/clob"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
testtx "github.com/dydxprotocol/v4-chain/protocol/testutil/tx"
testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
epochtypes "github.com/dydxprotocol/v4-chain/protocol/x/epochs/types"
feetierstypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types"
@@ -525,35 +526,35 @@ func TestHydrationWithMatchPreBlocker(t *testing.T) {
require.Equal(t, satypes.Subaccount{
Id: &constants.Carl_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(100_000_000_000 - 50_000_000_000),
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(100_000_000_000-50_000_000_000),
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(100_000_000),
FundingIndex: dtypes.NewInt(0),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(100_000_000),
big.NewInt(0),
),
},
}, carl)

dave := tApp.App.SubaccountsKeeper.GetSubaccount(ctx, constants.Dave_Num0)
require.Equal(t, satypes.Subaccount{
Id: &constants.Dave_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(500_000_000_000 + 50_000_000_000),
},
testutil.CreateSingleAssetPosition(
0,
big.NewInt(500_000_000_000+50_000_000_000),
),
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 0,
Quantums: dtypes.NewInt(-100_000_000),
FundingIndex: dtypes.NewInt(0),
},
testutil.CreateSinglePerpetualPosition(
0,
big.NewInt(-100_000_000),
big.NewInt(0),
),
},
}, dave)

Loading

0 comments on commit 2d2d0f3

Please sign in to comment.