Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/command/utility/rchash.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<void> {
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
})
Expand Down
13 changes: 13 additions & 0 deletions test/command/utility.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
Loading