Skip to content

Commit

Permalink
fix(klesia): decouple server from exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Sep 9, 2024
1 parent 8b296dd commit 21f552c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 55 deletions.
4 changes: 2 additions & 2 deletions apps/klesia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"scripts": {
"build": "tsup-node",
"dev": "tsup-node --watch --onSuccess \"node dist/index.js\"",
"start": "node dist/index.js",
"dev": "tsup-node --watch --onSuccess \"node dist/server.js\"",
"start": "node dist/server.js",
"test": "bun test"
},
"dependencies": {
Expand Down
86 changes: 44 additions & 42 deletions apps/klesia/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
import { expect, it } from "bun:test";
import { describe, expect, it } from "bun:test";
import { testClient } from "hono/testing";
import { klesiaRpcRoute } from "./";

const client = testClient(klesiaRpcRoute);
const request = testClient(klesiaRpcRoute).api.$post;

it("returns result for mina_getTransactionCount", async () => {
const response = await client.api.$post({
json: {
method: "mina_getTransactionCount",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
describe("Mina Devnet RPC", () => {
it("returns result for mina_getTransactionCount", async () => {
const response = await request({
json: {
method: "mina_getTransactionCount",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
});
const { result } = (await response.json()) as { result: string };
expect(BigInt(result)).toBeGreaterThan(0);
});
const { result } = (await response.json()) as { result: string };
expect(BigInt(result)).toBeGreaterThan(0);
});

it("returns result for mina_getBalance", async () => {
const response = await client.api.$post({
json: {
method: "mina_getBalance",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
it("returns result for mina_getBalance", async () => {
const response = await request({
json: {
method: "mina_getBalance",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
});
const { result } = (await response.json()) as { result: string };
expect(BigInt(String(result))).toBeGreaterThan(0);
});
const { result } = (await response.json()) as { result: string };
expect(BigInt(String(result))).toBeGreaterThan(0);
});

it("returns result for mina_blockHash", async () => {
const response = await client.api.$post({
json: { method: "mina_blockHash" },
it("returns result for mina_blockHash", async () => {
const response = await request({
json: { method: "mina_blockHash" },
});
const { result } = (await response.json()) as { result: string };
expect(result.length).toBeGreaterThan(0);
});
const { result } = (await response.json()) as { result: string };
expect(result.length).toBeGreaterThan(0);
});

it("returns result for mina_chainId", async () => {
const response = await client.api.$post({
json: { method: "mina_chainId" },
it("returns result for mina_chainId", async () => {
const response = await request({
json: { method: "mina_chainId" },
});
const { result } = (await response.json()) as { result: string };
expect(result.length).toBeGreaterThan(0);
});
const { result } = (await response.json()) as { result: string };
expect(result.length).toBeGreaterThan(0);
});

it("returns result for mina_getAccount", async () => {
const response = await client.api.$post({
json: {
method: "mina_getAccount",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
it("returns result for mina_getAccount", async () => {
const response = await request({
json: {
method: "mina_getAccount",
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
},
});
// biome-ignore lint/suspicious/noExplicitAny: TODO
const { result } = (await response.json()) as any;
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
});
// biome-ignore lint/suspicious/noExplicitAny: TODO
const { result } = (await response.json()) as any;
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
});
10 changes: 1 addition & 9 deletions apps/klesia/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "dotenv/config";
import { serve } from "@hono/node-server";
import { getConnInfo } from "@hono/node-server/conninfo";
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
import { PublicKeySchema } from "@mina-js/shared";
import { rateLimiter } from "hono-rate-limiter";
import { cors } from "hono/cors";
Expand Down Expand Up @@ -142,13 +141,6 @@ export const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
.exhaustive();
});

serve(
{ fetch: api.fetch, port: z.coerce.number().parse(process.env.PORT ?? 3000) },
(info) => {
console.log(`Listening on http://localhost:${info.port}`);
},
);

export type KlesiaRpc = typeof klesiaRpcRoute;
export {
KlesiaNetwork,
Expand Down
10 changes: 10 additions & 0 deletions apps/klesia/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { serve } from "@hono/node-server";
import { z } from "@hono/zod-openapi";
import { api } from "./";

serve(
{ fetch: api.fetch, port: z.coerce.number().parse(process.env.PORT ?? 3000) },
(info) => {
console.log(`Listening on http://localhost:${info.port}`);
},
);
6 changes: 5 additions & 1 deletion apps/klesia/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { defineConfig } from "tsup";
import sharedConfig from "../../packages/shared/tsup.config";

export default sharedConfig;
export default defineConfig({
...sharedConfig,
entry: ["src/index.ts", "src/server.ts"],
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "turbo build",
"test": "bun run --filter '*' test",
"test": "turbo test",
"cleanup": "bun run --filter '*' cleanup",
"lint": "bunx biome check .",
"format": "bunx biome check . --write --unsafe"
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"test": {},
"cleanup": {},
"dev": {
"persistent": true,
Expand Down

0 comments on commit 21f552c

Please sign in to comment.