From 79de0b85813423b59fb54985031f0121c257af0b Mon Sep 17 00:00:00 2001 From: Crt Ahlin Date: Fri, 13 Mar 2026 18:59:20 +0100 Subject: [PATCH 1/4] fix: use overlay prefix and correct depth for rchash command The rchash command was passing the full 64-char overlay address as anchor and using topology.depth instead of the correct depth from node status. This caused API errors and did not reflect the actual sampling parameters. Changes: - Truncate overlay to a short even-length hex prefix for the anchor - Use committedDepth from node status as the default depth - Add optional --depth flag to override the sampling depth - Add integration test for the rchash command Co-authored-by: AI --- src/command/utility/rchash.ts | 17 ++++++++++++++--- test/command/utility.spec.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/command/utility.spec.ts 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() + }) +}) From e0f44a51c4db75975e6ef6d4e9c4acbd51138ef8 Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 13 May 2026 14:41:59 +0200 Subject: [PATCH 2/4] chore: bump From b1fa0b1ded206732475e5536bd30ab2c5758ce4f Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 13 May 2026 15:04:01 +0200 Subject: [PATCH 3/4] test: rename utility.spec.ts to rchash.spec.ts and improve output validation --- test/command/{utility.spec.ts => rchash.spec.ts} | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) rename test/command/{utility.spec.ts => rchash.spec.ts} (60%) diff --git a/test/command/utility.spec.ts b/test/command/rchash.spec.ts similarity index 60% rename from test/command/utility.spec.ts rename to test/command/rchash.spec.ts index df9b475b..75eac0c3 100644 --- a/test/command/utility.spec.ts +++ b/test/command/rchash.spec.ts @@ -1,13 +1,18 @@ +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 invokeTestCli(['utility', 'rchash']) - expect(consoleMessages.find(m => m.includes('Reserve sampling duration'))).toBeTruthy() + expect(consoleMessages).toMatchLinesInOrder([['Reserve sampling duration']]) }) 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() + expect(consoleMessages).toMatchLinesInOrder([['Reserve sampling duration']]) }) }) From c640545cdace4da22e5f6e7a2f0fe38850f6a08d Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 13 May 2026 15:37:13 +0200 Subject: [PATCH 4/4] test: wait for warmup --- test/command/rchash.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/command/rchash.spec.ts b/test/command/rchash.spec.ts index 75eac0c3..78bb6fb3 100644 --- a/test/command/rchash.spec.ts +++ b/test/command/rchash.spec.ts @@ -1,3 +1,5 @@ +import { Bee } from '@ethersphere/bee-js' +import { System } from 'cafe-utility' import { toMatchLinesInOrder } from '../custom-matcher' import { describeCommand, invokeTestCli } from '../utility' @@ -7,11 +9,27 @@ expect.extend({ 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 + }, + { 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 + }, + { attempts: 300, waitMillis: 1000 }, + ) await invokeTestCli(['utility', 'rchash', '--depth', '2']) expect(consoleMessages).toMatchLinesInOrder([['Reserve sampling duration']]) })