Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
  • Loading branch information
shrenujb committed Apr 23, 2024
1 parent a94c952 commit b7051e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions protocol/x/perpetuals/keeper/perpetual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3542,3 +3542,35 @@ func TestModifyOpenInterest_store(t *testing.T) {
require.Equal(t, perpetualObject.OpenInterest, serializedOpenInterest)
}
}

func TestIsIsolatedPerpetual(t *testing.T) {
testCases := map[string]struct {
perp types.Perpetual
expected bool
}{
"Isolated Perpetual": {
perp: *perptest.GeneratePerpetual(
perptest.WithMarketType(types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED),
),
expected: true,
},
"Cross Perpetual": {
perp: *perptest.GeneratePerpetual(
perptest.WithMarketType(types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS),
),
expected: false,
},
}

for name, tc := range testCases {
t.Run(
name, func(t *testing.T) {
pc := keepertest.PerpetualsKeepers(t)
pc.PerpetualsKeeper.SetPerpetual(pc.Ctx, tc.perp)
isIsolated, err := pc.PerpetualsKeeper.IsIsolatedPerpetual(pc.Ctx, tc.perp.Params.Id)
require.NoError(t, err)
require.Equal(t, tc.expected, isIsolated)
},
)
}
}

0 comments on commit b7051e5

Please sign in to comment.