Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Mar 6, 2024
1 parent 95853be commit 3295a5b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
8 changes: 5 additions & 3 deletions protocol/scripts/genesis/sample_pregenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@
"initial_margin_ppm": 100000,
"maintenance_fraction_ppm": 500000,
"name": "Mid-Cap",
"open_interest_lower_cap": 50000000000000
"open_interest_lower_cap": 25000000000000,
"open_interest_upper_cap": 50000000000000
},
{
"base_position_notional": 100000000000,
Expand All @@ -882,7 +883,8 @@
"initial_margin_ppm": 200000,
"maintenance_fraction_ppm": 500000,
"name": "Long-Tail",
"open_interest_lower_cap": 20000000000000
"open_interest_lower_cap": 10000000000000,
"open_interest_upper_cap": 20000000000000
},
{
"base_position_notional": 1000000000,
Expand Down Expand Up @@ -1821,7 +1823,7 @@
]
}
},
"app_version": "4.0.0-dev0-60-geb100ae0",
"app_version": "4.0.0-dev0-62-g95853be5",
"chain_id": "dydx-sample-1",
"consensus": {
"params": {
Expand Down
16 changes: 16 additions & 0 deletions protocol/testutil/constants/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_0DefaultFunding_0AtomicResolution = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -130,6 +131,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_NegativeDefaultFunding_10AtomicResolution = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -142,6 +144,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_0DefaultFunding_10AtomicResolution = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -154,6 +157,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_0DefaultFunding_10AtomicResolution_20IM_18MM = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -166,6 +170,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_0_001Percent_DefaultFunding_10AtomicResolution = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -178,6 +183,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_SmallMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -190,6 +196,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_100PercentMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -202,6 +209,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_50PercentInitial_40PercentMaintenance = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -214,6 +222,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_20PercentInitial_10PercentMaintenance = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -226,6 +235,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_NoMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -238,6 +248,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
EthUsd_0DefaultFunding_9AtomicResolution = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -250,6 +261,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
EthUsd_NoMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -262,6 +274,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
EthUsd_20PercentInitial_10PercentMaintenance = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -274,6 +287,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
EthUsd_100PercentMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -286,6 +300,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
SolUsd_20PercentInitial_10PercentMaintenance = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Expand All @@ -298,6 +313,7 @@ var (
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
)

Expand Down
24 changes: 20 additions & 4 deletions protocol/x/perpetuals/client/cli/query_perpetual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
)

var (
serializableIntCmpOpts = cmp.Options{
cmpopts.IgnoreFields(types.Perpetual{}, "FundingIndex"), // existing ignore option
cmp.FilterValues(
func(x, y dtypes.SerializableInt) bool {
// This will apply the custom comparer only to SerializableInt fields
return true // Apply this filter to all SerializableInt values
},
cmp.Comparer(func(x, y dtypes.SerializableInt) bool { return x.Cmp(y) == 0 }),
),
}
)

func networkWithLiquidityTierAndPerpetualObjects(
t *testing.T,
m int,
Expand Down Expand Up @@ -75,6 +88,7 @@ func networkWithLiquidityTierAndPerpetualObjects(
MarketType: marketType,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
nullify.Fill(&perpetual) //nolint:staticcheck
state.Perpetuals = append(state.Perpetuals, perpetual)
Expand Down Expand Up @@ -142,7 +156,8 @@ func TestShowPerpetual(t *testing.T) {
// FundingIndex field is ignored since it can vary depending on funding-tick epoch.
// TODO(DEC-606): Improve end-to-end testing related to ticking epochs.
func checkExpectedPerp(t *testing.T, expected types.Perpetual, received types.Perpetual) {
if diff := cmp.Diff(expected, received, cmpopts.IgnoreFields(types.Perpetual{}, "FundingIndex")); diff != "" {

if diff := cmp.Diff(expected, received, serializableIntCmpOpts...); diff != "" {
t.Errorf("resp.Perpetual mismatch (-want +received):\n%s", diff)
}
}
Expand Down Expand Up @@ -215,12 +230,13 @@ func TestListPerpetual(t *testing.T) {
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NoError(t, err)
require.Equal(t, len(objs), int(resp.Pagination.Total))
cmpOptions := []cmp.Option{
cmpopts.IgnoreFields(types.Perpetual{}, "FundingIndex"),
cmpOptions := append(
serializableIntCmpOpts,
cmpopts.SortSlices(func(x, y types.Perpetual) bool {
return x.Params.Id > y.Params.Id
}),
}
)

if diff := cmp.Diff(objs, resp.Perpetual, cmpOptions...); diff != "" {
t.Errorf("resp.Perpetual mismatch (-want +received):\n%s", diff)
}
Expand Down

0 comments on commit 3295a5b

Please sign in to comment.