Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
swelf19 committed Sep 9, 2024
1 parent 31ae53f commit 7865c59
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 75 deletions.
31 changes: 11 additions & 20 deletions tests/dex/state_cancel_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package dex_state_test

import (
"cosmossdk.io/math"
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
math_utils "github.com/neutron-org/neutron/v4/utils/math"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
"strconv"
"testing"
"time"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

math_utils "github.com/neutron-org/neutron/v4/utils/math"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
)

type cancelLimitOrderTestParams struct {
Expand Down Expand Up @@ -95,19 +97,13 @@ func (s *DexStateTestSuite) setupCancelTest(params cancelLimitOrderTestParams) *
}
tick, err := dextypes.CalcTickIndexFromPrice(DefaultStartPrice)
s.NoError(err)
tranches, _ := s.App.DexKeeper.LimitOrderTrancheAll(s.Ctx, &dextypes.QueryAllLimitOrderTrancheRequest{
PairId: params.PairID.CanonicalString(),
TokenIn: params.PairID.Token0,
Pagination: nil,
})
fmt.Println(tranches)

req := dextypes.QueryGetLimitOrderTrancheRequest{
PairId: params.PairID.CanonicalString(),
TickIndex: -1 * tick,
TokenIn: params.PairID.Token0,
TrancheKey: res.TrancheKey,
}
fmt.Println(req)
tranchResp, err := s.App.DexKeeper.LimitOrderTranche(s.Ctx, &req)
s.NoError(err)

Expand Down Expand Up @@ -159,7 +155,7 @@ func (s *DexStateTestSuite) handleCancelErrors(params cancelLimitOrderTestParams
s.NoError(err)
}

func (s *DexStateTestSuite) assertCalcelAmount(params cancelLimitOrderTestParams, ut *dextypes.LimitOrderTrancheUser) {
func (s *DexStateTestSuite) assertCalcelAmount(params cancelLimitOrderTestParams) {
depositSize := BaseTokenAmountInt

// expected balance: InitialBalance - depositSize + pre-withdrawn (filled/2 or 0) + withdrawn (filled/2 or filled)
Expand All @@ -171,7 +167,6 @@ func (s *DexStateTestSuite) assertCalcelAmount(params cancelLimitOrderTestParams
// 1 - withdrawn amount
s.assertBalanceWithPrecision(s.creator, params.PairID.Token1, expectedBalanceB, 3)

//s.assertBalance(s.creator, params.PairID.Token0, ut.SharesOwned.Sub(ut.SharesWithdrawn))
s.assertBalance(s.creator, params.PairID.Token0, expectedBalanceA)
}

Expand Down Expand Up @@ -201,16 +196,12 @@ func TestCancel(t *testing.T) {
tc.printTestInfo(t)

initialTrancheKey := s.setupCancelTest(tc)
fmt.Println(initialTrancheKey)
ut, _ := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.creator.String(), initialTrancheKey.Key.TrancheKey)

resp, err := s.makeCancel(s.creator, initialTrancheKey.Key.TrancheKey)
_, err := s.makeCancel(s.creator, initialTrancheKey.Key.TrancheKey)
s.handleCancelErrors(tc, err)
_, found := s.App.DexKeeper.GetLimitOrderTrancheUser(s.Ctx, s.creator.String(), initialTrancheKey.Key.TrancheKey)
s.False(found)
fmt.Println("resp", resp)
fmt.Println("err", err)
s.assertCalcelAmount(tc, ut)
s.assertCalcelAmount(tc)
})
}
}
13 changes: 6 additions & 7 deletions tests/dex/state_place_limit_order_maker_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package dex_state_test

import (
"strconv"
"testing"
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

math_utils "github.com/neutron-org/neutron/v4/utils/math"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
"strconv"
"testing"
"time"
)

// ExistingTokenAHolders
Expand Down Expand Up @@ -207,7 +209,6 @@ func (s *DexStateTestSuite) assertLiquidity(id dextypes.PairID) {

s.assertDexBalance(id.Token0, TokenAInReserves)
s.assertDexBalance(id.Token1, TokenBInReserves)

}

// We assume, if there is a TokenB tranche in dex module, it's always BEL.
Expand All @@ -233,7 +234,6 @@ func (s *DexStateTestSuite) expectedInOutTokensAmount(tokenA sdk.Coin, denomOut
if maxSwap.GTE(reserveA) {
// expected to get tokenB = tokenA*
amountOut = amountOut.Add(math_utils.NewPrecDecFromInt(reserveA).Mul(t.Price()).TruncateInt())
reserveA = math.ZeroInt()
break
}
reserveA = reserveA.Sub(maxSwap)
Expand All @@ -249,7 +249,7 @@ func (s *DexStateTestSuite) assertExpectedTrancheKey(initialKey, msgKey string,
return
}

//otherwise they are equal
// otherwise they are equal
s.Equal(initialKey, msgKey)
}

Expand Down Expand Up @@ -299,7 +299,6 @@ func TestPlaceLimitOrderMaker(t *testing.T) {
s.intsApproxEqual("", expectedSwapTakerDenom, resp.TakerCoinOut.Amount, 1)
// 3. TrancheKey assertion
s.assertExpectedTrancheKey(initialTrancheKey, resp.TrancheKey, tc)

})
}
s.SetT(t)
Expand Down
22 changes: 10 additions & 12 deletions tests/dex/state_place_limit_order_taker_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package dex_state_test

import (
"cosmossdk.io/math"
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
math_utils "github.com/neutron-org/neutron/v4/utils/math"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
"strconv"
"strings"
"testing"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

math_utils "github.com/neutron-org/neutron/v4/utils/math"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
)

// LiquidityType
Expand Down Expand Up @@ -156,8 +158,7 @@ func (s *DexStateTestSuite) setupLoTakerState(params placeLimitOrderTakerTestPar
TokenB: sdk.NewCoin(params.PairID.Token1, math.ZeroInt()),
}
// tick+DefaultFee to put liquidity the same tick as LO
resp, err := s.makeDeposit(s.alice, liduidity, DefaultFee, tick+DefaultFee, true)
fmt.Println(resp)
_, err := s.makeDeposit(s.alice, liduidity, DefaultFee, tick+DefaultFee, true)
s.NoError(err)
}
}
Expand Down Expand Up @@ -197,7 +198,7 @@ func ExpectedInOut(params placeLimitOrderTakerTestParams) (math.Int, math.Int) {
}
toOut := tickLiquidity
if params.MaxAmountOut != nil {
toOut = math.MinInt(toOut, (*params.MaxAmountOut).Sub(TotalOut))
toOut = math.MinInt(toOut, params.MaxAmountOut.Sub(TotalOut))
}

toIn := dextypes.MustCalcPrice(tick).MulInt(toOut).Ceil().TruncateInt()
Expand All @@ -219,7 +220,6 @@ func (s *DexStateTestSuite) handleTakerErrors(params placeLimitOrderTakerTestPar
if maxIn.LT(params.AmountIn.Amount) {
if errors.Is(err, dextypes.ErrFoKLimitOrderNotFilled) {
s.T().Skip()

}
}
}
Expand Down Expand Up @@ -249,7 +249,6 @@ func TestPlaceLimitOrderTaker(t *testing.T) {

for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
fmt.Println(testCasesRaw[i])
s.SetT(t)
tc.printTestInfo(t)

Expand All @@ -258,8 +257,7 @@ func TestPlaceLimitOrderTaker(t *testing.T) {
//

resp, err := s.makePlaceTakerLO(s.creator, tc.AmountIn, tc.PairID.Token0, tc.LimitPrice.String(), dextypes.LimitOrderType(tc.OrderType), tc.MaxAmountOut)
fmt.Println(resp)
fmt.Println(MaxAmountAOut(tc))

s.handleTakerErrors(tc, err)

expIn, expOut := ExpectedInOut(tc)
Expand Down
27 changes: 12 additions & 15 deletions tests/dex/state_setup_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package dex_state_test

import (
"cosmossdk.io/math"
"fmt"
"strconv"
"time"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/bank/types"
"strconv"
"time"

"github.com/neutron-org/neutron/v4/testutil/apptesting"
"github.com/neutron-org/neutron/v4/testutil/common/sample"
Expand Down Expand Up @@ -110,6 +112,7 @@ type LiquidityDistribution struct {
TokenB sdk.Coin
}

//nolint:unused
func (l LiquidityDistribution) doubleSided() bool {
return l.TokenA.Amount.IsPositive() && l.TokenB.Amount.IsPositive()
}
Expand All @@ -118,6 +121,7 @@ func (l LiquidityDistribution) empty() bool {
return l.TokenA.Amount.IsZero() && l.TokenB.Amount.IsZero()
}

//nolint:unused
func (l LiquidityDistribution) singleSided() bool {
return !l.doubleSided() && !l.empty()
}
Expand Down Expand Up @@ -234,7 +238,6 @@ func (s *DexStateTestSuite) GetBalances() Balances {

func (s *DexStateTestSuite) makeDepositDefault(addr sdk.AccAddress, depositAmts LiquidityDistribution, disableAutoSwap bool) (*dextypes.MsgDepositResponse, error) {
return s.makeDeposit(addr, depositAmts, DefaultFee, DefaultTick, disableAutoSwap)

}

func (s *DexStateTestSuite) makeDeposit(addr sdk.AccAddress, depositAmts LiquidityDistribution, fee uint64, tick int64, disableAutoSwap bool) (*dextypes.MsgDepositResponse, error) {
Expand All @@ -251,14 +254,15 @@ func (s *DexStateTestSuite) makeDeposit(addr sdk.AccAddress, depositAmts Liquidi
})
}

//nolint:unparam
func (s *DexStateTestSuite) makeDepositSuccess(addr sdk.AccAddress, depositAmts LiquidityDistribution, disableAutoSwap bool) *dextypes.MsgDepositResponse {
resp, err := s.makeDepositDefault(addr, depositAmts, disableAutoSwap)
s.NoError(err)

return resp
}

func (s *DexStateTestSuite) makeWithdraw(addr sdk.AccAddress, tokenA string, tokenB string, sharesToRemove math.Int) (*dextypes.MsgWithdrawalResponse, error) {
func (s *DexStateTestSuite) makeWithdraw(addr sdk.AccAddress, tokenA, tokenB string, sharesToRemove math.Int) (*dextypes.MsgWithdrawalResponse, error) {
return s.msgServer.Withdrawal(s.Ctx, &dextypes.MsgWithdrawal{
Creator: addr.String(),
Receiver: addr.String(),
Expand All @@ -270,7 +274,7 @@ func (s *DexStateTestSuite) makeWithdraw(addr sdk.AccAddress, tokenA string, tok
})
}

func (s *DexStateTestSuite) makePlaceTakerLO(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut string, sellPrice string, orderType dextypes.LimitOrderType, maxAmountOut *math.Int) (*dextypes.MsgPlaceLimitOrderResponse, error) {
func (s *DexStateTestSuite) makePlaceTakerLO(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut, sellPrice string, orderType dextypes.LimitOrderType, maxAmountOut *math.Int) (*dextypes.MsgPlaceLimitOrderResponse, error) {
p, err := math_utils.NewPrecDecFromStr(sellPrice)
if err != nil {
panic(err)
Expand All @@ -289,7 +293,7 @@ func (s *DexStateTestSuite) makePlaceTakerLO(addr sdk.AccAddress, amountIn sdk.C
})
}

func (s *DexStateTestSuite) makePlaceLO(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut string, sellPrice string, orderType dextypes.LimitOrderType, expTime *time.Time) (*dextypes.MsgPlaceLimitOrderResponse, error) {
func (s *DexStateTestSuite) makePlaceLO(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut, sellPrice string, orderType dextypes.LimitOrderType, expTime *time.Time) (*dextypes.MsgPlaceLimitOrderResponse, error) {
p, err := math_utils.NewPrecDecFromStr(sellPrice)
if err != nil {
panic(err)
Expand All @@ -308,10 +312,9 @@ func (s *DexStateTestSuite) makePlaceLO(addr sdk.AccAddress, amountIn sdk.Coin,
})
}

func (s *DexStateTestSuite) makePlaceLOSuccess(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut string, sellPrice string, orderType dextypes.LimitOrderType, expTime *time.Time) *dextypes.MsgPlaceLimitOrderResponse {
func (s *DexStateTestSuite) makePlaceLOSuccess(addr sdk.AccAddress, amountIn sdk.Coin, tokenOut, sellPrice string, orderType dextypes.LimitOrderType, expTime *time.Time) *dextypes.MsgPlaceLimitOrderResponse {
resp, err := s.makePlaceLO(addr, amountIn, tokenOut, sellPrice, orderType, expTime)
s.NoError(err)
fmt.Println("setup: ", resp)
return resp
}

Expand All @@ -322,12 +325,6 @@ func (s *DexStateTestSuite) makeCancel(addr sdk.AccAddress, trancheKey string) (
})
}

func (s *DexStateTestSuite) makeCancelSuccess(addr sdk.AccAddress, trancheKey string) *dextypes.MsgCancelLimitOrderResponse {
resp, err := s.makeCancel(addr, trancheKey)
s.NoError(err)
return resp
}

func (s *DexStateTestSuite) makeWithdrawFilled(addr sdk.AccAddress, trancheKey string) (*dextypes.MsgWithdrawFilledLimitOrderResponse, error) {
return s.msgServer.WithdrawFilledLimitOrder(s.Ctx, &dextypes.MsgWithdrawFilledLimitOrder{
Creator: addr.String(),
Expand Down
8 changes: 5 additions & 3 deletions tests/dex/state_withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package dex_state_test

import (
"fmt"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
"github.com/stretchr/testify/require"
"strconv"
"testing"

"github.com/stretchr/testify/require"

dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
)

type withdrawTestParams struct {
Expand Down Expand Up @@ -75,7 +77,7 @@ func hydrateAllWithdrawTestCases(paramsList []map[string]string) []withdrawTestP
tc.PairID = pairID
allTCs = append(allTCs, tc)
}

return allTCs
}

Expand Down
Loading

0 comments on commit 7865c59

Please sign in to comment.