@hashgraphonline/conversational-agent 0.2.215 → 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/index48.js +67 -85
- 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 +37 -27
- 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,152 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
|
|
4
|
+
import { CreatePostageStampTool } from '../../tools/CreatePostageStampTool';
|
|
5
|
+
import {
|
|
6
|
+
GATEWAY_STAMP_ERROR_MESSAGE,
|
|
7
|
+
BAD_REQUEST_STATUS,
|
|
8
|
+
NOT_FOUND_STATUS,
|
|
9
|
+
POSTAGE_CREATE_TIMEOUT_MESSAGE,
|
|
10
|
+
} from '../../constants';
|
|
11
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
12
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
13
|
+
import { BatchId, Duration, PostageBatch, Size } from '@ethersphere/bee-js';
|
|
14
|
+
import { getErrorMessage, runWithTimeout } from '../../utils';
|
|
15
|
+
|
|
16
|
+
describe('CreatePostageStampTool', () => {
|
|
17
|
+
let tool: CreatePostageStampTool;
|
|
18
|
+
let hederaKitMock: HederaAgentKit;
|
|
19
|
+
const rawBatch = {
|
|
20
|
+
batchID: { toHex: () => 'batch1' },
|
|
21
|
+
usageText: '0%',
|
|
22
|
+
remainingSize: Size.fromMegabytes(1),
|
|
23
|
+
size: Size.fromMegabytes(1),
|
|
24
|
+
immutableFlag: true,
|
|
25
|
+
duration: Duration.fromWeeks(1),
|
|
26
|
+
usable: true
|
|
27
|
+
} as unknown as PostageBatch;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
32
|
+
|
|
33
|
+
tool = new CreatePostageStampTool({
|
|
34
|
+
hederaKit: hederaKitMock,
|
|
35
|
+
config: swarmConfigMock,
|
|
36
|
+
bee: beeMock,
|
|
37
|
+
logger: contextMock.logger,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should throw if size is missing', async () => {
|
|
42
|
+
await expect(tool['executeQuery']({ size: 0, duration: '1w' } as any))
|
|
43
|
+
.rejects.toThrow('Missing required parameter: size.');
|
|
44
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
45
|
+
'Missing required parameter: size.'
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should throw if duration is missing', async () => {
|
|
50
|
+
await expect(tool['executeQuery']({ size: 100, duration: '' } as any))
|
|
51
|
+
.rejects.toThrow('Missing required parameter: duration.');
|
|
52
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
53
|
+
'Missing required parameter: duration.'
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should throw if duration is invalid', async () => {
|
|
58
|
+
await expect(tool['executeQuery']({ size: 100, duration: 'xyz' }))
|
|
59
|
+
.rejects.toThrow('Invalid parameter: duration.');
|
|
60
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
61
|
+
'Invalid parameter: duration.'
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should handle timeout from runWithTimeout', async () => {
|
|
66
|
+
const mockedRunWithTimeout = runWithTimeout as jest.MockedFunction<typeof runWithTimeout>;
|
|
67
|
+
mockedRunWithTimeout.mockResolvedValue([null, true]);
|
|
68
|
+
|
|
69
|
+
beeMock.buyStorage.mockReturnValue(Promise.resolve(rawBatch.batchID));
|
|
70
|
+
|
|
71
|
+
const result = await tool['executeQuery']({
|
|
72
|
+
size: 100,
|
|
73
|
+
duration: '1w',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(JSON.parse(result as string)).toEqual({
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: POSTAGE_CREATE_TIMEOUT_MESSAGE,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should return ToolResponse with BatchId on success', async () => {
|
|
87
|
+
const mockHex = 'abcd1234';
|
|
88
|
+
const batchId = { toHex: () => mockHex } as unknown as BatchId;
|
|
89
|
+
const mockedRunWithTimeout = runWithTimeout as jest.MockedFunction<typeof runWithTimeout>;
|
|
90
|
+
mockedRunWithTimeout.mockResolvedValue([batchId, false]);
|
|
91
|
+
beeMock.buyStorage.mockReturnValue(Promise.resolve(batchId));
|
|
92
|
+
|
|
93
|
+
const result = await tool['executeQuery']({
|
|
94
|
+
size: 10,
|
|
95
|
+
duration: '1d',
|
|
96
|
+
label: 'test-stamp',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const content = (result as any).content[0];
|
|
100
|
+
expect(content.type).toBe('text');
|
|
101
|
+
expect(content.text).toBe(`Postage batch ID: ${mockHex}`);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should handle NOT_FOUND_STATUS error', async () => {
|
|
105
|
+
const error = new Error('not found');
|
|
106
|
+
(error as any).status = NOT_FOUND_STATUS;
|
|
107
|
+
beeMock.buyStorage.mockImplementation(() => {
|
|
108
|
+
throw error;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
await expect(tool['executeQuery']({ size: 10, duration: '1w' }))
|
|
112
|
+
.rejects.toThrow(GATEWAY_STAMP_ERROR_MESSAGE);
|
|
113
|
+
|
|
114
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
115
|
+
GATEWAY_STAMP_ERROR_MESSAGE,
|
|
116
|
+
error
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handle BAD_REQUEST_STATUS error', async () => {
|
|
121
|
+
const error = new Error('Bad request');
|
|
122
|
+
(error as any).status = BAD_REQUEST_STATUS;
|
|
123
|
+
getErrorMessage as jest.MockedFunction<typeof getErrorMessage>;
|
|
124
|
+
(getErrorMessage as jest.Mock).mockReturnValue('Custom bad request message');
|
|
125
|
+
beeMock.buyStorage.mockImplementation(() => {
|
|
126
|
+
throw error;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await expect(tool['executeQuery']({ size: 10, duration: '1w' }))
|
|
130
|
+
.rejects.toThrow('Custom bad request message');
|
|
131
|
+
|
|
132
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
133
|
+
'Custom bad request message',
|
|
134
|
+
error
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should handle generic error', async () => {
|
|
139
|
+
const error = new Error('Generic error');
|
|
140
|
+
beeMock.buyStorage.mockImplementation(() => {
|
|
141
|
+
throw error;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await expect(tool['executeQuery']({ size: 10, duration: '1w' }))
|
|
145
|
+
.rejects.toThrow('Unable to buy storage.');
|
|
146
|
+
|
|
147
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
148
|
+
'Unable to buy storage.',
|
|
149
|
+
error
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { DownloadDataTool } from '../../tools/DownloadDataTool';
|
|
4
|
+
import { beeMock, contextMock, mockedUtils, swarmConfigMock } from './SwarmTool.mocks';
|
|
5
|
+
import { HederaAgentKit } from 'hedera-agent-kit';
|
|
6
|
+
import { BAD_REQUEST_STATUS } from '../../constants';
|
|
7
|
+
|
|
8
|
+
describe('DownloadDataTool', () => {
|
|
9
|
+
let tool: DownloadDataTool;
|
|
10
|
+
const hederaKitMock = {} as HederaAgentKit;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
|
|
15
|
+
tool = new DownloadDataTool({
|
|
16
|
+
hederaKit: hederaKitMock,
|
|
17
|
+
config: swarmConfigMock,
|
|
18
|
+
bee: beeMock,
|
|
19
|
+
logger: contextMock.logger,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const downloadDataMock = jest.fn().mockReturnValue({
|
|
23
|
+
toUtf8: jest.fn(() => 'hello swarm data'),
|
|
24
|
+
});
|
|
25
|
+
(beeMock.downloadData as unknown as jest.Mock).mockImplementation(downloadDataMock);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('downloads data successfully', async () => {
|
|
29
|
+
const reference = 'a'.repeat(64); // valid swarm reference
|
|
30
|
+
|
|
31
|
+
const result = await tool['executeQuery']({ reference });
|
|
32
|
+
|
|
33
|
+
expect(result).toEqual(
|
|
34
|
+
expect.objectContaining({
|
|
35
|
+
structuredContent: { textData: 'hello swarm data' },
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('throws error if reference is missing', async () => {
|
|
41
|
+
await expect(tool['executeQuery']({ reference: '' })).rejects.toThrow(
|
|
42
|
+
'Missing required parameter: reference.'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
46
|
+
'Missing required parameter: reference.'
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('throws error if reference is invalid length', async () => {
|
|
51
|
+
const reference = 'abc123'; // invalid
|
|
52
|
+
await expect(tool['executeQuery']({ reference })).rejects.toThrow(
|
|
53
|
+
'Invalid Swarm content address hash value for reference.'
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
57
|
+
'Invalid Swarm content address hash value for reference.'
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('handles generic download error', async () => {
|
|
62
|
+
const reference = 'b'.repeat(64);
|
|
63
|
+
const error = new Error('Download failed');
|
|
64
|
+
beeMock.downloadData.mockRejectedValueOnce(error);
|
|
65
|
+
|
|
66
|
+
await expect(tool['executeQuery']({ reference })).rejects.toThrow(
|
|
67
|
+
'Downloading data failed.'
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
71
|
+
'Downloading data failed.',
|
|
72
|
+
error
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('handles BAD_REQUEST_STATUS error with getErrorMessage', async () => {
|
|
77
|
+
const reference = 'c'.repeat(64);
|
|
78
|
+
const error = { status: BAD_REQUEST_STATUS };
|
|
79
|
+
|
|
80
|
+
beeMock.downloadData.mockRejectedValueOnce(error);
|
|
81
|
+
mockedUtils.getErrorMessage.mockReturnValue('Bad request: invalid data');
|
|
82
|
+
|
|
83
|
+
await expect(tool['executeQuery']({ reference })).rejects.toThrow(
|
|
84
|
+
'Bad request: invalid data'
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(mockedUtils.getErrorMessage).toHaveBeenCalledWith(error);
|
|
88
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
89
|
+
'Bad request: invalid data',
|
|
90
|
+
error
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { DownloadFilesTool } from '../../tools/DownloadFilesTool';
|
|
4
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
5
|
+
import { HederaAgentKit } from 'hedera-agent-kit';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { Bytes, MantarayNode } from '@ethersphere/bee-js';
|
|
9
|
+
|
|
10
|
+
describe('DownloadFilesTool', () => {
|
|
11
|
+
let tool: DownloadFilesTool;
|
|
12
|
+
const hederaKitMock = {} as HederaAgentKit;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
|
|
17
|
+
tool = new DownloadFilesTool({
|
|
18
|
+
hederaKit: hederaKitMock,
|
|
19
|
+
config: swarmConfigMock,
|
|
20
|
+
bee: beeMock,
|
|
21
|
+
logger: contextMock.logger,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('throws error if reference is missing', async () => {
|
|
28
|
+
await expect(tool['executeQuery']({ reference: '', filePath: undefined }))
|
|
29
|
+
.rejects.toThrow('Missing required parameter: reference.');
|
|
30
|
+
|
|
31
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
32
|
+
'Missing required parameter: reference.'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('returns message for non-manifest reference', async () => {
|
|
37
|
+
// MantarayNode.unmarshal throws → treated as non-manifest
|
|
38
|
+
(MantarayNode.unmarshal as unknown as jest.Mock) = jest.fn<any>().mockRejectedValue(new Error('Not manifest'));
|
|
39
|
+
|
|
40
|
+
const result = await tool['executeQuery']({ reference: 'abc123' });
|
|
41
|
+
|
|
42
|
+
expect(result).toBe(
|
|
43
|
+
'Try swarm-download-data tool instead since the given reference is not a manifest.'
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('returns manifest file list when filePath not provided', async () => {
|
|
48
|
+
const mockNode = {
|
|
49
|
+
loadRecursively: jest.fn<any>().mockResolvedValue(undefined),
|
|
50
|
+
collect: jest.fn().mockReturnValue([
|
|
51
|
+
{
|
|
52
|
+
fullPathString: '/test.txt',
|
|
53
|
+
targetAddress: Uint8Array.from([1, 2, 3]),
|
|
54
|
+
metadata: { contentType: 'text/plain' },
|
|
55
|
+
},
|
|
56
|
+
]),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
(MantarayNode.unmarshal as unknown as jest.Mock) = jest.fn<any>().mockResolvedValue(mockNode);
|
|
60
|
+
|
|
61
|
+
const result = await tool['executeQuery']({
|
|
62
|
+
reference: 'manifest123',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const text = JSON.parse(result["content"][0].text);
|
|
66
|
+
expect(text.type).toBe('manifest');
|
|
67
|
+
expect(text.files.length).toBe(1);
|
|
68
|
+
expect(text.files[0].path).toBe('/test.txt');
|
|
69
|
+
expect(text.message).toContain('Provide a filePath to download all files');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('downloads single file manifest successfully', async () => {
|
|
73
|
+
const mockNode = {
|
|
74
|
+
loadRecursively: jest.fn<any>().mockResolvedValue(undefined),
|
|
75
|
+
collect: jest.fn().mockReturnValue([
|
|
76
|
+
{
|
|
77
|
+
fullPathString: 'single.txt',
|
|
78
|
+
targetAddress: Uint8Array.from([1, 2, 3]),
|
|
79
|
+
},
|
|
80
|
+
]),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
(MantarayNode.unmarshal as unknown as jest.Mock) = jest.fn<any>().mockResolvedValue(mockNode);
|
|
84
|
+
|
|
85
|
+
const mkdirMock = jest.fn<any>().mockResolvedValue(undefined);
|
|
86
|
+
const writeFileMock = jest.fn<any>().mockResolvedValue(undefined);
|
|
87
|
+
jest.spyOn(require('util'), 'promisify').mockImplementation((fn) => {
|
|
88
|
+
if (fn === fs.mkdir) return mkdirMock;
|
|
89
|
+
if (fn === fs.writeFile) return writeFileMock;
|
|
90
|
+
return fn as any;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
|
|
94
|
+
|
|
95
|
+
const downloadDataMock = jest.fn().mockReturnValueOnce({
|
|
96
|
+
toUint8Array: () => new Uint8Array([1, 2, 3]),
|
|
97
|
+
});
|
|
98
|
+
(beeMock.downloadData as unknown as jest.Mock).mockImplementation(downloadDataMock);
|
|
99
|
+
|
|
100
|
+
const result = await tool['executeQuery']({
|
|
101
|
+
reference: 'manifest123',
|
|
102
|
+
filePath: '/mock/folder',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(mkdirMock).not.toHaveBeenCalled(); // folder already exists
|
|
106
|
+
expect(downloadDataMock).toHaveBeenCalledWith(Uint8Array.from([1, 2, 3]));
|
|
107
|
+
expect(writeFileMock).toHaveBeenCalledWith(
|
|
108
|
+
path.join('/mock/folder', 'single.txt'),
|
|
109
|
+
new Uint8Array([1, 2, 3])
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const text = JSON.parse(result["content"][0].text);
|
|
113
|
+
expect(text.savedTo).toBe('/mock/folder');
|
|
114
|
+
expect(text.message).toContain('successfully downloaded');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('downloads multiple files manifest successfully', async () => {
|
|
118
|
+
const mockNodes = [
|
|
119
|
+
{
|
|
120
|
+
fullPathString: 'dir/file1.txt',
|
|
121
|
+
targetAddress: Uint8Array.from([1]),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
fullPathString: 'dir/file2.txt',
|
|
125
|
+
targetAddress: Uint8Array.from([2]),
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
const mockNode = {
|
|
129
|
+
loadRecursively: jest.fn<any>().mockResolvedValue(undefined),
|
|
130
|
+
collect: jest.fn().mockReturnValue(mockNodes),
|
|
131
|
+
};
|
|
132
|
+
(MantarayNode.unmarshal as unknown as jest.Mock) = jest.fn<any>().mockResolvedValue(mockNode);
|
|
133
|
+
|
|
134
|
+
const mkdirMock = jest.fn<any>().mockResolvedValue(undefined);
|
|
135
|
+
const writeFileMock = jest.fn<any>().mockResolvedValue(undefined);
|
|
136
|
+
jest.spyOn(require('util'), 'promisify').mockImplementation((fn) => {
|
|
137
|
+
if (fn === fs.mkdir) return mkdirMock;
|
|
138
|
+
if (fn === fs.writeFile) return writeFileMock;
|
|
139
|
+
return fn as any;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
jest
|
|
143
|
+
.spyOn(fs, 'existsSync')
|
|
144
|
+
.mockImplementation((p) => p.toString().includes('dir'));
|
|
145
|
+
|
|
146
|
+
const downloadDataMock = jest.fn().mockReturnValue({
|
|
147
|
+
toUint8Array: () => new Uint8Array([5]),
|
|
148
|
+
});
|
|
149
|
+
(beeMock.downloadData as unknown as jest.Mock).mockImplementation(downloadDataMock);
|
|
150
|
+
|
|
151
|
+
const result = await tool['executeQuery']({
|
|
152
|
+
reference: 'manifestMulti',
|
|
153
|
+
filePath: '/mock/folder',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(mkdirMock).toHaveBeenCalled(); // at least for subfolder
|
|
157
|
+
expect(writeFileMock).toHaveBeenCalledTimes(2);
|
|
158
|
+
|
|
159
|
+
const text = JSON.parse(result["content"][0].text);
|
|
160
|
+
expect(text.manifestNodeCount).toBe(2);
|
|
161
|
+
expect(text.message).toContain('successfully downloaded');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
|
|
4
|
+
import { ExtendPostageStampTool } from '../../tools/ExtendPostageStampTool';
|
|
5
|
+
import {
|
|
6
|
+
GATEWAY_STAMP_ERROR_MESSAGE,
|
|
7
|
+
BAD_REQUEST_STATUS,
|
|
8
|
+
NOT_FOUND_STATUS,
|
|
9
|
+
} from '../../constants';
|
|
10
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
11
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
12
|
+
import { BatchId, Duration, Size } from '@ethersphere/bee-js';
|
|
13
|
+
import { getErrorMessage } from '../../utils';
|
|
14
|
+
|
|
15
|
+
describe('ExtendPostageStampTool', () => {
|
|
16
|
+
let tool: ExtendPostageStampTool;
|
|
17
|
+
let hederaKitMock: HederaAgentKit;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks();
|
|
21
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
22
|
+
|
|
23
|
+
tool = new ExtendPostageStampTool({
|
|
24
|
+
hederaKit: hederaKitMock,
|
|
25
|
+
config: swarmConfigMock,
|
|
26
|
+
bee: beeMock,
|
|
27
|
+
logger: contextMock.logger,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should throw if postageBatchId is missing', async () => {
|
|
32
|
+
await expect(tool['executeQuery']({ duration: '1w' } as any))
|
|
33
|
+
.rejects.toThrow('Missing required parameter: postageBatchId.');
|
|
34
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
35
|
+
'Missing required parameter: postageBatchId.'
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should throw if both duration and size are missing', async () => {
|
|
40
|
+
await expect(tool['executeQuery']({ postageBatchId: 'abc' } as any))
|
|
41
|
+
.rejects.toThrow('You need at least one parameter from duration and size.');
|
|
42
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
43
|
+
'You need at least one parameter from duration and size.'
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should throw if duration is invalid', async () => {
|
|
48
|
+
await expect(tool['executeQuery']({ postageBatchId: 'abc', duration: 'xyz' }))
|
|
49
|
+
.rejects.toThrow('Invalid parameter: duration.');
|
|
50
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
51
|
+
'Invalid parameter: duration.'
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should return ToolResponse with BatchId on success', async () => {
|
|
56
|
+
const mockHex = 'abcd1234';
|
|
57
|
+
const batchId = { toHex: () => mockHex } as unknown as BatchId;
|
|
58
|
+
|
|
59
|
+
beeMock.extendStorage.mockResolvedValue(batchId);
|
|
60
|
+
|
|
61
|
+
const result = await tool['executeQuery']({
|
|
62
|
+
postageBatchId: 'batch1',
|
|
63
|
+
size: 10,
|
|
64
|
+
duration: '1d',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect((result as any).structuredContent.postageBatchId).toBe(mockHex);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should handle NOT_FOUND_STATUS error', async () => {
|
|
71
|
+
const error = new Error('not found');
|
|
72
|
+
(error as any).status = NOT_FOUND_STATUS;
|
|
73
|
+
|
|
74
|
+
beeMock.extendStorage.mockImplementation(() => {
|
|
75
|
+
throw error;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await expect(tool['executeQuery']({ postageBatchId: 'batch1', size: 10 }))
|
|
79
|
+
.rejects.toThrow(GATEWAY_STAMP_ERROR_MESSAGE);
|
|
80
|
+
|
|
81
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
82
|
+
GATEWAY_STAMP_ERROR_MESSAGE,
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should handle BAD_REQUEST_STATUS error', async () => {
|
|
88
|
+
const error = new Error('Bad request');
|
|
89
|
+
(error as any).status = BAD_REQUEST_STATUS;
|
|
90
|
+
|
|
91
|
+
(getErrorMessage as jest.MockedFunction<typeof getErrorMessage>)
|
|
92
|
+
.mockReturnValue('Custom bad request message');
|
|
93
|
+
|
|
94
|
+
beeMock.extendStorage.mockImplementation(() => {
|
|
95
|
+
throw error;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await expect(tool['executeQuery']({ postageBatchId: 'batch1', size: 10 }))
|
|
99
|
+
.rejects.toThrow('Custom bad request message');
|
|
100
|
+
|
|
101
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
102
|
+
'Custom bad request message',
|
|
103
|
+
error
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should handle generic error', async () => {
|
|
108
|
+
const error = new Error('Generic error');
|
|
109
|
+
beeMock.extendStorage.mockImplementation(() => {
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
await expect(tool['executeQuery']({ postageBatchId: 'batch1', size: 10 }))
|
|
114
|
+
.rejects.toThrow('Extend failed.');
|
|
115
|
+
|
|
116
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
117
|
+
'Extend failed.',
|
|
118
|
+
error
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should use default Size.fromBytes(1) if size is not provided', async () => {
|
|
123
|
+
const batchId = { toHex: () => 'batch123' } as unknown as BatchId;
|
|
124
|
+
|
|
125
|
+
const sizeSpy = jest.spyOn(Size, 'fromBytes');
|
|
126
|
+
beeMock.extendStorage.mockResolvedValue(batchId);
|
|
127
|
+
|
|
128
|
+
await tool['executeQuery']({ postageBatchId: 'batch1', duration: '1w' });
|
|
129
|
+
|
|
130
|
+
expect(sizeSpy).toHaveBeenCalledWith(1);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { GetPostageStampTool } from '../../tools/GetPostageStampTool';
|
|
4
|
+
import { GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from '../../constants';
|
|
5
|
+
import type { HederaAgentKit } from 'hedera-agent-kit';
|
|
6
|
+
import { beeMock, contextMock, swarmConfigMock } from './SwarmTool.mocks';
|
|
7
|
+
import { Duration, PostageBatch, Size } from '@ethersphere/bee-js';
|
|
8
|
+
import { PostageBatchCurated, PostageBatchSummary, ResponseContent } from '../../model';
|
|
9
|
+
import { ToolResponse } from '../../utils';
|
|
10
|
+
|
|
11
|
+
describe('GetPostageStampTool', () => {
|
|
12
|
+
let tool: GetPostageStampTool;
|
|
13
|
+
let hederaKitMock: HederaAgentKit;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
|
|
18
|
+
hederaKitMock = {} as HederaAgentKit;
|
|
19
|
+
|
|
20
|
+
tool = new GetPostageStampTool({
|
|
21
|
+
hederaKit: hederaKitMock,
|
|
22
|
+
config: swarmConfigMock,
|
|
23
|
+
bee: beeMock,
|
|
24
|
+
logger: contextMock.logger,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should throw an error if postageBatchId is missing', async () => {
|
|
29
|
+
await expect(tool['executeQuery']({ postageBatchId: '' }))
|
|
30
|
+
.rejects.toThrow('Missing required parameter: postageBatchId.');
|
|
31
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
32
|
+
'Missing required parameter: postageBatchId.'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should handle Bee getPostageBatch not found error', async () => {
|
|
37
|
+
const error = new Error('Not found');
|
|
38
|
+
(error as any).status = NOT_FOUND_STATUS;
|
|
39
|
+
beeMock.getPostageBatch.mockRejectedValue(error);
|
|
40
|
+
|
|
41
|
+
await expect(tool['executeQuery']({ postageBatchId: '123' }))
|
|
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 getPostageBatch other errors', async () => {
|
|
50
|
+
const error = new Error('Server error');
|
|
51
|
+
beeMock.getPostageBatch.mockRejectedValue(error);
|
|
52
|
+
|
|
53
|
+
await expect(tool['executeQuery']({ postageBatchId: '123' }))
|
|
54
|
+
.rejects.toThrow('Retrieval of postage batch failed.');
|
|
55
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
56
|
+
'Retrieval of postage batch failed.',
|
|
57
|
+
error
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should return structured response on success', async () => {
|
|
62
|
+
const batchId = 'abc123';
|
|
63
|
+
const rawBatch = {
|
|
64
|
+
batchID: { toHex: () => batchId },
|
|
65
|
+
usageText: '0%',
|
|
66
|
+
remainingSize: Size.fromMegabytes(1),
|
|
67
|
+
size: Size.fromMegabytes(1),
|
|
68
|
+
immutableFlag: true,
|
|
69
|
+
duration: Duration.fromWeeks(1)
|
|
70
|
+
} as unknown as PostageBatch;
|
|
71
|
+
|
|
72
|
+
beeMock.getPostageBatch.mockResolvedValue(rawBatch);
|
|
73
|
+
|
|
74
|
+
const result = await tool['executeQuery']({ postageBatchId: batchId }) as ToolResponse;
|
|
75
|
+
|
|
76
|
+
// Extract structured content from response
|
|
77
|
+
const structured = result.structuredContent as ResponseContent<PostageBatchCurated, PostageBatchSummary>;
|
|
78
|
+
|
|
79
|
+
expect(structured.raw.batchID).toBe(batchId);
|
|
80
|
+
expect(structured.summary.stampID).toEqual(batchId);
|
|
81
|
+
expect(structured.summary.capacity).toEqual('1.000 MB remaining out of 1.000 MB');
|
|
82
|
+
});
|
|
83
|
+
});
|