Skip to content

Commit

Permalink
chore(minajs): remove scalar and add tests for klesia
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Sep 6, 2024
1 parent ed51624 commit 5ebb0fd
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 29 deletions.
63 changes: 55 additions & 8 deletions apps/docs/docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,63 @@ MinaJS is a set of packages and apps built by our team. The aim is to provide a

The libraries are available on npm. You can install them using npm, yarn, pnpm, and bun (yep, we support Bun).

```bash
# Install MinaJS Connect
$ npm install @mina-js/connect
<div role="tablist" className="tabs tabs-boxed">
<input type="radio" name="my_tabs_2" role="tab" className="tab ml-2" aria-label="NPM" checked="checked" readOnly />
<div role="tabpanel" className="tab-content">
```bash
# Install MinaJS Connect
$ npm install @mina-js/connect

# Install MinaJS Accounts
$ npm install @mina-js/accounts
# Install MinaJS Accounts
$ npm install @mina-js/accounts

# Install Klesia SDK
$ npm install @mina-js/klesia-sdk
```
# Install Klesia SDK
$ npm install @mina-js/klesia-sdk
```
</div>

<input type="radio" name="my_tabs_2" role="tab" className="tab" aria-label="Yarn" />
<div role="tabpanel" className="tab-content">
```bash
# Install MinaJS Connect
$ yarn add @mina-js/connect

# Install MinaJS Accounts
$ yarn add @mina-js/accounts

# Install Klesia SDK
$ yarn add @mina-js/klesia-sdk
```
</div>

<input type="radio" name="my_tabs_2" role="tab" className="tab" aria-label="PNPM" />
<div role="tabpanel" className="tab-content">
```bash
# Install MinaJS Connect
$ pnpm add @mina-js/connect

# Install MinaJS Accounts
$ pnpm add @mina-js/accounts

# Install Klesia SDK
$ pnpm add @mina-js/klesia-sdk
```
</div>

<input type="radio" name="my_tabs_2" role="tab" className="tab" aria-label="Bun" />
<div role="tabpanel" className="tab-content">
```bash
# Install MinaJS Connect
$ bun add @mina-js/connect

# Install MinaJS Accounts
$ bun add @mina-js/accounts

# Install Klesia SDK
$ bun add @mina-js/klesia-sdk
```
</div>
</div>

## SDK specific usage

Expand Down
19 changes: 19 additions & 0 deletions apps/docs/docs/pages/roadmap.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Roadmap

```mermaid
timeline
section Q4 2024
MinaJS
: @mina-js/connect Beta
: @mina-js/provider Beta
: @mina-js/accounts Beta
Klesia
: Klesia RPC Beta
: @mina-js/klesia-sdk Beta
section Q1 2025
MinaJS
: Auro Wallet integration
Klesia
: Zeko integration
: Protokit integration
```
4 changes: 4 additions & 0 deletions apps/docs/vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default defineConfig({
text: "FAQ",
link: "/faq",
},
{
text: "Roadmap",
link: "/roadmap",
},
{
text: "MinaJS Connect",
link: "/connect",
Expand Down
4 changes: 2 additions & 2 deletions apps/klesia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"scripts": {
"build": "tsup-node",
"dev": "tsup-node --watch --onSuccess \"node dist/index.js\"",
"start": "node dist/index.js"
"start": "node dist/index.js",
"test": "bun test"
},
"dependencies": {
"@hono/node-server": "^1.12.2",
"@hono/zod-openapi": "^0.16.0",
"@mina-js/shared": "workspace:*",
"@scalar/hono-api-reference": "^0.5.143",
"@urql/core": "^5.0.6",
"dayjs": "^1.11.13",
"dotenv": "^16.4.5",
Expand Down
43 changes: 43 additions & 0 deletions apps/klesia/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, it } from "bun:test";
import { testClient } from "hono/testing";
import { klesiaRpcRoute } from "./";

const client = testClient(klesiaRpcRoute);

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

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

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

it("returns result for mina_chainId", async () => {
const response = await client.api.$post({
json: { method: "mina_chainId" },
});
const { result } = await response.json();
expect((result as unknown as string).length).toBeGreaterThan(0);
});
22 changes: 6 additions & 16 deletions apps/klesia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { serve } from "@hono/node-server";
import { getConnInfo } from "@hono/node-server/conninfo";
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
import { PublicKeySchema } from "@mina-js/shared";
import { apiReference } from "@scalar/hono-api-reference";
import { rateLimiter } from "hono-rate-limiter";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
Expand All @@ -15,12 +14,15 @@ import { mina } from "./methods/mina";
import { RpcMethodSchema, RpcResponseSchema } from "./schema";
import { buildResponse } from "./utils/build-response";

const api = new OpenAPIHono();
export const api = new OpenAPIHono();

api.use(logger());
api.use(
rateLimiter({
skip: (c) => c.req.path !== "/api" || c.req.method !== "POST",
skip: (c) =>
process.env.NODE_ENV === "test" ||
c.req.path !== "/api" ||
c.req.method !== "POST",
keyGenerator: (c) =>
c.req.header("x-forwarded-for") ??
getConnInfo(c).remote.address ??
Expand Down Expand Up @@ -58,9 +60,7 @@ const rpcRoute = createRoute({
},
});

api.get("/", ({ redirect }) => redirect("/api", 301));

const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
export const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
const body = req.valid("json");
return match(body)
.with({ method: "mina_getTransactionCount" }, async ({ params }) => {
Expand Down Expand Up @@ -93,16 +93,6 @@ const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
.exhaustive();
});

api.get(
"/api",
apiReference({
spec: {
url: "/api/openapi",
},
theme: "deepSpace",
}),
);

serve(api);

export type KlesiaRpc = typeof klesiaRpcRoute;
24 changes: 24 additions & 0 deletions apps/klesia/src/methods/mina.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, it } from "bun:test";
import { mina } from "./mina";

const TEST_PKEY = "B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS";

it("should return transactions count", async () => {
const result = await mina.getTransactionCount({ publicKey: TEST_PKEY });
expect(result).toBeGreaterThan(0);
});

it("should return balance", async () => {
const result = await mina.getBalance({ publicKey: TEST_PKEY });
expect(BigInt(result)).toBeGreaterThan(0);
});

it("should return block hash", async () => {
const result = await mina.blockHash();
expect(result.length).toBeGreaterThan(0);
});

it("should return chain id", async () => {
const result = await mina.chainId();
expect(result.length).toBeGreaterThan(0);
});
16 changes: 13 additions & 3 deletions apps/klesia/src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import { z } from "zod";

const NetworkMatcher = z.enum(["devnet", "mainnet"]);

const MINA_NETWORK = NetworkMatcher.parse(process.env.MINA_NETWORK);
const NODE_API_DEVNET = z.string().parse(process.env.NODE_API_DEVNET);
const NODE_API_MAINNET = z.string().parse(process.env.NODE_API_MAINNET);
const MINA_NETWORK = NetworkMatcher.parse(process.env.MINA_NETWORK ?? "devnet");
const NODE_API_DEVNET = z
.string()
.parse(
process.env.NODE_API_DEVNET ??
"https://api.minascan.io/node/devnet/v1/graphql",
);
const NODE_API_MAINNET = z
.string()
.parse(
process.env.NODE_API_MAINNET ??
"https://api.minascan.io/node/mainnet/v1/graphql",
);

export const getNodeApiUrl = () => {
return match(MINA_NETWORK)
Expand Down
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 5ebb0fd

Please sign in to comment.