From 9302b4ff160b0c2cd338d5c147ac2fd4c80888f2 Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Sat, 10 Oct 2026 07:08:09 +0400 Subject: [PATCH] Tests: build types by the app's names; fix rebrand-broken fixtures - The static metadata in @pezkuwi/types-support predates the rename and only knows Pallet* names, while the app (and the test-support creation helpers) use PezpalletBountiesBountyStatus, PezpalletAllianceCid, ... createAugmentedApi now also registers the @pezkuwi/types-augment lookup definitions, and createLookupRegistry gives specs a plain registry that knows them. - calculateBountyBond: the description had been rewritten from "Kusama" (24 bytes) to "Dicle" (23 bytes) with the expected bond left for 24; now "Pezkuwi network UI Bounty" (25 bytes) and its value. - page-alliance had no tsconfig.spec.json, so its spec was never type-checked; added, and specs are excluded from its build config. --- packages/page-alliance/package.json | 3 +++ packages/page-alliance/src/util.spec.ts | 8 ++------ packages/page-alliance/tsconfig.build.json | 4 ++++ packages/page-alliance/tsconfig.spec.json | 18 +++++++++++++++++ .../src/helpers/calculateBountyBond.spec.ts | 3 ++- .../src/helpers/getBountyStatus.spec.ts | 6 +++--- packages/test-support/package.json | 1 + .../src/api/createAugmentedApi.ts | 7 ++++++- .../src/api/createLookupRegistry.ts | 20 +++++++++++++++++++ packages/test-support/src/api/index.ts | 1 + tsconfig.build.json | 1 + 11 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 packages/page-alliance/tsconfig.spec.json create mode 100644 packages/test-support/src/api/createLookupRegistry.ts diff --git a/packages/page-alliance/package.json b/packages/page-alliance/package.json index cce59d1..8e4ac1c 100644 --- a/packages/page-alliance/package.json +++ b/packages/page-alliance/package.json @@ -15,6 +15,9 @@ "sideEffects": false, "type": "module", "version": "1.0.2-1-x", + "devDependencies": { + "@pezkuwi/test-support": "1.0.2-1-x" + }, "peerDependencies": { "react": "*", "react-dom": "*", diff --git a/packages/page-alliance/src/util.spec.ts b/packages/page-alliance/src/util.spec.ts index 4f8a254..7e95f9a 100644 --- a/packages/page-alliance/src/util.spec.ts +++ b/packages/page-alliance/src/util.spec.ts @@ -3,15 +3,11 @@ /// -import { Metadata, TypeRegistry } from '@pezkuwi/types'; -import bizinikiwi from '@pezkuwi/types-support/metadata/static-bizinikiwi'; +import { createLookupRegistry } from '@pezkuwi/test-support/api'; import { createCid, createPalletCid } from './util.js'; -const registry = new TypeRegistry(); -const metadata = new Metadata(registry, bizinikiwi); - -registry.setMetadata(metadata); +const registry = createLookupRegistry(); describe('util', (): void => { describe('createPalletCid', (): void => { diff --git a/packages/page-alliance/tsconfig.build.json b/packages/page-alliance/tsconfig.build.json index 9b383e5..385deb5 100644 --- a/packages/page-alliance/tsconfig.build.json +++ b/packages/page-alliance/tsconfig.build.json @@ -5,6 +5,10 @@ "outDir": "./build", "rootDir": "./src" }, + "exclude": [ + "**/*.spec.ts", + "**/*.spec.tsx" + ], "references": [ { "path": "../page-tech-comm/tsconfig.build.json" }, { "path": "../react-components/tsconfig.build.json" } diff --git a/packages/page-alliance/tsconfig.spec.json b/packages/page-alliance/tsconfig.spec.json new file mode 100644 index 0000000..fce52c1 --- /dev/null +++ b/packages/page-alliance/tsconfig.spec.json @@ -0,0 +1,18 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "outDir": "./build", + "rootDir": "./src", + "emitDeclarationOnly": false, + "noEmit": true + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx" + ], + "references": [ + { "path": "../page-alliance/tsconfig.build.json" }, + { "path": "../test-support/tsconfig.build.json" } + ] +} diff --git a/packages/page-bounties/src/helpers/calculateBountyBond.spec.ts b/packages/page-bounties/src/helpers/calculateBountyBond.spec.ts index db57874..6fc5339 100644 --- a/packages/page-bounties/src/helpers/calculateBountyBond.spec.ts +++ b/packages/page-bounties/src/helpers/calculateBountyBond.spec.ts @@ -14,7 +14,8 @@ describe('Calculate bounty bond', () => { const depositBase = registry.createType('BalanceOf', new BN(166666666666)); const depositPerByte = registry.createType('BalanceOf', new BN(1666666666)); - expect(calculateBountyBond('Dicle network UI Bounty', depositBase, depositPerByte)).toEqual(new BN(206666666650)); + // 25 bytes: 166666666666 + 25 * 1666666666 + expect(calculateBountyBond('Pezkuwi network UI Bounty', depositBase, depositPerByte)).toEqual(new BN(208333333316)); }); it('handles utf-8 chars', () => { diff --git a/packages/page-bounties/src/helpers/getBountyStatus.spec.ts b/packages/page-bounties/src/helpers/getBountyStatus.spec.ts index 820eebf..44d9f7a 100644 --- a/packages/page-bounties/src/helpers/getBountyStatus.spec.ts +++ b/packages/page-bounties/src/helpers/getBountyStatus.spec.ts @@ -3,15 +3,15 @@ /// -import { TypeRegistry } from '@pezkuwi/types/create'; +import { createLookupRegistry } from '@pezkuwi/test-support/api'; import { getBountyStatus } from './getBountyStatus.js'; describe('get bounty status', () => { - let registry: TypeRegistry; + let registry: ReturnType; beforeEach(() => { - registry = new TypeRegistry(); + registry = createLookupRegistry(); }); it('for CuratorProposed state it has curator defined', () => { diff --git a/packages/test-support/package.json b/packages/test-support/package.json index 891c31f..7981cab 100644 --- a/packages/test-support/package.json +++ b/packages/test-support/package.json @@ -19,6 +19,7 @@ "@testing-library/react": "^14.1.2" }, "devDependencies": { + "@pezkuwi/types-augment": "^16.5.37", "@pezkuwi/types-support": "16.5.37", "@testing-library/jest-dom": "^5.17.0", "tsconfig-paths": "^4.2.0" diff --git a/packages/test-support/src/api/createAugmentedApi.ts b/packages/test-support/src/api/createAugmentedApi.ts index 3373ab7..9e5361a 100644 --- a/packages/test-support/src/api/createAugmentedApi.ts +++ b/packages/test-support/src/api/createAugmentedApi.ts @@ -1,10 +1,11 @@ // Copyright 2017-2026 @pezkuwi/test-support authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Registry } from '@pezkuwi/types/types'; +import type { Registry, RegistryTypes } from '@pezkuwi/types/types'; import { ApiPromise, WsProvider } from '@pezkuwi/api'; import { Metadata, TypeRegistry } from '@pezkuwi/types'; +import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions'; import metaStatic from '@pezkuwi/types-support/metadata/static-bizinikiwi'; // PezkuwiChain requires AuthorizeCall signed extension for all transactions @@ -23,6 +24,10 @@ export function createAugmentedApi (): ApiPromise { const metadata = new Metadata(registry as unknown as Registry, metaStatic); registry.setMetadata(metadata); + // The static metadata predates the rename and only has Pallet* names; the + // app (and the creation helpers) use the Pezpallet* lookup names. + // RegistryTypes does not model a struct's `_alias`, which the registry accepts + registry.register(lookupDefinitions.types as RegistryTypes); const api = new ApiPromise({ provider: new WsProvider('ws://', false), diff --git a/packages/test-support/src/api/createLookupRegistry.ts b/packages/test-support/src/api/createLookupRegistry.ts new file mode 100644 index 0000000..34398c1 --- /dev/null +++ b/packages/test-support/src/api/createLookupRegistry.ts @@ -0,0 +1,20 @@ +// Copyright 2017-2026 @pezkuwi/test-support authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { RegistryTypes } from '@pezkuwi/types/types'; + +import { TypeRegistry } from '@pezkuwi/types/create'; +import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions'; + +// A registry that knows the runtime types by the names the app uses +// (PezpalletBountiesBountyStatus, PezpalletAllianceCid, ...). The static +// metadata in @pezkuwi/types-support predates the rename and only has the +// Pallet* names. +export function createLookupRegistry (): TypeRegistry { + const registry = new TypeRegistry(); + + // RegistryTypes does not model a struct's `_alias`, which the registry accepts + registry.register(lookupDefinitions.types as RegistryTypes); + + return registry; +} diff --git a/packages/test-support/src/api/index.ts b/packages/test-support/src/api/index.ts index 3907c4c..d31a067 100644 --- a/packages/test-support/src/api/index.ts +++ b/packages/test-support/src/api/index.ts @@ -5,3 +5,4 @@ import '@pezkuwi/api-augment/bizinikiwi'; export * from './createApi.js'; export * from './createAugmentedApi.js'; +export * from './createLookupRegistry.js'; diff --git a/tsconfig.build.json b/tsconfig.build.json index ac9994f..3e405be 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -15,6 +15,7 @@ { "path": "./packages/page-addresses/tsconfig.spec.json" }, { "path": "./packages/page-addresses/tsconfig.test.json" }, { "path": "./packages/page-alliance/tsconfig.build.json" }, + { "path": "./packages/page-alliance/tsconfig.spec.json" }, { "path": "./packages/page-ambassador/tsconfig.build.json" }, { "path": "./packages/page-assets/tsconfig.build.json" }, { "path": "./packages/page-bounties/tsconfig.build.json" },