File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change
1
+ import { expect , it } from "bun:test" ;
2
+ import { createClient } from "./client" ;
3
+
4
+ it ( "fetches transaction count" , async ( ) => {
5
+ const client = createClient ( { network : "devnet" } ) ;
6
+ const { result } = await client . request ( {
7
+ method : "mina_getTransactionCount" ,
8
+ params : [ "B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS" ] ,
9
+ } ) ;
10
+ expect ( result ) . toBeGreaterThan ( 0 ) ;
11
+ } ) ;
Original file line number Diff line number Diff line change @@ -5,13 +5,23 @@ import { z } from "zod";
5
5
6
6
const NetworkMatcher = z . enum ( [ "mainnet" , "devnet" ] ) ;
7
7
8
- export const createClient = ( {
9
- network,
10
- } : { network : "mainnet" | "devnet" } ) => {
11
- return match ( NetworkMatcher . parse ( network ) )
12
- . with ( "devnet" , ( ) => hc < KlesiaRpc > ( "https://devnet.klesia.palladians.xyz" ) )
8
+ type CreateClientProps = { network : "mainnet" | "devnet" ; customUrl ?: string } ;
9
+
10
+ export const createClient = ( { network, customUrl } : CreateClientProps ) => {
11
+ const baseClient = match ( NetworkMatcher . parse ( network ) )
12
+ . with ( "devnet" , ( ) =>
13
+ hc < KlesiaRpc > ( customUrl ?? "https://devnet.klesia.palladians.xyz" ) ,
14
+ )
13
15
. with ( "mainnet" , ( ) =>
14
- hc < KlesiaRpc > ( "https://mainnet.klesia.palladians.xyz" ) ,
16
+ hc < KlesiaRpc > ( customUrl ?? "https://mainnet.klesia.palladians.xyz" ) ,
15
17
)
16
18
. exhaustive ( ) ;
19
+ const rpcHandler = baseClient . api . $post ;
20
+ type RpcRequest = Parameters < typeof rpcHandler > [ 0 ] ;
21
+ const request = async ( req : RpcRequest [ "json" ] ) => {
22
+ return ( await baseClient . api . $post ( { json : req } ) ) . json ( ) ;
23
+ } ;
24
+ return {
25
+ request,
26
+ } ;
17
27
} ;
You can’t perform that action at this time.
0 commit comments