Skip to content

Commit

Permalink
test: add more hook test keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt committed Jul 25, 2023
1 parent d3178e8 commit 73fc859
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions x/perp/v2/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,63 @@ func TestAfterEpochEnd(t *testing.T) {
Then(
MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())),
),

TC("missing twap").
Given(
CreateCustomMarket(pairBtcUsdc),
SetBlockTime(startTime),
StartEpoch(epochtypes.ThirtyMinuteEpochID),
).
When(
MoveToNextBlockWithDuration(30 * time.Minute),
).
Then(
MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())),
),

TC("0 price mark").
Given(
CreateCustomMarket(pairBtcUsdc),
SetBlockTime(startTime),
StartEpoch(epochtypes.ThirtyMinuteEpochID),
InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.ZeroDec()),
).
When(
MoveToNextBlockWithDuration(30 * time.Minute),
).
Then(
MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())),
),

TC("market not enabled").
Given(
CreateCustomMarket(pairBtcUsdc),
SetMarketEnabled(pairBtcUsdc, false),
SetBlockTime(startTime),
StartEpoch(epochtypes.ThirtyMinuteEpochID),
InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.NewDec(2)),
).
When(
MoveToNextBlockWithDuration(30 * time.Minute),
).
Then(
MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())),
),

TC("not correct epoch id").
Given(
CreateCustomMarket(pairBtcUsdc),
SetMarketEnabled(pairBtcUsdc, false),
SetBlockTime(startTime),
StartEpoch(epochtypes.FifteenMinuteEpochID),
InsertOraclePriceSnapshot(pairBtcUsdc, startTime.Add(15*time.Minute), sdk.NewDec(2)),
).
When(
MoveToNextBlockWithDuration(30 * time.Minute),
).
Then(
MarketShouldBeEqual(pairBtcUsdc, Market_LatestCPFShouldBeEqualTo(sdk.ZeroDec())),
),
}

NewTestSuite(t).WithTestCases(tc...).Run()
Expand Down

0 comments on commit 73fc859

Please sign in to comment.