@hashgraphonline/conversational-agent 0.2.216 → 0.2.217
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/cli/readme.md +181 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/config.d.ts +6 -0
- package/dist/cjs/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/cjs/plugins/community/swarm/index.d.ts +2 -0
- package/dist/cjs/plugins/community/swarm/model.d.ts +23 -0
- package/dist/cjs/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/cjs/plugins/index.d.ts +1 -0
- package/dist/esm/index.js +33 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +13 -677
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +601 -234
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +296 -136
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +127 -235
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +247 -84
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +81 -159
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +155 -229
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +238 -140
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +139 -493
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +479 -91
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +88 -147
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +127 -666
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +698 -44
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +45 -304
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +303 -153
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +150 -117
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +154 -18
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +18 -22
- package/dist/esm/index27.js.map +1 -1
- package/dist/esm/index28.js +15 -74
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +70 -295
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index30.js +279 -100
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +86 -922
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +904 -189
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +185 -1169
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +1218 -112
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +111 -99
- package/dist/esm/index35.js.map +1 -1
- package/dist/esm/index36.js +113 -8
- package/dist/esm/index36.js.map +1 -1
- package/dist/esm/index37.js +8 -45
- package/dist/esm/index37.js.map +1 -1
- package/dist/esm/index38.js +41 -102
- package/dist/esm/index38.js.map +1 -1
- package/dist/esm/index39.js +96 -55
- package/dist/esm/index39.js.map +1 -1
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index40.js +58 -71
- package/dist/esm/index40.js.map +1 -1
- package/dist/esm/index41.js +79 -21
- package/dist/esm/index41.js.map +1 -1
- package/dist/esm/index42.js +21 -5
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +4 -11
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +12 -322
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +280 -142
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +181 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +7 -95
- package/dist/esm/index47.js.map +1 -1
- package/dist/esm/index48.js +77 -7
- package/dist/esm/index48.js.map +1 -1
- package/dist/esm/index49.js +75 -0
- package/dist/esm/index49.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index50.js +57 -0
- package/dist/esm/index50.js.map +1 -0
- package/dist/esm/index51.js +103 -0
- package/dist/esm/index51.js.map +1 -0
- package/dist/esm/index52.js +79 -0
- package/dist/esm/index52.js.map +1 -0
- package/dist/esm/index53.js +75 -0
- package/dist/esm/index53.js.map +1 -0
- package/dist/esm/index54.js +124 -0
- package/dist/esm/index54.js.map +1 -0
- package/dist/esm/index55.js +58 -0
- package/dist/esm/index55.js.map +1 -0
- package/dist/esm/index56.js +83 -0
- package/dist/esm/index56.js.map +1 -0
- package/dist/esm/index57.js +100 -0
- package/dist/esm/index57.js.map +1 -0
- package/dist/esm/index58.js +118 -0
- package/dist/esm/index58.js.map +1 -0
- package/dist/esm/index59.js +108 -0
- package/dist/esm/index59.js.map +1 -0
- package/dist/esm/index6.js +132 -833
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index60.js +30 -0
- package/dist/esm/index60.js.map +1 -0
- package/dist/esm/index61.js +98 -0
- package/dist/esm/index61.js.map +1 -0
- package/dist/esm/index62.js +131 -0
- package/dist/esm/index62.js.map +1 -0
- package/dist/esm/index63.js +19 -0
- package/dist/esm/index63.js.map +1 -0
- package/dist/esm/index7.js +826 -75
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +91 -13
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +13 -17
- package/dist/esm/index9.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/config.d.ts +6 -0
- package/dist/types/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/types/plugins/community/swarm/index.d.ts +2 -0
- package/dist/types/plugins/community/swarm/model.d.ts +23 -0
- package/dist/types/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/types/plugins/index.d.ts +1 -0
- package/package.json +36 -26
- package/src/index.ts +1 -0
- package/src/plugins/community/swarm/README.md +279 -0
- package/src/plugins/community/swarm/SwarmPlugin.ts +178 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.mocks.ts +105 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.ts +152 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.ts +163 -0
- package/src/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.ts +132 -0
- package/src/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.ts +83 -0
- package/src/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.ts +219 -0
- package/src/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.ts +169 -0
- package/src/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.ts +133 -0
- package/src/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.ts +67 -0
- package/src/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.ts +148 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadDataTool.test.ts +125 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFileTool.test.ts +194 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.ts +118 -0
- package/src/plugins/community/swarm/config.ts +6 -0
- package/src/plugins/community/swarm/constants.ts +12 -0
- package/src/plugins/community/swarm/index.ts +2 -0
- package/src/plugins/community/swarm/model.ts +23 -0
- package/src/plugins/community/swarm/tools/CreatePostageStampTool.ts +137 -0
- package/src/plugins/community/swarm/tools/DownloadDataTool.ts +79 -0
- package/src/plugins/community/swarm/tools/DownloadFilesTool.ts +155 -0
- package/src/plugins/community/swarm/tools/ExtendPostageStampTool.ts +112 -0
- package/src/plugins/community/swarm/tools/GetPostageStampTool.ts +92 -0
- package/src/plugins/community/swarm/tools/ListPostageStampsTool.ts +124 -0
- package/src/plugins/community/swarm/tools/QueryUploadProgressTool.ts +109 -0
- package/src/plugins/community/swarm/tools/ReadFeedTool.ts +110 -0
- package/src/plugins/community/swarm/tools/UpdateFeedTool.ts +149 -0
- package/src/plugins/community/swarm/tools/UploadDataTool.ts +109 -0
- package/src/plugins/community/swarm/tools/UploadFileTool.ts +163 -0
- package/src/plugins/community/swarm/tools/UploadFolderTool.ts +150 -0
- package/src/plugins/community/swarm/utils.ts +172 -0
- package/src/plugins/index.ts +1 -0
- package/cli/dist/CLIApp.d.ts +0 -11
- package/cli/dist/CLIApp.d.ts.map +0 -1
- package/cli/dist/CLIApp.js +0 -128
- package/cli/dist/CLIApp.js.map +0 -1
- package/cli/dist/LocalConversationalAgent.d.ts +0 -37
- package/cli/dist/LocalConversationalAgent.js +0 -58
- package/cli/dist/app.d.ts +0 -18
- package/cli/dist/app.d.ts.map +0 -1
- package/cli/dist/app.js +0 -14
- package/cli/dist/app.js.map +0 -1
- package/cli/dist/cli.d.ts +0 -3
- package/cli/dist/cli.d.ts.map +0 -1
- package/cli/dist/cli.js +0 -87
- package/cli/dist/cli.js.map +0 -1
- package/cli/dist/components/AppContainer.d.ts +0 -16
- package/cli/dist/components/AppContainer.js +0 -24
- package/cli/dist/components/AppScreens.d.ts +0 -2
- package/cli/dist/components/AppScreens.js +0 -259
- package/cli/dist/components/ChatScreen.d.ts +0 -21
- package/cli/dist/components/ChatScreen.d.ts.map +0 -1
- package/cli/dist/components/ChatScreen.js +0 -40
- package/cli/dist/components/ChatScreen.js.map +0 -1
- package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
- package/cli/dist/components/DebugLoadingScreen.js +0 -31
- package/cli/dist/components/LoadingScreen.d.ts +0 -3
- package/cli/dist/components/LoadingScreen.d.ts.map +0 -1
- package/cli/dist/components/LoadingScreen.js +0 -17
- package/cli/dist/components/LoadingScreen.js.map +0 -1
- package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
- package/cli/dist/components/LoadingScreenDebug.js +0 -27
- package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
- package/cli/dist/components/MCPConfigScreen.d.ts.map +0 -1
- package/cli/dist/components/MCPConfigScreen.js +0 -186
- package/cli/dist/components/MCPConfigScreen.js.map +0 -1
- package/cli/dist/components/ScreenRouter.d.ts +0 -13
- package/cli/dist/components/ScreenRouter.d.ts.map +0 -1
- package/cli/dist/components/ScreenRouter.js +0 -23
- package/cli/dist/components/ScreenRouter.js.map +0 -1
- package/cli/dist/components/SetupScreen.d.ts +0 -16
- package/cli/dist/components/SetupScreen.d.ts.map +0 -1
- package/cli/dist/components/SetupScreen.js +0 -67
- package/cli/dist/components/SetupScreen.js.map +0 -1
- package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
- package/cli/dist/components/SingleLoadingScreen.js +0 -27
- package/cli/dist/components/StatusBadge.d.ts +0 -10
- package/cli/dist/components/StatusBadge.d.ts.map +0 -1
- package/cli/dist/components/StatusBadge.js +0 -24
- package/cli/dist/components/StatusBadge.js.map +0 -1
- package/cli/dist/components/TerminalWindow.d.ts +0 -9
- package/cli/dist/components/TerminalWindow.d.ts.map +0 -1
- package/cli/dist/components/TerminalWindow.js +0 -19
- package/cli/dist/components/TerminalWindow.js.map +0 -1
- package/cli/dist/components/WelcomeScreen.d.ts +0 -12
- package/cli/dist/components/WelcomeScreen.d.ts.map +0 -1
- package/cli/dist/components/WelcomeScreen.js +0 -47
- package/cli/dist/components/WelcomeScreen.js.map +0 -1
- package/cli/dist/context/AppContext.d.ts +0 -68
- package/cli/dist/context/AppContext.js +0 -363
- package/cli/dist/headless-runner.d.ts +0 -17
- package/cli/dist/headless-runner.d.ts.map +0 -1
- package/cli/dist/headless-runner.js +0 -128
- package/cli/dist/headless-runner.js.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
- package/cli/dist/hooks/useInitializeAgent.d.ts.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.js +0 -29
- package/cli/dist/hooks/useInitializeAgent.js.map +0 -1
- package/cli/dist/hooks/useStableState.d.ts +0 -38
- package/cli/dist/hooks/useStableState.d.ts.map +0 -1
- package/cli/dist/hooks/useStableState.js +0 -69
- package/cli/dist/hooks/useStableState.js.map +0 -1
- package/cli/dist/managers/AgentManager.d.ts +0 -58
- package/cli/dist/managers/AgentManager.d.ts.map +0 -1
- package/cli/dist/managers/AgentManager.js +0 -121
- package/cli/dist/managers/AgentManager.js.map +0 -1
- package/cli/dist/managers/ConfigManager.d.ts +0 -54
- package/cli/dist/managers/ConfigManager.d.ts.map +0 -1
- package/cli/dist/managers/ConfigManager.js +0 -188
- package/cli/dist/managers/ConfigManager.js.map +0 -1
- package/cli/dist/types.d.ts +0 -52
- package/cli/dist/types.d.ts.map +0 -1
- package/cli/dist/types.js +0 -34
- package/cli/dist/types.js.map +0 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
|
|
4
|
+
import { ListPostageStampsTool } from '../../tools/ListPostageStampsTool';
|
|
5
|
+
import { GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from '../../constants';
|
|
6
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
7
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
8
|
+
import { PostageBatch, Duration, Size } from '@ethersphere/bee-js';
|
|
9
|
+
import { PostageBatchCurated, PostageBatchSummary, ResponseContent } from '../../model';
|
|
10
|
+
import type { ToolResponse } from '../../utils';
|
|
11
|
+
|
|
12
|
+
describe('ListPostageStampsTool', () => {
|
|
13
|
+
let tool: ListPostageStampsTool;
|
|
14
|
+
let hederaKitMock: HederaAgentKit;
|
|
15
|
+
const rawBatch = {
|
|
16
|
+
usageText: '0%',
|
|
17
|
+
remainingSize: Size.fromMegabytes(1),
|
|
18
|
+
size: Size.fromMegabytes(1),
|
|
19
|
+
immutableFlag: true,
|
|
20
|
+
duration: Duration.fromWeeks(1),
|
|
21
|
+
usable: true
|
|
22
|
+
} as unknown as PostageBatch;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
27
|
+
|
|
28
|
+
tool = new ListPostageStampsTool({
|
|
29
|
+
hederaKit: hederaKitMock,
|
|
30
|
+
config: swarmConfigMock,
|
|
31
|
+
bee: beeMock,
|
|
32
|
+
logger: contextMock.logger,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should handle Bee.getPostageBatches not found error', async () => {
|
|
37
|
+
const error = new Error('Not found');
|
|
38
|
+
(error as any).status = NOT_FOUND_STATUS;
|
|
39
|
+
beeMock.getPostageBatches.mockRejectedValue(error);
|
|
40
|
+
|
|
41
|
+
await expect(tool['executeQuery']({}))
|
|
42
|
+
.rejects.toThrow(GATEWAY_STAMP_ERROR_MESSAGE);
|
|
43
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
44
|
+
GATEWAY_STAMP_ERROR_MESSAGE,
|
|
45
|
+
error
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should handle Bee.getPostageBatches other errors', async () => {
|
|
50
|
+
const error = new Error('Server error');
|
|
51
|
+
beeMock.getPostageBatches.mockRejectedValue(error);
|
|
52
|
+
|
|
53
|
+
await expect(tool['executeQuery']({}))
|
|
54
|
+
.rejects.toThrow('Retrieval of postage batches failed.');
|
|
55
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
56
|
+
'Retrieval of postage batches failed.',
|
|
57
|
+
error
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should return all usable postage batches by default', async () => {
|
|
62
|
+
const mockBatches = [
|
|
63
|
+
{
|
|
64
|
+
...rawBatch,
|
|
65
|
+
batchID: { toHex: () => 'batch1' },
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
...rawBatch,
|
|
69
|
+
batchID: { toHex: () => 'batch2' },
|
|
70
|
+
usable: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
...rawBatch,
|
|
74
|
+
batchID: { toHex: () => 'batch3' },
|
|
75
|
+
},
|
|
76
|
+
] as unknown as PostageBatch[];
|
|
77
|
+
|
|
78
|
+
beeMock.getPostageBatches.mockResolvedValue(mockBatches);
|
|
79
|
+
|
|
80
|
+
const result = await tool['executeQuery']({}) as ToolResponse;
|
|
81
|
+
const structured = result.structuredContent as ResponseContent<
|
|
82
|
+
PostageBatchCurated[],
|
|
83
|
+
PostageBatchSummary[]
|
|
84
|
+
>;
|
|
85
|
+
|
|
86
|
+
// Expect only usable batches (2 total)
|
|
87
|
+
expect(structured.raw.length).toBe(2);
|
|
88
|
+
expect(structured.raw.map(b => b.batchID)).toEqual(['batch1', 'batch3']);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should filter by minUsage and maxUsage', async () => {
|
|
92
|
+
const mockBatches = [
|
|
93
|
+
{
|
|
94
|
+
...rawBatch,
|
|
95
|
+
batchID: { toHex: () => 'a' },
|
|
96
|
+
usable: true,
|
|
97
|
+
usage: 0.1
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
...rawBatch,
|
|
101
|
+
batchID: { toHex: () => 'b' },
|
|
102
|
+
usable: true,
|
|
103
|
+
usage: 0.5
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
...rawBatch,
|
|
107
|
+
batchID: { toHex: () => 'c' },
|
|
108
|
+
usable: true,
|
|
109
|
+
usage: 0.9
|
|
110
|
+
},
|
|
111
|
+
] as unknown as PostageBatch[];
|
|
112
|
+
|
|
113
|
+
beeMock.getPostageBatches.mockResolvedValue(mockBatches);
|
|
114
|
+
|
|
115
|
+
const result = await tool['executeQuery']({
|
|
116
|
+
minUsage: 30,
|
|
117
|
+
maxUsage: 80,
|
|
118
|
+
}) as ToolResponse;
|
|
119
|
+
|
|
120
|
+
const structured = result.structuredContent as ResponseContent<
|
|
121
|
+
PostageBatchCurated[],
|
|
122
|
+
PostageBatchSummary[]
|
|
123
|
+
>;
|
|
124
|
+
|
|
125
|
+
expect(structured.raw.map(b => b.batchID)).toEqual(['b']);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should sort by least used when leastUsed = true', async () => {
|
|
129
|
+
const mockBatches = [
|
|
130
|
+
{
|
|
131
|
+
...rawBatch,
|
|
132
|
+
batchID: { toHex: () => 'a' },
|
|
133
|
+
usable: true,
|
|
134
|
+
usage: 0.9
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
...rawBatch,
|
|
138
|
+
batchID: { toHex: () => 'b' },
|
|
139
|
+
usable: true,
|
|
140
|
+
usage: 0.1
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
...rawBatch,
|
|
144
|
+
batchID: { toHex: () => 'c' },
|
|
145
|
+
usable: true,
|
|
146
|
+
usage: 0.5
|
|
147
|
+
},
|
|
148
|
+
] as unknown as PostageBatch[];
|
|
149
|
+
|
|
150
|
+
beeMock.getPostageBatches.mockResolvedValue(mockBatches);
|
|
151
|
+
|
|
152
|
+
const result = await tool['executeQuery']({
|
|
153
|
+
leastUsed: true,
|
|
154
|
+
}) as ToolResponse;
|
|
155
|
+
|
|
156
|
+
const structured = result.structuredContent as ResponseContent<
|
|
157
|
+
PostageBatchCurated[],
|
|
158
|
+
PostageBatchSummary[]
|
|
159
|
+
>;
|
|
160
|
+
|
|
161
|
+
expect(structured.raw.map(b => b.batchID)).toEqual(['b', 'c', 'a']);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('should limit the number of returned batches when limit is set', async () => {
|
|
165
|
+
const mockBatches = [
|
|
166
|
+
{
|
|
167
|
+
...rawBatch,
|
|
168
|
+
batchID: { toHex: () => 'a' },
|
|
169
|
+
usable: true,
|
|
170
|
+
usage: 0.1
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
...rawBatch,
|
|
174
|
+
batchID: { toHex: () => 'b' },
|
|
175
|
+
usable: true,
|
|
176
|
+
usage: 0.2
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
...rawBatch,
|
|
180
|
+
batchID: { toHex: () => 'c' },
|
|
181
|
+
usable: true,
|
|
182
|
+
usage: 0.3
|
|
183
|
+
},
|
|
184
|
+
] as unknown as PostageBatch[];
|
|
185
|
+
|
|
186
|
+
beeMock.getPostageBatches.mockResolvedValue(mockBatches);
|
|
187
|
+
|
|
188
|
+
const result = await tool['executeQuery']({ limit: 2 }) as ToolResponse;
|
|
189
|
+
const structured = result.structuredContent as ResponseContent<
|
|
190
|
+
PostageBatchCurated[],
|
|
191
|
+
PostageBatchSummary[]
|
|
192
|
+
>;
|
|
193
|
+
|
|
194
|
+
expect(structured.raw.length).toBe(2);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('should return structured response on success', async () => {
|
|
198
|
+
const mockBatches = [
|
|
199
|
+
{
|
|
200
|
+
...rawBatch,
|
|
201
|
+
batchID: { toHex: () => 'x' },
|
|
202
|
+
usable: true,
|
|
203
|
+
usage: 0.4
|
|
204
|
+
},
|
|
205
|
+
] as unknown as PostageBatch[];
|
|
206
|
+
|
|
207
|
+
beeMock.getPostageBatches.mockResolvedValue(mockBatches);
|
|
208
|
+
|
|
209
|
+
const result = await tool['executeQuery']({}) as ToolResponse;
|
|
210
|
+
const structured = result.structuredContent as ResponseContent<
|
|
211
|
+
PostageBatchCurated[],
|
|
212
|
+
PostageBatchSummary[]
|
|
213
|
+
>;
|
|
214
|
+
|
|
215
|
+
expect(structured.raw[0].batchID).toBe('x');
|
|
216
|
+
expect(Array.isArray(structured.summary)).toBe(true);
|
|
217
|
+
expect(structured.summary.length).toBe(1);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
|
|
4
|
+
import { QueryUploadProgressTool } from '../../tools/QueryUploadProgressTool';
|
|
5
|
+
import { GATEWAY_TAG_ERROR_MESSAGE } from '../../constants';
|
|
6
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
7
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
8
|
+
import { getResponseWithStructuredContent } from '../../utils';
|
|
9
|
+
|
|
10
|
+
describe('QueryUploadProgressTool', () => {
|
|
11
|
+
let tool: QueryUploadProgressTool;
|
|
12
|
+
let hederaKitMock: HederaAgentKit;
|
|
13
|
+
|
|
14
|
+
const tagDataMock = {
|
|
15
|
+
address: '0x123',
|
|
16
|
+
synced: 50,
|
|
17
|
+
seen: 25,
|
|
18
|
+
split: 100,
|
|
19
|
+
stored: 10,
|
|
20
|
+
sent: 10,
|
|
21
|
+
uid: 1,
|
|
22
|
+
startedAt: '2025-11-04T12:00:00Z',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
jest.clearAllMocks();
|
|
27
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
28
|
+
|
|
29
|
+
tool = new QueryUploadProgressTool({
|
|
30
|
+
hederaKit: hederaKitMock,
|
|
31
|
+
config: swarmConfigMock,
|
|
32
|
+
bee: beeMock,
|
|
33
|
+
logger: contextMock.logger,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should throw if tagId is missing', async () => {
|
|
38
|
+
await expect(tool['executeQuery']({} as any))
|
|
39
|
+
.rejects.toThrow('Missing required parameter: tagId.');
|
|
40
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
41
|
+
'Missing required parameter: tagId.'
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should throw if tagId is not a numeric string', async () => {
|
|
46
|
+
await expect(tool['executeQuery']({ tagId: 'abc' }))
|
|
47
|
+
.rejects.toThrow('Invalid tagId format. Expected a numeric string.');
|
|
48
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
49
|
+
'Invalid tagId format. Expected a numeric string.'
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return progress for a tag', async () => {
|
|
54
|
+
beeMock.retrieveTag.mockResolvedValue(tagDataMock);
|
|
55
|
+
|
|
56
|
+
const result = await tool['executeQuery']({ tagId: '1' });
|
|
57
|
+
|
|
58
|
+
const expectedPercentage = Math.round((tagDataMock.synced + tagDataMock.seen) / tagDataMock.split * 100);
|
|
59
|
+
|
|
60
|
+
expect(result).toEqual(
|
|
61
|
+
getResponseWithStructuredContent({
|
|
62
|
+
processedPercentage: expectedPercentage,
|
|
63
|
+
message: `Upload progress: ${expectedPercentage}% processed`,
|
|
64
|
+
startedAt: tagDataMock.startedAt,
|
|
65
|
+
tagAddress: tagDataMock.address,
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should delete tag if upload is complete', async () => {
|
|
71
|
+
const completeTag = { ...tagDataMock, synced: 50, seen: 50, split: 100 };
|
|
72
|
+
beeMock.retrieveTag.mockResolvedValue(completeTag);
|
|
73
|
+
beeMock.deleteTag.mockResolvedValue(undefined);
|
|
74
|
+
|
|
75
|
+
const result = await tool['executeQuery']({ tagId: '1' });
|
|
76
|
+
|
|
77
|
+
expect(beeMock.deleteTag).toHaveBeenCalledWith(1);
|
|
78
|
+
expect(result).toEqual(
|
|
79
|
+
getResponseWithStructuredContent({
|
|
80
|
+
processedPercentage: 100,
|
|
81
|
+
message: 'Upload completed successfully.',
|
|
82
|
+
startedAt: completeTag.startedAt,
|
|
83
|
+
tagAddress: completeTag.address,
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should continue if tag deletion fails', async () => {
|
|
89
|
+
const completeTag = { ...tagDataMock, synced: 50, seen: 50, split: 100 };
|
|
90
|
+
beeMock.retrieveTag.mockResolvedValue(completeTag);
|
|
91
|
+
beeMock.deleteTag.mockImplementation(() => {
|
|
92
|
+
throw new Error('Deletion failed');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const result = await tool['executeQuery']({ tagId: '1' });
|
|
96
|
+
|
|
97
|
+
expect(beeMock.deleteTag).toHaveBeenCalledWith(1);
|
|
98
|
+
expect(result).toEqual(
|
|
99
|
+
getResponseWithStructuredContent({
|
|
100
|
+
processedPercentage: 100,
|
|
101
|
+
message: 'Upload completed successfully.',
|
|
102
|
+
startedAt: completeTag.startedAt,
|
|
103
|
+
tagAddress: completeTag.address,
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handle not found errors (404)', async () => {
|
|
109
|
+
const error = { status: 404, message: 'Not found' };
|
|
110
|
+
beeMock.retrieveTag.mockImplementation(() => {
|
|
111
|
+
throw error;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
await expect(tool['executeQuery']({ tagId: '999' }))
|
|
115
|
+
.rejects.toThrow(`Tag with ID 999 does not exist or has been deleted. ${GATEWAY_TAG_ERROR_MESSAGE}`);
|
|
116
|
+
|
|
117
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
118
|
+
`Tag with ID 999 does not exist or has been deleted. ${GATEWAY_TAG_ERROR_MESSAGE}`,
|
|
119
|
+
error
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should handle generic errors', async () => {
|
|
124
|
+
const error = new Error('Something went wrong');
|
|
125
|
+
beeMock.retrieveTag.mockImplementation(() => {
|
|
126
|
+
throw error;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await expect(tool['executeQuery']({ tagId: '1' }))
|
|
130
|
+
.rejects.toThrow('Failed to retrieve upload progress: Something went wrong');
|
|
131
|
+
|
|
132
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
133
|
+
'Failed to retrieve upload progress: Something went wrong',
|
|
134
|
+
error
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return 0% progress if total is zero', async () => {
|
|
139
|
+
const zeroTotalTag = { ...tagDataMock, synced: 0, seen: 0, split: 0 };
|
|
140
|
+
beeMock.retrieveTag.mockResolvedValue(zeroTotalTag);
|
|
141
|
+
|
|
142
|
+
const result = await tool['executeQuery']({ tagId: '1' });
|
|
143
|
+
|
|
144
|
+
expect(result).toEqual(
|
|
145
|
+
getResponseWithStructuredContent({
|
|
146
|
+
processedPercentage: 0,
|
|
147
|
+
message: 'Upload progress: 0% processed',
|
|
148
|
+
startedAt: zeroTotalTag.startedAt,
|
|
149
|
+
tagAddress: zeroTotalTag.address,
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should return 0% progress if nothing has been processed', async () => {
|
|
155
|
+
const zeroProcessedTag = { ...tagDataMock, synced: 0, seen: 0, split: 100 };
|
|
156
|
+
beeMock.retrieveTag.mockResolvedValue(zeroProcessedTag);
|
|
157
|
+
|
|
158
|
+
const result = await tool['executeQuery']({ tagId: '1' });
|
|
159
|
+
|
|
160
|
+
expect(result).toEqual(
|
|
161
|
+
getResponseWithStructuredContent({
|
|
162
|
+
processedPercentage: 0,
|
|
163
|
+
message: 'Upload progress: 0% processed',
|
|
164
|
+
startedAt: zeroProcessedTag.startedAt,
|
|
165
|
+
tagAddress: zeroProcessedTag.address,
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { ReadFeedTool } from '../../tools/ReadFeedTool';
|
|
4
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
5
|
+
import { getErrorMessage, getResponseWithStructuredContent } from '../../utils';
|
|
6
|
+
import { BAD_REQUEST_STATUS } from '../../constants';
|
|
7
|
+
import { HederaAgentKit } from 'hedera-agent-kit';
|
|
8
|
+
|
|
9
|
+
describe('ReadFeedTool', () => {
|
|
10
|
+
let tool: ReadFeedTool;
|
|
11
|
+
let hederaKitMock: HederaAgentKit;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
16
|
+
tool = new ReadFeedTool({
|
|
17
|
+
hederaKit: hederaKitMock,
|
|
18
|
+
config: { ...swarmConfigMock, beeFeedPK: 'a'.repeat(64) },
|
|
19
|
+
bee: beeMock,
|
|
20
|
+
logger: contextMock.logger,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should throw if memoryTopic is missing', async () => {
|
|
25
|
+
await expect(tool['executeQuery']({ memoryTopic: '' } as any))
|
|
26
|
+
.rejects.toThrow('Missing required parameter: memoryTopic.');
|
|
27
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
28
|
+
'Missing required parameter: memoryTopic.'
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should throw if feed private key is missing', async () => {
|
|
33
|
+
tool.config.beeFeedPK = '';
|
|
34
|
+
await expect(tool['executeQuery']({ memoryTopic: 'my-topic' }))
|
|
35
|
+
.rejects.toThrow('Feed private key not configured.');
|
|
36
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
37
|
+
'Feed private key not configured.'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should throw if owner is invalid', async () => {
|
|
42
|
+
await expect(tool['executeQuery']({ memoryTopic: 'topic', owner: '0x123' }))
|
|
43
|
+
.rejects.toThrow('Owner must be a valid Ethereum address.');
|
|
44
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
45
|
+
'Owner must be a valid Ethereum address.'
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should hash non-hex topic', async () => {
|
|
50
|
+
const topic = 'nonHexTopic';
|
|
51
|
+
const downloadMock = jest.fn().mockReturnValueOnce({
|
|
52
|
+
payload: { toUtf8: () => 'feed-data' },
|
|
53
|
+
});
|
|
54
|
+
const makeFeedReaderMock = jest.fn().mockReturnValue({
|
|
55
|
+
downloadPayload: downloadMock,
|
|
56
|
+
});
|
|
57
|
+
(beeMock.makeFeedReader as unknown as jest.Mock).mockImplementation(makeFeedReaderMock);
|
|
58
|
+
|
|
59
|
+
const result = await tool['executeQuery']({ memoryTopic: topic });
|
|
60
|
+
|
|
61
|
+
expect(result).toEqual(getResponseWithStructuredContent({ textData: 'feed-data' }));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should remove 0x prefix from hex topic and owner', async () => {
|
|
65
|
+
const topic = '0x' + 'a'.repeat(64);
|
|
66
|
+
const owner = '0x' + 'b'.repeat(40);
|
|
67
|
+
const downloadMock = jest.fn().mockReturnValueOnce({
|
|
68
|
+
payload: { toUtf8: () => 'feed-data' },
|
|
69
|
+
});
|
|
70
|
+
const makeFeedReaderMock = jest.fn().mockReturnValue({
|
|
71
|
+
downloadPayload: downloadMock,
|
|
72
|
+
});
|
|
73
|
+
(beeMock.makeFeedReader as unknown as jest.Mock).mockImplementation(makeFeedReaderMock);
|
|
74
|
+
|
|
75
|
+
const result = await tool['executeQuery']({ memoryTopic: topic, owner });
|
|
76
|
+
|
|
77
|
+
expect(makeFeedReaderMock).toHaveBeenCalled();
|
|
78
|
+
expect(result).toEqual(getResponseWithStructuredContent({ textData: 'feed-data' }));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should use feed private key to derive owner if not provided', async () => {
|
|
82
|
+
const topic = '0x' + 'a'.repeat(64);
|
|
83
|
+
const downloadMock = jest.fn().mockReturnValueOnce({
|
|
84
|
+
payload: { toUtf8: () => 'feed-data' },
|
|
85
|
+
});
|
|
86
|
+
const makeFeedReaderMock = jest.fn().mockReturnValue({
|
|
87
|
+
downloadPayload: downloadMock,
|
|
88
|
+
});
|
|
89
|
+
(beeMock.makeFeedReader as unknown as jest.Mock).mockImplementation(makeFeedReaderMock);
|
|
90
|
+
|
|
91
|
+
const result = await tool['executeQuery']({ memoryTopic: topic });
|
|
92
|
+
|
|
93
|
+
expect(result).toEqual(getResponseWithStructuredContent({ textData: 'feed-data' }));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should handle BAD_REQUEST_STATUS error from feed', async () => {
|
|
97
|
+
const topic = '0x' + 'a'.repeat(64);
|
|
98
|
+
getErrorMessage as jest.MockedFunction<typeof getErrorMessage>;
|
|
99
|
+
(getErrorMessage as jest.Mock).mockReturnValue('Custom bad request message.');
|
|
100
|
+
const error = new Error('Custom bad request message.');
|
|
101
|
+
(error as any).status = BAD_REQUEST_STATUS;
|
|
102
|
+
|
|
103
|
+
(beeMock.makeFeedReader as unknown as jest.Mock).mockImplementation(() => {
|
|
104
|
+
throw error;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await expect(tool['executeQuery']({ memoryTopic: topic }))
|
|
108
|
+
.rejects.toThrow('Custom bad request message.');
|
|
109
|
+
|
|
110
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
111
|
+
'Custom bad request message.',
|
|
112
|
+
expect.anything()
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should handle generic error from feed', async () => {
|
|
117
|
+
const topic = '0x' + 'a'.repeat(64);
|
|
118
|
+
getErrorMessage as jest.MockedFunction<typeof getErrorMessage>;
|
|
119
|
+
(getErrorMessage as jest.Mock).mockReturnValue('Custom bad request message.');
|
|
120
|
+
const error = new Error('Custom bad request message.');
|
|
121
|
+
|
|
122
|
+
(beeMock.makeFeedReader as unknown as jest.Mock).mockImplementation(() => {
|
|
123
|
+
throw error;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
await expect(tool['executeQuery']({ memoryTopic: topic }))
|
|
127
|
+
.rejects.toThrow('Reading feed failed.');
|
|
128
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
129
|
+
'Reading feed failed.',
|
|
130
|
+
expect.anything()
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Bee } from "@ethersphere/bee-js";
|
|
2
|
+
import type { Logger } from '@hashgraphonline/standards-sdk';
|
|
3
|
+
import { GenericPluginContext, HederaAgentKit } from "hedera-agent-kit";
|
|
4
|
+
import * as utils from '../../utils';
|
|
5
|
+
|
|
6
|
+
const loggerMock = {
|
|
7
|
+
info: jest.fn(),
|
|
8
|
+
warn: jest.fn(),
|
|
9
|
+
error: jest.fn(),
|
|
10
|
+
debug: jest.fn(),
|
|
11
|
+
} as unknown as Logger;
|
|
12
|
+
|
|
13
|
+
jest.mock('hedera-agent-kit', () => ({
|
|
14
|
+
BaseHederaQueryTool: class {
|
|
15
|
+
logger = loggerMock;
|
|
16
|
+
constructor(_params: any) {}
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
let beeMock: jest.Mocked<Bee> = new Bee("http://127.0.0.1:1633") as jest.Mocked<Bee>;
|
|
21
|
+
beeMock.getPostageBatch = jest.fn();
|
|
22
|
+
beeMock.getPostageBatches = jest.fn();
|
|
23
|
+
beeMock.buyStorage = jest.fn();
|
|
24
|
+
beeMock.extendStorage = jest.fn();
|
|
25
|
+
beeMock.createTag = jest.fn();
|
|
26
|
+
beeMock.retrieveTag = jest.fn();
|
|
27
|
+
beeMock.deleteTag = jest.fn();
|
|
28
|
+
beeMock.makeFeedReader = jest.fn();
|
|
29
|
+
beeMock.makeFeedWriter = jest.fn();
|
|
30
|
+
beeMock.uploadFilesFromDirectory = jest.fn();
|
|
31
|
+
beeMock.uploadFile = jest.fn();
|
|
32
|
+
beeMock.downloadData = jest.fn();
|
|
33
|
+
beeMock.uploadData = jest.fn();
|
|
34
|
+
|
|
35
|
+
const swarmConfigMock = {
|
|
36
|
+
beeApiUrl: 'http://127.0.0.1:1633',
|
|
37
|
+
beeFeedPK: "",
|
|
38
|
+
autoAssignStamp: true,
|
|
39
|
+
deferredUploadSizeThresholdMB: 5
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const contextMock = {
|
|
43
|
+
config: {
|
|
44
|
+
hederaKit: {} as HederaAgentKit,
|
|
45
|
+
},
|
|
46
|
+
logger: loggerMock,
|
|
47
|
+
} as unknown as GenericPluginContext;
|
|
48
|
+
|
|
49
|
+
jest.mock('../../utils', () => {
|
|
50
|
+
const originalModule = jest.requireActual('../../utils');
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...originalModule,
|
|
54
|
+
runWithTimeout: jest.fn(),
|
|
55
|
+
getErrorMessage: jest.fn(),
|
|
56
|
+
getUploadPostageBatchId: jest.fn(),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const mockedUtils = utils as jest.Mocked<typeof utils>;
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
beeMock,
|
|
64
|
+
contextMock,
|
|
65
|
+
swarmConfigMock,
|
|
66
|
+
mockedUtils,
|
|
67
|
+
};
|