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
36 changes: 36 additions & 0 deletions test/command/rchash.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Bee } from '@ethersphere/bee-js'
import { System } from 'cafe-utility'
import { toMatchLinesInOrder } from '../custom-matcher'
import { describeCommand, invokeTestCli } from '../utility'

expect.extend({
toMatchLinesInOrder,
})

describeCommand('Test Utility rchash command', ({ consoleMessages }) => {
it('should print reserve sampling duration', async () => {
await System.waitFor(
async () => {
const bee = new Bee('http://localhost:1633')
const status = await bee.getStatus()
return status.isWarmingUp === false

Check failure on line 16 in test/command/rchash.spec.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Expected blank line before this statement
},
{ attempts: 300, waitMillis: 1000 },
)
await invokeTestCli(['utility', 'rchash'])
expect(consoleMessages).toMatchLinesInOrder([['Reserve sampling duration']])
})

it('should print reserve sampling duration with custom depth', async () => {
await System.waitFor(
async () => {
const bee = new Bee('http://localhost:1633')
const status = await bee.getStatus()
return status.isWarmingUp === false

Check failure on line 29 in test/command/rchash.spec.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Expected blank line before this statement
},
{ attempts: 300, waitMillis: 1000 },
)
await invokeTestCli(['utility', 'rchash', '--depth', '2'])
expect(consoleMessages).toMatchLinesInOrder([['Reserve sampling duration']])
})
})
Loading