diff --git a/src/command/utility/rchash.ts b/src/command/utility/rchash.ts index 5dd13192..be47d345 100644 --- a/src/command/utility/rchash.ts +++ b/src/command/utility/rchash.ts @@ -1,5 +1,5 @@ import { System } from 'cafe-utility' -import { LeafCommand } from 'furious-commander' +import { LeafCommand, Option } from 'furious-commander' import { createSpinner } from '../../utils/spinner' import { createKeyValue } from '../../utils/text' import { RootCommand } from '../root-command' @@ -9,12 +9,23 @@ export class Rchash extends RootCommand implements LeafCommand { public readonly description = 'Check reserve sampling duration' + @Option({ + key: 'depth', + type: 'number', + minimum: 0, + maximum: 32, + description: 'Depth to use for sampling (default: committedDepth from node status)', + }) + public depth!: number + public async run(): Promise { super.init() const addresses = await this.bee.getNodeAddresses() - const topology = await this.bee.getTopology() + const status = await this.bee.getStatus() + const depth = this.depth ?? status.committedDepth + const anchor = addresses.overlay.toHex().slice(0, Math.max(2, Math.ceil(depth / 8) * 2)) let stillRunning = true - const promise = this.bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex()) + const promise = this.bee.rchash(depth, anchor, anchor) promise.finally(() => { stillRunning = false }) diff --git a/test/command/utility.spec.ts b/test/command/utility.spec.ts new file mode 100644 index 00000000..df9b475b --- /dev/null +++ b/test/command/utility.spec.ts @@ -0,0 +1,13 @@ +import { describeCommand, invokeTestCli } from '../utility' + +describeCommand('Test Utility rchash command', ({ consoleMessages }) => { + it('should print reserve sampling duration', async () => { + await invokeTestCli(['utility', 'rchash']) + expect(consoleMessages.find(m => m.includes('Reserve sampling duration'))).toBeTruthy() + }) + + it('should print reserve sampling duration with custom depth', async () => { + await invokeTestCli(['utility', 'rchash', '--depth', '2']) + expect(consoleMessages.find(m => m.includes('Reserve sampling duration'))).toBeTruthy() + }) +})