@ledgerhq/coin-module-framework 11.4.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ledgerhq/coin-module-framework
2
2
 
3
+ ## 12.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1324](https://github.com/LedgerHQ/coin-modules/pull/1324) [`f45c1e8`](https://github.com/LedgerHQ/coin-modules/commit/f45c1e8967e3c9685d74f75e11646ea8f044bd5b) Thanks [@cted-ledger](https://github.com/cted-ledger)! - `capabilityReport()` reports `supported`, the optional capabilities a module implements, in place of `unsupported`. A module's test asserts `{ supported, inconsistent }` and no longer breaks when a framework release adds a capability.
8
+
3
9
  ## 11.4.0
4
10
 
5
11
  ### Minor Changes
@@ -2,28 +2,34 @@ import type { CoinModuleImpl, OptionalApiKey } from '../api/impl';
2
2
  import type { Memo, TxData } from '../api/types';
3
3
  import type { Context, CurrencyConfig } from '../config';
4
4
  /**
5
- * What a module reports about the capabilities it does not implement, as a consumer sees it
6
- * through `withDefaults`. Meant to be asserted whole:
5
+ * What a module reports about its optional capabilities, as a consumer sees it through
6
+ * `withDefaults`. Meant to be asserted whole:
7
7
  *
8
8
  * ```ts
9
9
  * await expect(capabilityReport(createApi(), context)).resolves.toEqual({
10
- * unsupported: ['call', 'craftRawTransaction', 'getRewards', 'getValidators', 'register'],
10
+ * supported: ['getBlock', 'getBlockInfo', 'getStakes', 'validateAddress', 'validateIntent'],
11
11
  * inconsistent: [],
12
12
  * })
13
13
  * ```
14
14
  *
15
- * One expectation then covers what a module's api test used to spell out method by method:
16
- * that each capability is absent, that reaching it raises `"<name> is not supported"`, and
17
- * that `supports()` agrees. `toEqual` makes it exhaustive — a capability dropped or newly
18
- * implemented changes the list, so the test notices instead of silently still passing.
15
+ * `supported` lists what the module implements, so it changes only when the module does: a
16
+ * capability dropped or newly implemented changes the list, and the test notices instead of
17
+ * silently still passing. A capability the framework adds is not implemented by an existing
18
+ * module, so it leaves the list alone: a framework release that adds a capability does not break
19
+ * the modules' tests.
20
+ *
21
+ * Every other capability is reached, and must raise `"<name> is not supported"`; one that does
22
+ * not lands in `inconsistent`. An empty `inconsistent` therefore covers what a module's api test
23
+ * used to spell out method by method: that each absent capability raises its error, and that
24
+ * `supports()` agrees.
19
25
  *
20
26
  * It reads a module written either way: a `CoinModuleImpl` that omits its capabilities, or a
21
27
  * value built by spreading `notSupportedApi()`. Both are "not implemented" as far as
22
28
  * `supports()` is concerned, which is what this observes.
23
29
  */
24
30
  export type CapabilityReport = {
25
- /** Capabilities the module does not implement, sorted, each verified to raise its error. */
26
- unsupported: OptionalApiKey[];
31
+ /** Capabilities the module implements, sorted: those `supports()` reports present. */
32
+ supported: OptionalApiKey[];
27
33
  /**
28
34
  * Capabilities `supports()` calls absent but which did not raise `"<name> is not
29
35
  * supported"` when reached — a missing backfill, or an error naming another method.
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAQxD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,4FAA4F;IAC5F,WAAW,EAAE,cAAc,EAAE,CAAA;IAC7B;;;;OAIG;IACH,YAAY,EAAE,cAAc,EAAE,CAAA;CAC/B,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,EACrB,UAAU,SAAS,MAAM,EAEzB,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EACtD,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAgC3B"}
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAQxD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sFAAsF;IACtF,SAAS,EAAE,cAAc,EAAE,CAAA;IAC3B;;;;OAIG;IACH,YAAY,EAAE,cAAc,EAAE,CAAA;CAC/B,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,SAAS,cAAc,EACjC,QAAQ,SAAS,IAAI,EACrB,UAAU,SAAS,MAAM,EAEzB,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,EACtD,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAsC3B"}
@@ -19,11 +19,15 @@ const isMethod = (value) => typeof value === 'function';
19
19
  async function capabilityReport(impl, context) {
20
20
  const resolved = (0, withDefaults_1.withDefaults)(impl);
21
21
  const asRecord = resolved;
22
- const unsupported = [];
22
+ const supported = [];
23
23
  const inconsistent = [];
24
24
  for (const name of impl_1.optionalApiKeys) {
25
- if (name === 'getAccountInfo' || resolved.supports(name))
25
+ if (name === 'getAccountInfo')
26
26
  continue;
27
+ if (resolved.supports(name)) {
28
+ supported.push(name);
29
+ continue;
30
+ }
27
31
  const method = asRecord[name];
28
32
  if (!isMethod(method)) {
29
33
  inconsistent.push(name);
@@ -34,11 +38,12 @@ async function capabilityReport(impl, context) {
34
38
  const raised = await Promise.resolve()
35
39
  .then(() => method(context))
36
40
  .then(() => undefined, (error) => (error instanceof Error ? error.message : String(error)));
37
- if (raised === `${name} is not supported`)
38
- unsupported.push(name);
39
- else
41
+ if (raised !== `${name} is not supported`)
40
42
  inconsistent.push(name);
41
43
  }
42
- return { unsupported: unsupported.sort(), inconsistent: inconsistent.sort() };
44
+ return {
45
+ supported: supported.sort(),
46
+ inconsistent: inconsistent.sort(),
47
+ };
43
48
  }
44
49
  //# sourceMappingURL=capabilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAoDtC,4CAuCC;AAtFD,sCAA6C;AAC7C,sDAAkD;AAElD,iFAAiF;AACjF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4C,EAAE,CAC5E,OAAO,KAAK,KAAK,UAAU,CAAA;AAiC7B;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CAKpC,IAAsD,EACtD,OAA4B;IAE5B,MAAM,QAAQ,GAEV,IAAA,2BAAY,EAAC,IAAI,CAAC,CAAA;IACtB,MAAM,QAAQ,GAA4B,QAAQ,CAAA;IAElD,MAAM,WAAW,GAAqB,EAAE,CAAA;IACxC,MAAM,YAAY,GAAqB,EAAE,CAAA;IAEzC,KAAK,MAAM,IAAI,IAAI,sBAAe,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,gBAAgB,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAQ;QAElE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvB,SAAQ;QACV,CAAC;QAED,0FAA0F;QAC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AQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACpB,SAAQ;QACV,CAAC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvB,SAAQ;QACV,CAAC;QAED,0FAA0F;QAC1F,gFAAgF;QAChF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE;aACnC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC3B,IAAI,CACH,GAAG,EAAE,CAAC,SAAS,EACf,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAA;QAEH,IAAI,MAAM,KAAK,GAAG,IAAI,mBAAmB;YAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpE,CAAC;IAED,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE;QAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE;KAClC,CAAA;AACH,CAAC"}
@@ -2,28 +2,34 @@ import type { CoinModuleImpl, OptionalApiKey } from '../api/impl';
2
2
  import type { Memo, TxData } from '../api/types';
3
3
  import type { Context, CurrencyConfig } from '../config';
4
4
  /**
5
- * What a module reports about the capabilities it does not implement, as a consumer sees it
6
- * through `withDefaults`. Meant to be asserted whole:
5
+ * What a module reports about its optional capabilities, as a consumer sees it through
6
+ * `withDefaults`. Meant to be asserted whole:
7
7
  *
8
8
  * ```ts
9
9
  * await expect(capabilityReport(createApi(), context)).resolves.toEqual({
10
- * unsupported: ['call', 'craftRawTransaction', 'getRewards', 'getValidators', 'register'],
10
+ * supported: ['getBlock', 'getBlockInfo', 'getStakes', 'validateAddress', 'validateIntent'],
11
11
  * inconsistent: [],
12
12
  * })
13
13
  * ```
14
14
  *
15
- * One expectation then covers what a module's api test used to spell out method by method:
16
- * that each capability is absent, that reaching it raises `"<name> is not supported"`, and
17
- * that `supports()` agrees. `toEqual` makes it exhaustive — a capability dropped or newly
18
- * implemented changes the list, so the test notices instead of silently still passing.
15
+ * `supported` lists what the module implements, so it changes only when the module does: a
16
+ * capability dropped or newly implemented changes the list, and the test notices instead of
17
+ * silently still passing. A capability the framework adds is not implemented by an existing
18
+ * module, so it leaves the list alone: a framework release that adds a capability does not break
19
+ * the modules' tests.
20
+ *
21
+ * Every other capability is reached, and must raise `"<name> is not supported"`; one that does
22
+ * not lands in `inconsistent`. An empty `inconsistent` therefore covers what a module's api test
23
+ * used to spell out method by method: that each absent capability raises its error, and that
24
+ * `supports()` agrees.
19
25
  *
20
26
  * It reads a module written either way: a `CoinModuleImpl` that omits its capabilities, or a
21
27
  * value built by spreading `notSupportedApi()`. Both are "not implemented" as far as
22
28
  * `supports()` is concerned, which is what this observes.
23
29
  */
24
30
  export type CapabilityReport = {
25
- /** Capabilities the module does not implement, sorted, each verified to raise its error. */
26
- unsupported: OptionalApiKey[];
31
+ /** Capabilities the module implements, sorted: those `supports()` reports present. */
32
+ supported: OptionalApiKey[];
27
33
  /**
28
34
  * Capabilities `supports()` calls absent but which did not raise `"<name> is not
29
35
  * supported"` when reached — a missing backfill, or an error naming another method.
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WA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(value) => typeof value === 'function';
16
16
  export async function capabilityReport(impl, context) {
17
17
  const resolved = withDefaults(impl);
18
18
  const asRecord = resolved;
19
- const unsupported = [];
19
+ const supported = [];
20
20
  const inconsistent = [];
21
21
  for (const name of optionalApiKeys) {
22
- if (name === 'getAccountInfo' || resolved.supports(name))
22
+ if (name === 'getAccountInfo')
23
23
  continue;
24
+ if (resolved.supports(name)) {
25
+ supported.push(name);
26
+ continue;
27
+ }
24
28
  const method = asRecord[name];
25
29
  if (!isMethod(method)) {
26
30
  inconsistent.push(name);
@@ -31,11 +35,12 @@ export async function capabilityReport(impl, context) {
31
35
  const raised = await Promise.resolve()
32
36
  .then(() => method(context))
33
37
  .then(() => undefined, (error) => (error instanceof Error ? error.message : String(error)));
34
- if (raised === `${name} is not supported`)
35
- unsupported.push(name);
36
- else
38
+ if (raised !== `${name} is not supported`)
37
39
  inconsistent.push(name);
38
40
  }
39
- return { unsupported: unsupported.sort(), inconsistent: inconsistent.sort() };
41
+ return {
42
+ supported: supported.sort(),
43
+ inconsistent: inconsistent.sort(),
44
+ };
40
45
  }
41
46
  //# sourceMappingURL=capabilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/test-utils/capabilities.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAKtC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,iFAAiF;AACjF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4C,EAAE,CAC5E,OAAO,KAAK,KAAK,UAAU,CAAA;AAiC7B;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAKpC,IAAsD,EACtD,OAA4B;IAE5B,MAAM,QAAQ,GAEV,YAAY,CAAC,IAAI,CAAC,CAAA;IACtB,MAAM,QAAQ,GAA4B,QAAQ,CAAA;IAElD,MAAM,WAAW,GAAq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SAAS,CAAC,IAAI,EAAE;QAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE;KAClC,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-module-framework",
3
- "version": "11.4.0",
3
+ "version": "12.0.0",
4
4
  "description": "Ledger framework for Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -25,40 +25,36 @@ const minimalModule: CoinModuleImpl<Cfg> = {
25
25
  craftTransactionData: (_ctx: Ctx, _intent: TransactionIntent) => ({ type: 'none' }) as const,
26
26
  }
27
27
 
28
- // Every optional capability but getAccountInfo, which ADR-045 answers with a sentinel rather
29
- // than an error and which the report therefore leaves out.
30
- const ALL_CAPABILITIES = [
31
- 'call',
32
- 'craftRawTransaction',
33
- 'getBlock',
34
- 'getBlockInfo',
35
- 'getNextSequence',
36
- 'getRewards',
37
- 'getStakes',
38
- 'getValidators',
39
- 'listHoldings',
40
- 'register',
41
- 'validateAddress',
42
- 'validateIntent',
43
- ]
44
-
45
28
  describe('capabilityReport', () => {
46
- it('lists every capability a minimal module leaves out', async () => {
29
+ it('reports nothing supported for a minimal module', async () => {
47
30
  await expect(capabilityReport(minimalModule, ctx)).resolves.toEqual({
48
- unsupported: ALL_CAPABILITIES,
31
+ supported: [],
49
32
  inconsistent: [],
50
33
  })
51
34
  })
52
35
 
53
- it('drops a capability from the list once the module implements it', async () => {
54
- const withStaking: CoinModuleImpl<Cfg> = {
36
+ it('lists the capabilities a module implements, sorted', async () => {
37
+ const withReads: CoinModuleImpl<Cfg> = {
55
38
  ...minimalModule,
56
39
  getStakes: (_ctx: Ctx, _addr: string) => Promise.resolve({ items: [] }),
40
+ getBlockInfo: (_ctx: Ctx, _height: number): Promise<BlockInfo> =>
41
+ Promise.reject(new Error('stub')),
42
+ }
43
+ await expect(capabilityReport(withReads, ctx)).resolves.toEqual({
44
+ supported: ['getBlockInfo', 'getStakes'],
45
+ inconsistent: [],
46
+ })
47
+ })
48
+
49
+ // `getAccountInfo` answers a sentinel rather than an error (ADR-045), so it is no capability
50
+ // in the sense of this report, implemented or not.
51
+ it('leaves getAccountInfo out', async () => {
52
+ const withAccountInfo: CoinModuleImpl<Cfg> = {
53
+ ...minimalModule,
54
+ getAccountInfo: (_ctx: Ctx, _addr: string) => Promise.resolve({ type: 'none' } as const),
57
55
  }
58
- const report = await capabilityReport(withStaking, ctx)
59
- expect(report.unsupported).not.toContain('getStakes')
60
- expect(report.unsupported).toContain('getRewards')
61
- expect(report.inconsistent).toEqual([])
56
+ const report = await capabilityReport(withAccountInfo, ctx)
57
+ expect(report.supported).not.toContain('getAccountInfo')
62
58
  })
63
59
 
64
60
  // A module built by spreading `notSupportedApi()` carries a stub for everything, where a
@@ -71,10 +67,10 @@ describe('capabilityReport', () => {
71
67
  getBalance: minimalModule.getBalance,
72
68
  getStakes: (_ctx: Ctx, _addr: string) => Promise.resolve({ items: [] }),
73
69
  }
74
- const report = await capabilityReport(spread, ctx)
75
- expect(report.unsupported).not.toContain('getStakes')
76
- expect(report.unsupported).toContain('getValidators')
77
- expect(report.inconsistent).toEqual([])
70
+ await expect(capabilityReport(spread, ctx)).resolves.toEqual({
71
+ supported: ['getStakes'],
72
+ inconsistent: [],
73
+ })
78
74
  })
79
75
 
80
76
  it('never invokes an implemented capability', async () => {
@@ -83,27 +79,29 @@ describe('capabilityReport', () => {
83
79
  expect(network).not.toHaveBeenCalled()
84
80
  })
85
81
 
86
- it('counts a stub that rejects asynchronously as raising the error', async () => {
82
+ it('counts a hand-written stub as implemented', async () => {
87
83
  const asyncStub = {
88
84
  ...minimalModule,
89
85
  getRewards: (_ctx: Ctx, _addr: string) =>
90
86
  Promise.reject(new Error('getRewards is not supported')),
91
87
  }
92
- const report = await capabilityReport(asyncStub, ctx)
93
- // The module fills the slot, so `supports()` calls it implemented and the report skips it —
94
- // the tagged-stub check is what tells a placeholder apart, and an inline throw cannot be
95
- // told apart from an implementation.
96
- expect(report.unsupported).not.toContain('getRewards')
97
- expect(report.inconsistent).toEqual([])
88
+ // The module fills the slot, so `supports()` calls it implemented — the tagged-stub check is
89
+ // what tells a placeholder apart, and an inline throw cannot be told apart from an
90
+ // implementation.
91
+ await expect(capabilityReport(asyncStub, ctx)).resolves.toEqual({
92
+ supported: ['getRewards'],
93
+ inconsistent: [],
94
+ })
98
95
  })
99
96
 
100
97
  it('re-labels a tagged stub whose error names another method', async () => {
101
98
  const mislabelled = { ...minimalModule, getValidators: notSupported('getStakes') }
102
- const report = await capabilityReport(mislabelled, ctx)
103
99
  // A tagged stub counts as omitted, so `withDefaults` replaces it with its own — which names
104
100
  // the method it stands for. The mislabelling `coin-canton` shipped cannot survive the
105
101
  // resolver, and `inconsistent` stays empty: it only fills if a backfill goes missing.
106
- expect(report.unsupported).toContain('getValidators')
107
- expect(report.inconsistent).toEqual([])
102
+ await expect(capabilityReport(mislabelled, ctx)).resolves.toEqual({
103
+ supported: [],
104
+ inconsistent: [],
105
+ })
108
106
  })
109
107
  })
@@ -12,28 +12,34 @@ const isMethod = (value: unknown): value is (...args: unknown[]) => unknown =>
12
12
  typeof value === 'function'
13
13
 
14
14
  /**
15
- * What a module reports about the capabilities it does not implement, as a consumer sees it
16
- * through `withDefaults`. Meant to be asserted whole:
15
+ * What a module reports about its optional capabilities, as a consumer sees it through
16
+ * `withDefaults`. Meant to be asserted whole:
17
17
  *
18
18
  * ```ts
19
19
  * await expect(capabilityReport(createApi(), context)).resolves.toEqual({
20
- * unsupported: ['call', 'craftRawTransaction', 'getRewards', 'getValidators', 'register'],
20
+ * supported: ['getBlock', 'getBlockInfo', 'getStakes', 'validateAddress', 'validateIntent'],
21
21
  * inconsistent: [],
22
22
  * })
23
23
  * ```
24
24
  *
25
- * One expectation then covers what a module's api test used to spell out method by method:
26
- * that each capability is absent, that reaching it raises `"<name> is not supported"`, and
27
- * that `supports()` agrees. `toEqual` makes it exhaustive — a capability dropped or newly
28
- * implemented changes the list, so the test notices instead of silently still passing.
25
+ * `supported` lists what the module implements, so it changes only when the module does: a
26
+ * capability dropped or newly implemented changes the list, and the test notices instead of
27
+ * silently still passing. A capability the framework adds is not implemented by an existing
28
+ * module, so it leaves the list alone: a framework release that adds a capability does not break
29
+ * the modules' tests.
30
+ *
31
+ * Every other capability is reached, and must raise `"<name> is not supported"`; one that does
32
+ * not lands in `inconsistent`. An empty `inconsistent` therefore covers what a module's api test
33
+ * used to spell out method by method: that each absent capability raises its error, and that
34
+ * `supports()` agrees.
29
35
  *
30
36
  * It reads a module written either way: a `CoinModuleImpl` that omits its capabilities, or a
31
37
  * value built by spreading `notSupportedApi()`. Both are "not implemented" as far as
32
38
  * `supports()` is concerned, which is what this observes.
33
39
  */
34
40
  export type CapabilityReport = {
35
- /** Capabilities the module does not implement, sorted, each verified to raise its error. */
36
- unsupported: OptionalApiKey[]
41
+ /** Capabilities the module implements, sorted: those `supports()` reports present. */
42
+ supported: OptionalApiKey[]
37
43
  /**
38
44
  * Capabilities `supports()` calls absent but which did not raise `"<name> is not
39
45
  * supported"` when reached — a missing backfill, or an error naming another method.
@@ -64,11 +70,15 @@ export async function capabilityReport<
64
70
  } = withDefaults(impl)
65
71
  const asRecord: Record<string, unknown> = resolved
66
72
 
67
- const unsupported: OptionalApiKey[] = []
73
+ const supported: OptionalApiKey[] = []
68
74
  const inconsistent: OptionalApiKey[] = []
69
75
 
70
76
  for (const name of optionalApiKeys) {
71
- if (name === 'getAccountInfo' || resolved.supports(name)) continue
77
+ if (name === 'getAccountInfo') continue
78
+ if (resolved.supports(name)) {
79
+ supported.push(name)
80
+ continue
81
+ }
72
82
 
73
83
  const method = asRecord[name]
74
84
  if (!isMethod(method)) {
@@ -85,9 +95,11 @@ export async function capabilityReport<
85
95
  (error: unknown) => (error instanceof Error ? error.message : String(error))
86
96
  )
87
97
 
88
- if (raised === `${name} is not supported`) unsupported.push(name)
89
- else inconsistent.push(name)
98
+ if (raised !== `${name} is not supported`) inconsistent.push(name)
90
99
  }
91
100
 
92
- return { unsupported: unsupported.sort(), inconsistent: inconsistent.sort() }
101
+ return {
102
+ supported: supported.sort(),
103
+ inconsistent: inconsistent.sort(),
104
+ }
93
105
  }