Skip to content

Commit 3b630b1

Browse files
committed
refactor version-coupled test semver helpers
1 parent 2759927 commit 3b630b1

16 files changed

Lines changed: 149 additions & 73 deletions

test/bitcoind-bootstrap.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
import { MANAGED_RPC_RETRY_MESSAGE } from "../src/bitcoind/retryable-rpc.js";
4444
import type { BootstrapPhase, SnapshotChunkManifest, SnapshotMetadata, WritingQuote } from "../src/bitcoind/types.js";
4545
import { createTempDirectory, removeTempDirectory } from "./bitcoind-helpers.js";
46+
import { CURRENT_ARTWORK_VERSION_TEXT } from "./version-helpers.js";
4647

4748
const execFileAsync = promisify(execFile);
4849

@@ -1814,12 +1815,15 @@ test("follow scene renders a lower-right mining version beside the status text",
18141815
statusText,
18151816
0,
18161817
{
1817-
artworkStatusRightText: "v1.1.12",
1818+
artworkStatusRightText: CURRENT_ARTWORK_VERSION_TEXT,
18181819
},
18191820
);
18201821
const field = extractField(frame, 13);
18211822

1822-
assert.match(field, /Waiting for next block\s{2,}v1\.1\.12$/);
1823+
assert.match(
1824+
field,
1825+
new RegExp(`Waiting for next block\\s{2,}${CURRENT_ARTWORK_VERSION_TEXT.replaceAll(".", "\\.")}$`),
1826+
);
18231827
assert.equal(field.indexOf(statusText), Math.floor((64 - statusText.length) / 2));
18241828
});
18251829

@@ -1831,12 +1835,15 @@ test("follow scene renders an UPDATE badge on the left while keeping semver on t
18311835
0,
18321836
{
18331837
artworkStatusLeftText: "UPDATE",
1834-
artworkStatusRightText: "v1.1.12",
1838+
artworkStatusRightText: CURRENT_ARTWORK_VERSION_TEXT,
18351839
},
18361840
);
18371841
const field = extractField(frame, 13);
18381842

1839-
assert.match(field, /^UPDATE\s{2,}.*Waiting for next block.*\s{2,}v1\.1\.12$/);
1843+
assert.match(
1844+
field,
1845+
new RegExp(`^UPDATE\\s{2,}.*Waiting for next block.*\\s{2,}${CURRENT_ARTWORK_VERSION_TEXT.replaceAll(".", "\\.")}$`),
1846+
);
18401847
assert.equal(field.indexOf(statusText), Math.floor((64 - statusText.length) / 2));
18411848
});
18421849

test/bitcoind.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import { openSqliteDatabase } from "../src/sqlite/driver.js";
4141
import { openSqliteStore } from "../src/sqlite/index.js";
4242
import { createTempDirectory, generateBlocks, getMiningDescriptor, removeTempDirectory, replayBlocks, serializeStateHex, waitForCondition } from "./bitcoind-helpers.js";
4343
import { createWalletReadContext } from "./current-model-helpers.js";
44+
import {
45+
CURRENT_CLIENT_VERSION,
46+
NEWER_CLIENT_VERSION,
47+
} from "./version-helpers.js";
4448

4549
interface RegtestFixture {
4650
rootDir: string;
@@ -2197,7 +2201,7 @@ test("attach restarts a compatible stale daemon when expectedBinaryVersion is ne
21972201
dataDir: fixture.dataDir,
21982202
databasePath: fixture.databasePath,
21992203
walletRootId,
2200-
expectedBinaryVersion: "1.1.12",
2204+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
22012205
startupTimeoutMs: 5_000,
22022206
});
22032207

@@ -2238,7 +2242,7 @@ test("attach restarts a compatible unparseable daemon when expectedBinaryVersion
22382242
dataDir: fixture.dataDir,
22392243
databasePath: fixture.databasePath,
22402244
walletRootId,
2241-
expectedBinaryVersion: "1.1.12",
2245+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
22422246
startupTimeoutMs: 5_000,
22432247
});
22442248

@@ -2261,8 +2265,8 @@ test("attach restarts a compatible unparseable daemon when expectedBinaryVersion
22612265

22622266
test("attach keeps compatible equal and newer daemon versions running", async () => {
22632267
const cases = [
2264-
{ name: "equal", binaryVersion: "1.1.12" },
2265-
{ name: "newer", binaryVersion: "1.1.13" },
2268+
{ name: "equal", binaryVersion: CURRENT_CLIENT_VERSION },
2269+
{ name: "newer", binaryVersion: NEWER_CLIENT_VERSION },
22662270
];
22672271

22682272
for (const testCase of cases) {
@@ -2285,7 +2289,7 @@ test("attach keeps compatible equal and newer daemon versions running", async ()
22852289
dataDir: fixture.dataDir,
22862290
databasePath: fixture.databasePath,
22872291
walletRootId,
2288-
expectedBinaryVersion: "1.1.12",
2292+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
22892293
startupTimeoutMs: 1_000,
22902294
});
22912295

@@ -2338,7 +2342,7 @@ test("attach rejects a live daemon with incompatible service metadata without sp
23382342
dataDir: fixture.dataDir,
23392343
databasePath: fixture.databasePath,
23402344
walletRootId,
2341-
expectedBinaryVersion: "1.1.12",
2345+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
23422346
startupTimeoutMs: 1_000,
23432347
}),
23442348
/indexer_daemon_service_version_mismatch/,
@@ -2367,7 +2371,7 @@ test("attach accepts a live daemon for a different wallet root when the daemon i
23672371
dataDir: fixture.dataDir,
23682372
databasePath: fixture.databasePath,
23692373
walletRootId,
2370-
expectedBinaryVersion: "1.1.12",
2374+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
23712375
startupTimeoutMs: 1_000,
23722376
});
23732377
await daemon.close();
@@ -2395,7 +2399,7 @@ test("attach rejects a live daemon with an incompatible schema version", async (
23952399
dataDir: fixture.dataDir,
23962400
databasePath: fixture.databasePath,
23972401
walletRootId,
2398-
expectedBinaryVersion: "1.1.12",
2402+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
23992403
startupTimeoutMs: 1_000,
24002404
}),
24012405
/indexer_daemon_schema_mismatch/,

test/current-model-helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { WalletStateV1 } from "../src/wallet/types.js";
22
import type { MiningRuntimeStatusV1 } from "../src/wallet/mining/types.js";
33
import type { MiningControlPlaneView } from "../src/wallet/mining/types.js";
44
import { createWalletReadModel } from "../src/wallet/read/project.js";
5+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
56

67
export function createMiningState(overrides: Partial<WalletStateV1["miningState"]> = {}): WalletStateV1["miningState"] {
78
return {
@@ -90,7 +91,7 @@ export function createMiningRuntimeStatus(
9091
schemaVersion: 1,
9192
walletRootId: "wallet-root",
9293
workerApiVersion: "cogcoin/mining-worker/v1",
93-
workerBinaryVersion: "1.1.12",
94+
workerBinaryVersion: CURRENT_CLIENT_VERSION,
9495
workerBuildId: "build-1",
9596
updatedAtUnixMs: 1,
9697
runMode: "stopped",

test/indexer-daemon-internals.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ import type {
3737
LoadedSnapshotMaterial,
3838
} from "../src/bitcoind/indexer-daemon/types.js";
3939
import { createTrackedTempDirectory } from "./bitcoind-helpers.js";
40+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
4041

4142
function createRuntimeState(
4243
overrides: Partial<IndexerDaemonRuntimeState> = {},
4344
): IndexerDaemonRuntimeState {
4445
return {
4546
daemonInstanceId: "daemon-1",
46-
binaryVersion: "1.1.12",
47+
binaryVersion: CURRENT_CLIENT_VERSION,
4748
startedAtUnixMs: 1_700_000_000_000,
4849
walletRootId: "wallet-root-test",
4950
snapshots: new Map(),
@@ -80,7 +81,7 @@ function createManagedIndexerDaemonStatus(
8081
): ManagedIndexerDaemonStatus {
8182
return {
8283
serviceApiVersion: "cogcoin/indexer-ipc/v1",
83-
binaryVersion: "1.1.12",
84+
binaryVersion: CURRENT_CLIENT_VERSION,
8485
buildId: null,
8586
updatedAtUnixMs: 1_700_000_000_100,
8687
walletRootId,
@@ -118,7 +119,7 @@ function createSnapshotHandleFixture(
118119
token: "lease-1",
119120
expiresAtUnixMs: Date.now() + 5_000,
120121
serviceApiVersion: "cogcoin/indexer-ipc/v1",
121-
binaryVersion: "1.1.12",
122+
binaryVersion: CURRENT_CLIENT_VERSION,
122123
buildId: null,
123124
walletRootId: "wallet-root-test",
124125
daemonInstanceId: "daemon-1",

test/managed-runtime-coordinator.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
ManagedIndexerDaemonObservedStatus,
1313
} from "../src/bitcoind/types.js";
1414
import { createTrackedTempDirectory } from "./bitcoind-helpers.js";
15+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
1516

1617
function createManagedBitcoindObservedStatus(
1718
overrides: Partial<ManagedBitcoindObservedStatus> = {},
@@ -56,7 +57,7 @@ function createManagedIndexerDaemonObservedStatus(
5657
): ManagedIndexerDaemonObservedStatus {
5758
return {
5859
serviceApiVersion: "cogcoin/indexer-ipc/v1",
59-
binaryVersion: "1.1.12",
60+
binaryVersion: CURRENT_CLIENT_VERSION,
6061
buildId: null,
6162
updatedAtUnixMs: 1_700_000_000_100,
6263
walletRootId: "wallet-root-default",
@@ -360,14 +361,14 @@ test("attachOrStartManagedIndexerRuntime reuses a compatible daemon without lock
360361
walletRootId,
361362
databasePath: "/tmp/client.sqlite",
362363
startupTimeoutMs: 5_000,
363-
expectedBinaryVersion: "1.1.12",
364+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
364365
}, {
365366
getPaths: () => paths,
366367
probeDaemon: async () => ({
367368
compatibility: "compatible",
368369
status: createManagedIndexerDaemonObservedStatus({
369370
walletRootId,
370-
binaryVersion: "1.1.12",
371+
binaryVersion: CURRENT_CLIENT_VERSION,
371372
}),
372373
client: existingClient,
373374
error: null,
@@ -406,7 +407,7 @@ test("attachOrStartManagedIndexerRuntime replaces stale compatible daemons befor
406407
walletRootId,
407408
databasePath: "/tmp/client.sqlite",
408409
startupTimeoutMs: 5_000,
409-
expectedBinaryVersion: "1.1.12",
410+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
410411
}, {
411412
getPaths: () => paths,
412413
probeDaemon: async () => {
@@ -459,7 +460,7 @@ test("attachOrStartManagedIndexerRuntime rejects incompatible daemon metadata",
459460
walletRootId,
460461
databasePath: "/tmp/client.sqlite",
461462
startupTimeoutMs: 5_000,
462-
expectedBinaryVersion: "1.1.12",
463+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
463464
}, {
464465
getPaths: () => paths,
465466
probeDaemon: async () => ({
@@ -503,7 +504,7 @@ test("attachOrStartManagedIndexerRuntime recycles a live daemon when background
503504
databasePath: "/tmp/client.sqlite",
504505
startupTimeoutMs: 5_000,
505506
shutdownTimeoutMs: 2_000,
506-
expectedBinaryVersion: "1.1.12",
507+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
507508
}, {
508509
getPaths: () => paths,
509510
probeDaemon: async () => {
@@ -568,7 +569,7 @@ test("attachOrStartManagedIndexerRuntime throws recovery_failed when a freshly s
568569
walletRootId,
569570
databasePath: "/tmp/client.sqlite",
570571
startupTimeoutMs: 5_000,
571-
expectedBinaryVersion: "1.1.12",
572+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
572573
}, {
573574
getPaths: () => paths,
574575
probeDaemon: async () => ({

test/managed-runtime-policy.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
ManagedIndexerDaemonObservedStatus,
2020
ManagedIndexerDaemonStatus,
2121
} from "../src/bitcoind/types.js";
22+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
2223

2324
function createManagedBitcoindObservedStatus(
2425
overrides: Partial<ManagedBitcoindObservedStatus> = {},
@@ -63,7 +64,7 @@ function createManagedIndexerDaemonObservedStatus(
6364
): ManagedIndexerDaemonObservedStatus {
6465
return {
6566
serviceApiVersion: "cogcoin/indexer-ipc/v1",
66-
binaryVersion: "1.1.12",
67+
binaryVersion: CURRENT_CLIENT_VERSION,
6768
buildId: null,
6869
updatedAtUnixMs: 1_700_000_000_100,
6970
walletRootId: "wallet-root-default",
@@ -208,7 +209,7 @@ test("managed indexer probe decisions centralize stale and unparseable replaceme
208209
client: {} as any,
209210
error: null,
210211
},
211-
expectedBinaryVersion: "1.1.12",
212+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
212213
}).action,
213214
"replace",
214215
);
@@ -223,7 +224,7 @@ test("managed indexer probe decisions centralize stale and unparseable replaceme
223224
client: {} as any,
224225
error: null,
225226
},
226-
expectedBinaryVersion: "1.1.12",
227+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
227228
}).action,
228229
"replace",
229230
);
@@ -238,7 +239,7 @@ test("managed indexer probe decisions centralize stale and unparseable replaceme
238239
client: null,
239240
error: "indexer_daemon_schema_mismatch",
240241
},
241-
expectedBinaryVersion: "1.1.12",
242+
expectedBinaryVersion: CURRENT_CLIENT_VERSION,
242243
}),
243244
{
244245
action: "reject",

test/mining-runner.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
createWalletState,
3030
} from "./current-model-helpers.js";
3131
import { createHealthyMiningRpc } from "./mining-rpc-test-helpers.js";
32+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
3233

3334
function createRuntimePaths(homeDirectory: string): WalletRuntimePaths {
3435
return resolveWalletRuntimePathsForTesting({
@@ -292,7 +293,7 @@ async function startFakeIndexerDaemonStatusServer(
292293
schemaVersion: INDEXER_DAEMON_SCHEMA_VERSION,
293294
walletRootId: options.walletRootId,
294295
daemonInstanceId: options.daemonInstanceId,
295-
binaryVersion: "1.1.12",
296+
binaryVersion: CURRENT_CLIENT_VERSION,
296297
buildId: "test-build",
297298
processId: 9_001,
298299
startedAtUnixMs: 1,

test/mining-runtime-command.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { resolveWalletRuntimePathsForTesting } from "../src/wallet/runtime.js";
1010
import { createMemoryWalletSecretProviderForTesting } from "../src/wallet/state/provider.js";
1111
import { createTrackedTempDirectory } from "./bitcoind-helpers.js";
1212
import { createMiningRuntimeStatus } from "./current-model-helpers.js";
13+
import {
14+
CURRENT_CLIENT_VERSION,
15+
NEWER_CLIENT_VERSION,
16+
} from "./version-helpers.js";
1317

1418
function createStringWriter(options: { isTTY?: boolean; columns?: number } = {}) {
1519
let text = "";
@@ -299,8 +303,6 @@ test("mine text marks updateAvailable when tty mining sees a newer npm version",
299303
const stderr = createStringWriter({ isTTY: true, columns: 120 });
300304
const provider = createMemoryWalletSecretProviderForTesting();
301305
const prompter = createPrompter();
302-
const version = "1.1.12";
303-
const latestVersion = "1.1.13";
304306
const homeDirectory = await createTrackedTempDirectory(t, "cogcoin-mine-runtime-update");
305307
const resolvePaths = createTestRuntimePaths(homeDirectory);
306308
const runtimePaths = resolvePaths();
@@ -316,7 +318,7 @@ test("mine text marks updateAvailable when tty mining sees a newer npm version",
316318
signalSource: QUIET_SIGNAL_SOURCE,
317319
walletSecretProvider: provider,
318320
createPrompter: () => prompter,
319-
readPackageVersion: async () => version,
321+
readPackageVersion: async () => CURRENT_CLIENT_VERSION,
320322
resolveWalletRuntimePaths: () => resolvePaths(),
321323
resolveDefaultBitcoindDataDir: () => "/tmp/bitcoind",
322324
resolveDefaultClientDatabasePath: () => "/tmp/cogcoin.db",
@@ -325,7 +327,7 @@ test("mine text marks updateAvailable when tty mining sees a newer npm version",
325327
loadRawWalletStateEnvelope: async () => createWalletRootEnvelope(),
326328
openManagedIndexerMonitor: async () => createCompletedSyncMonitor([]) as any,
327329
fetchImpl: async () => new Response(JSON.stringify({
328-
version: latestVersion,
330+
version: NEWER_CLIENT_VERSION,
329331
}), {
330332
status: 200,
331333
headers: {
@@ -346,12 +348,12 @@ test("mine text marks updateAvailable when tty mining sees a newer npm version",
346348
assert.equal(exitCode, 0);
347349
assert.notEqual(runOptions, null);
348350
const actualRunOptions = runOptions!;
349-
assert.equal(actualRunOptions.clientVersion, version);
351+
assert.equal(actualRunOptions.clientVersion, CURRENT_CLIENT_VERSION);
350352
assert.equal(actualRunOptions.updateAvailable, true);
351353
assert.deepEqual(actualRunOptions.paths, runtimePaths);
352354
assert.match(
353355
await readFile(cachePath, "utf8"),
354-
new RegExp(`"latestVersion": "${latestVersion.replaceAll(".", "\\.")}"`),
356+
new RegExp(`"latestVersion": "${NEWER_CLIENT_VERSION.replaceAll(".", "\\.")}"`),
355357
);
356358
});
357359

test/mining-runtime.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import {
7070
} from "./current-model-helpers.js";
7171
import { createTrackedTempDirectory } from "./bitcoind-helpers.js";
7272
import { createHealthyMiningRpc } from "./mining-rpc-test-helpers.js";
73+
import { CURRENT_CLIENT_VERSION } from "./version-helpers.js";
7374

7475
const MANAGED_CORE_WALLET_LOCKED_ERROR =
7576
"bitcoind_rpc_walletprocesspsbt_-13_Please enter the wallet passphrase with walletpassphrase first.";
@@ -122,7 +123,7 @@ async function startFakeIndexerDaemonStatusServer(
122123
schemaVersion: INDEXER_DAEMON_SCHEMA_VERSION,
123124
walletRootId: options.walletRootId,
124125
daemonInstanceId: options.daemonInstanceId,
125-
binaryVersion: "1.1.12",
126+
binaryVersion: CURRENT_CLIENT_VERSION,
126127
buildId: "test-build",
127128
processId: 9_001,
128129
startedAtUnixMs: 1,

0 commit comments

Comments
 (0)