genlayer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/tests/libs/jsonRpcClient.test.ts +60 -0
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -39699,7 +39699,7 @@ var {
|
|
|
39699
39699
|
} = import_index.default;
|
|
39700
39700
|
|
|
39701
39701
|
// package.json
|
|
39702
|
-
var version = "0.1.
|
|
39702
|
+
var version = "0.1.1";
|
|
39703
39703
|
|
|
39704
39704
|
// src/lib/config/text.ts
|
|
39705
39705
|
var CLI_DESCRIPTION = "GenLayer CLI is a development environment for the GenLayer ecosystem. It allows developers to interact with the protocol by creating accounts, sending transactions, and working with Intelligent Contracts by testing, debugging, and deploying them.";
|
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, beforeEach, test, expect, vi, Mock } from "vitest";
|
|
2
|
+
import fetch from "node-fetch";
|
|
3
|
+
import { JsonRpcClient, JsonRPCParams } from "../../src/lib/clients/jsonRpcClient";
|
|
4
|
+
|
|
5
|
+
vi.mock("node-fetch", () => ({
|
|
6
|
+
default: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe("JsonRpcClient - Successful and Unsuccessful Requests", () => {
|
|
10
|
+
let rpcClient: JsonRpcClient;
|
|
11
|
+
const mockServerUrl = "http://mock-server-url.com";
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
rpcClient = new JsonRpcClient(mockServerUrl);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("should make a successful JSON-RPC request and return the JSON response", async () => {
|
|
18
|
+
const mockResponse = { result: "success" };
|
|
19
|
+
|
|
20
|
+
(fetch as Mock).mockResolvedValueOnce({
|
|
21
|
+
ok: true,
|
|
22
|
+
json: async () => mockResponse,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const params: JsonRPCParams = {
|
|
26
|
+
method: "testMethod",
|
|
27
|
+
params: ["param1", "param2"],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const response = await rpcClient.request(params);
|
|
31
|
+
|
|
32
|
+
expect(fetch).toHaveBeenCalledWith(mockServerUrl, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: { "Content-Type": "application/json" },
|
|
35
|
+
body: expect.stringContaining('"method":"testMethod"'),
|
|
36
|
+
});
|
|
37
|
+
expect(response).toEqual(mockResponse);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("should return null when the fetch response is not ok", async () => {
|
|
41
|
+
(fetch as Mock).mockResolvedValueOnce({
|
|
42
|
+
ok: false,
|
|
43
|
+
json: async () => ({ error: "Something went wrong" }),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const params: JsonRPCParams = {
|
|
47
|
+
method: "testMethod",
|
|
48
|
+
params: ["param1", "param2"],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const response = await rpcClient.request(params);
|
|
52
|
+
|
|
53
|
+
expect(response).toBeNull();
|
|
54
|
+
expect(fetch).toHaveBeenCalledWith(mockServerUrl, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: expect.stringContaining('"method":"testMethod"'),
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|