Skip to content

Commit

Permalink
Retry mildly flaky sleep tests
Browse files Browse the repository at this point in the history
Fix lint/tsconfig issues with config files

Force `unstable_cache` to store the candlestick cached data as raw JSON database data instead of bigint/structured data

Add comment

Remove non-existent import

Don't output pre-commit logs if the hook passes

Lint/format
  • Loading branch information
xbtmatt committed Nov 6, 2024
1 parent a2aed1b commit 3d9d845
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
path: './src/python/hooks/.venv'
- uses: 'pre-commit/[email protected]'
with:
extra_args: '--all-files --config cfg/pre-commit-config.yaml --verbose'
extra_args: '--all-files --config cfg/pre-commit-config.yaml'
name: 'pre-commit'
'on':
pull_request: null
Expand Down
3 changes: 2 additions & 1 deletion src/typescript/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = {
"node_modules/**",
".eslintrc.js",
"config-overrides.js",
"playwright.config.ts",
"next.config.mjs",
"playwright.config.js",
"postcss.config.js",
"tailwind.config.js",
"tests/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
baseURL: "http://127.0.0.1:3001",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "retain-on-first-failure",
trace: "on-first-retry",

launchOptions: {
env: {
Expand Down
13 changes: 7 additions & 6 deletions src/typescript/frontend/src/app/candlesticks/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { fetchPeriodicEventsSince } from "@/queries/market";
import { type Period, toPeriod } from "@sdk/index";
import { type PeriodicStateEventModel } from "@sdk/indexer-v2/types";
import { type PeriodTypeFromDatabase } from "@sdk/indexer-v2/types/json-types";
import { stringifyJSONWithBigInts } from "@sdk/indexer-v2/json-bigint";
import {
type DatabaseJsonType,
type PeriodTypeFromDatabase,
} from "@sdk/indexer-v2/types/json-types";
import { parseInt } from "lodash";
import { unstable_cache } from "next/cache";
import { type NextRequest } from "next/server";
import { stringifyJSON } from "utils";

const CANDLESTICKS_LIMIT = 500;

Expand All @@ -18,7 +20,7 @@ type QueryParams = {

const getCandlesticks = async (params: QueryParams) => {
const { marketID, start, period, limit } = params;
const aggregate: PeriodicStateEventModel[] = [];
const aggregate: DatabaseJsonType["periodic_state_events"][] = [];

while (aggregate.length < limit) {
const data = await fetchPeriodicEventsSince({
Expand Down Expand Up @@ -75,6 +77,5 @@ export async function GET(request: NextRequest) {
const marketID = parseInt(marketIDStr);

const data = await getCachedCandlesticks({ marketID, start, period, limit });

return new Response(stringifyJSON(data));
return new Response(stringifyJSONWithBigInts(data));
}
12 changes: 9 additions & 3 deletions src/typescript/frontend/src/components/charts/PrivateChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { useEventStore } from "context/event-store-context";
import { getPeriodStartTimeFromTime } from "@sdk/utils";
import { getAptosConfig } from "lib/utils/aptos-client";
import { getSymbolEmojisInString, symbolToEmojis, toMarketEmojiData } from "@sdk/emoji_data";
import { type PeriodicStateEventModel, type MarketMetadataModel } from "@sdk/indexer-v2/types";
import {
type PeriodicStateEventModel,
type MarketMetadataModel,
toPeriodicStateEventModel,
} from "@sdk/indexer-v2/types";
import { getMarketResource } from "@sdk/markets";
import { Aptos } from "@aptos-labs/ts-sdk";
import { PeriodDuration, periodEnumToRawDuration, Trigger } from "@sdk/const";
Expand All @@ -40,7 +44,8 @@ import {
periodicStateTrackerToLatestBar,
toBar,
} from "@/store/event/candlestick-bars";
import { parseJSON } from "utils";
import { parseJSONWithBigInts } from "@sdk/indexer-v2/json-bigint";
import { type DatabaseJsonType } from "@sdk/indexer-v2/types/json-types";

const configurationData: DatafeedConfiguration = {
supported_resolutions: TV_CHARTING_LIBRARY_RESOLUTIONS,
Expand Down Expand Up @@ -169,7 +174,8 @@ export const Chart = (props: ChartContainerProps) => {
});
const data: PeriodicStateEventModel[] = await fetch(`/candlesticks?${params.toString()}`)
.then((res) => res.text())
.then((res) => parseJSON(res));
.then((res) => parseJSONWithBigInts<DatabaseJsonType["periodic_state_events"][]>(res))
.then((res) => res.map(toPeriodicStateEventModel));

const isFetchForMostRecentBars = end.getTime() - new Date().getTime() > 1000;

Expand Down
3 changes: 1 addition & 2 deletions src/typescript/frontend/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../tsconfig.json",
"include": [
"**/*.ts",
"../playwright.config.ts"
"**/*.ts"
]
}
65 changes: 0 additions & 65 deletions src/typescript/sdk/src/indexer-v2/queries/app/candlesticks.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/typescript/sdk/src/indexer-v2/queries/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./home";
export * from "./market";
export * from "./pools";
export * from "./candlesticks";
13 changes: 5 additions & 8 deletions src/typescript/sdk/src/indexer-v2/queries/app/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ if (process.env.NODE_ENV !== "test") {

import { LIMIT, ORDER_BY } from "../../../queries";
import { type AnyNumberString } from "../../../types";
import { TableName } from "../../types/json-types";
import { type DatabaseJsonType, TableName } from "../../types/json-types";
import { postgrest, toQueryArray } from "../client";
import { queryHelper, queryHelperSingle } from "../utils";
import {
toChatEventModel,
toMarketStateModel,
toPeriodicStateEventModel,
toSwapEventModel,
} from "../../types";
import { toChatEventModel, toMarketStateModel, toSwapEventModel } from "../../types";
import { type PeriodicStateEventQueryArgs, type MarketStateQueryArgs } from "../../types/common";
import { type SymbolEmoji } from "../../../emoji_data/types";

Expand Down Expand Up @@ -68,8 +63,10 @@ const selectMarketState = ({ searchEmojis }: { searchEmojis: SymbolEmoji[] }) =>

export const fetchSwapEvents = queryHelper(selectSwapsByMarketID, toSwapEventModel);
export const fetchChatEvents = queryHelper(selectChatsByMarketID, toChatEventModel);
// Note the lack of a conversion function here- this is because we must cache the data
// with no bigints, so we store it as the raw database JSON data.
export const fetchPeriodicEventsSince = queryHelper(
selectPeriodicEventsSince,
toPeriodicStateEventModel
(r: DatabaseJsonType["periodic_state_events"]) => r
);
export const fetchMarketState = queryHelperSingle(selectMarketState, toMarketStateModel);
2 changes: 2 additions & 0 deletions src/typescript/sdk/tests/unit/sleep.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getTime, sleep, UNIT_OF_TIME_MULTIPLIERS, UnitOfTime } from "../../src";

jest.retryTimes(3);

describe("sleep utility function with units of time", () => {
it("converts units of time to milliseconds", () => {
expect(UNIT_OF_TIME_MULTIPLIERS[UnitOfTime.Microseconds]).toEqual(0.001);
Expand Down

0 comments on commit 3d9d845

Please sign in to comment.