@ledgerhq/coin-module-framework 11.0.0 → 11.3.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 +30 -0
- package/lib/api/getBlock/assertBlockHeight.d.ts +2 -0
- package/lib/api/getBlock/assertBlockHeight.d.ts.map +1 -0
- package/lib/api/getBlock/assertBlockHeight.js +12 -0
- package/lib/api/getBlock/assertBlockHeight.js.map +1 -0
- package/lib/api/impl.d.ts +19 -1
- package/lib/api/impl.d.ts.map +1 -1
- package/lib/api/types.d.ts +79 -2
- package/lib/api/types.d.ts.map +1 -1
- package/lib/api/withDefaults.d.ts +13 -2
- package/lib/api/withDefaults.d.ts.map +1 -1
- package/lib/api/withDefaults.js +35 -1
- package/lib/api/withDefaults.js.map +1 -1
- package/lib/currencies/formatCurrencyUnit.js +1 -1
- package/lib/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib/currencies/parseCurrencyUnit.js +1 -1
- package/lib/currencies/parseCurrencyUnit.js.map +1 -1
- package/lib/errors.d.ts +37 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +71 -2
- package/lib/errors.js.map +1 -1
- package/lib/promises/promises.d.ts +1 -1
- package/lib/promises/promises.d.ts.map +1 -1
- package/lib/promises/promises.js +1 -1
- package/lib/promises/promises.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +9 -0
- package/lib/utils.js.map +1 -1
- package/lib-es/api/getBlock/assertBlockHeight.d.ts +2 -0
- package/lib-es/api/getBlock/assertBlockHeight.d.ts.map +1 -0
- package/lib-es/api/getBlock/assertBlockHeight.js +9 -0
- package/lib-es/api/getBlock/assertBlockHeight.js.map +1 -0
- package/lib-es/api/impl.d.ts +19 -1
- package/lib-es/api/impl.d.ts.map +1 -1
- package/lib-es/api/types.d.ts +79 -2
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/api/withDefaults.d.ts +13 -2
- package/lib-es/api/withDefaults.d.ts.map +1 -1
- package/lib-es/api/withDefaults.js +35 -1
- package/lib-es/api/withDefaults.js.map +1 -1
- package/lib-es/currencies/formatCurrencyUnit.js +1 -1
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib-es/currencies/parseCurrencyUnit.js +1 -1
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -1
- package/lib-es/errors.d.ts +37 -1
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +64 -1
- package/lib-es/errors.js.map +1 -1
- package/lib-es/promises/promises.d.ts +1 -1
- package/lib-es/promises/promises.d.ts.map +1 -1
- package/lib-es/promises/promises.js +1 -1
- package/lib-es/promises/promises.js.map +1 -1
- package/lib-es/utils.d.ts +1 -0
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +8 -0
- package/lib-es/utils.js.map +1 -1
- package/package.json +12 -6
- package/src/api/getBalance/rejectBalanceOptions.test.ts +8 -0
- package/src/api/getBlock/assertBlockHeight.test.ts +28 -0
- package/src/api/getBlock/assertBlockHeight.ts +10 -0
- package/src/api/impl.ts +22 -1
- package/src/api/types.ts +97 -3
- package/src/api/withDefaults.test.ts +124 -1
- package/src/api/withDefaults.ts +65 -3
- package/src/currencies/formatCurrencyUnit.test.ts +14 -0
- package/src/currencies/formatCurrencyUnit.ts +1 -1
- package/src/currencies/parseCurrencyUnit.test.ts +5 -0
- package/src/currencies/parseCurrencyUnit.ts +1 -1
- package/src/errors.test.ts +89 -0
- package/src/errors.ts +59 -1
- package/src/promises/promises.test.ts +1 -1
- package/src/promises/promises.ts +1 -1
- package/src/utils.test.ts +24 -1
- package/src/utils.ts +11 -0
- package/.oxlintrc.json +0 -17
- package/jest-global-setup.js +0 -12
- package/jest.config.js +0 -32
- package/knip.json +0 -15
- package/tsconfig.build.json +0 -21
- package/tsconfig.json +0 -26
package/lib-es/errors.js
CHANGED
|
@@ -106,9 +106,72 @@ export class UnknownError extends Error {
|
|
|
106
106
|
}
|
|
107
107
|
export class BlockNotFoundError extends Error {
|
|
108
108
|
name = 'BlockNotFoundError';
|
|
109
|
-
|
|
109
|
+
statusCode = 404;
|
|
110
|
+
constructor(message, fields, options) {
|
|
110
111
|
super(message || 'BlockNotFoundError');
|
|
112
|
+
if (fields)
|
|
113
|
+
Object.assign(this, fields);
|
|
114
|
+
if (options?.cause !== undefined)
|
|
115
|
+
Object.assign(this, { cause: options.cause });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export class InvalidBlockHeightError extends Error {
|
|
119
|
+
name = 'InvalidBlockHeightError';
|
|
120
|
+
statusCode = 400;
|
|
121
|
+
constructor(message, fields, options) {
|
|
122
|
+
super(message || 'InvalidBlockHeightError');
|
|
123
|
+
if (fields)
|
|
124
|
+
Object.assign(this, fields);
|
|
125
|
+
if (options?.cause !== undefined)
|
|
126
|
+
Object.assign(this, { cause: options.cause });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export class RateLimitError extends Error {
|
|
130
|
+
name = 'RateLimitError';
|
|
131
|
+
statusCode = 429;
|
|
132
|
+
constructor(message, fields, options) {
|
|
133
|
+
super(message || 'Upstream rate limit exceeded (429), please retry later');
|
|
134
|
+
if (fields)
|
|
135
|
+
Object.assign(this, fields);
|
|
136
|
+
if (options?.cause !== undefined)
|
|
137
|
+
Object.assign(this, { cause: options.cause });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export class InvalidExplorerResponse extends Error {
|
|
141
|
+
name = 'InvalidExplorerResponse';
|
|
142
|
+
constructor(message, fields, options) {
|
|
143
|
+
super(message || 'InvalidExplorerResponse');
|
|
144
|
+
if (fields)
|
|
145
|
+
Object.assign(this, fields);
|
|
146
|
+
if (options?.cause !== undefined)
|
|
147
|
+
Object.assign(this, { cause: options.cause });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export class GetBlockInfoError extends Error {
|
|
151
|
+
name = 'GetBlockInfoError';
|
|
152
|
+
constructor(message, fields, options) {
|
|
153
|
+
super(message || 'GetBlockInfoError');
|
|
154
|
+
if (fields)
|
|
155
|
+
Object.assign(this, fields);
|
|
156
|
+
if (options?.cause !== undefined)
|
|
157
|
+
Object.assign(this, { cause: options.cause });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class GetBlockError extends Error {
|
|
161
|
+
name = 'GetBlockError';
|
|
162
|
+
constructor(message, fields, options) {
|
|
163
|
+
super(message || 'GetBlockError');
|
|
164
|
+
if (fields)
|
|
165
|
+
Object.assign(this, fields);
|
|
166
|
+
if (options?.cause !== undefined)
|
|
167
|
+
Object.assign(this, { cause: options.cause });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export function statusCodeOf(error) {
|
|
171
|
+
if (error instanceof Error && 'statusCode' in error && typeof error.statusCode === 'number') {
|
|
172
|
+
return error.statusCode;
|
|
111
173
|
}
|
|
174
|
+
return undefined;
|
|
112
175
|
}
|
|
113
176
|
export class UnexpectedGetBalanceError extends Error {
|
|
114
177
|
name = 'UnexpectedGetBalanceError';
|
package/lib-es/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAEtC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,GAAG,mBAAmB,CAAA;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,mBAAmB,CAAC,CAAA;IACvC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,IAAI,GAAG,uBAAuB,CAAA;IACvC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAA;IAC3C,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,GAAG,gBAAgB,CAAA;IAChC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO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,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QACvC,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;IACjF,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,GAAG,eAAe,CAAA;IAC/B,YAAY,OAAgB,EAAE,MAAgC,EAAE,OAA6B;QAC3F,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC,CAAA;QACjC,IAAI,MAAM;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QACvC,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;IACjF,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,KAAK,IAAI,YAAY,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5F,OAAO,KAAK,CAAC,UAAU,CAAA;IACzB,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACzC,IAAI,GAAG,2BAA2B,CAAA;IAC3C,KAAK,CAAS;IAEd,YAAY,OAAgB,EAAE,KAAe;QAC3C,KAAK,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAA;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -4,7 +4,7 @@ declare const defaults: {
|
|
|
4
4
|
interval: number;
|
|
5
5
|
intervalMultiplicator: number;
|
|
6
6
|
context: string;
|
|
7
|
-
retryCondition: (
|
|
7
|
+
retryCondition: (_error: unknown) => boolean;
|
|
8
8
|
};
|
|
9
9
|
export declare function retry<A>(f: () => Promise<A>, options?: Partial<typeof defaults>): Promise<A>;
|
|
10
10
|
export declare function promiseAllBatched<A, B>(batch: number, items: Array<A>, fn: (arg0: A, arg1: number) => Promise<B>): Promise<B[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/promises/promises.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAA0C,CAAA;AAEzF,QAAA,MAAM,QAAQ;;;;;
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/promises/promises.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAA0C,CAAA;AAEzF,QAAA,MAAM,QAAQ;;;;;6BAKa,OAAO;CACjC,CAAA;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsB5F;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAC1C,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GACxC,OAAO,CAAC,CAAC,EAAE,CAAC,CAuBd"}
|
|
@@ -7,7 +7,7 @@ const defaults = {
|
|
|
7
7
|
interval: 300,
|
|
8
8
|
intervalMultiplicator: 1.5,
|
|
9
9
|
context: '',
|
|
10
|
-
retryCondition: (
|
|
10
|
+
retryCondition: (_error) => true,
|
|
11
11
|
};
|
|
12
12
|
export function retry(f, options) {
|
|
13
13
|
const { maxRetry, interval, intervalMultiplicator, retryCondition } = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../../src/promises/promises.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AACtC,gDAAgD;AAEhD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAEzF,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,GAAG;IACb,qBAAqB,EAAE,GAAG;IAC1B,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../../src/promises/promises.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AACtC,gDAAgD;AAEhD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAEzF,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,GAAG;IACb,qBAAqB,EAAE,GAAG;IAC1B,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,CAAC,MAAe,EAAE,EAAE,CAAC,IAAI;CAC1C,CAAA;AAED,MAAM,UAAU,KAAK,CAAI,CAAmB,EAAE,OAAkC;IAC9E,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,EAAE,cAAc,EAAE,GAAG;QACpE,GAAG,QAAQ;QACX,GAAG,OAAO;KACX,CAAA;IAED,SAAS,GAAG,CAAC,YAAoB,EAAE,CAAS;QAC1C,MAAM,MAAM,GAAG,CAAC,EAAE,CAAA;QAElB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,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;SACrB,GAAG,CAAC,IAAI,CAAC,CACb,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/lib-es/utils.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare function fromBigNumberToBigInt(bigNumber: BigNumber | undefined):
|
|
|
4
4
|
export declare function fromBigNumberToBigInt(bigNumber: BigNumber | undefined, defaultValue: bigint): bigint;
|
|
5
5
|
export declare function isSendTransactionIntent(tx: TransactionIntent): tx is SendTransactionIntent;
|
|
6
6
|
export declare function isStakingTransactionIntent(tx: TransactionIntent): tx is StakingTransactionIntent;
|
|
7
|
+
export declare function isHttpTooManyRequests(error: unknown): boolean;
|
|
7
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib-es/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAC3F,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,YAAY,EAAE,MAAM,GACnB,MAAM,CAAA;AAWT,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,iBAAiB,GAAG,EAAE,IAAI,qBAAqB,CAE1F;AAED,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,iBAAiB,GAAG,EAAE,IAAI,wBAAwB,CAEhG"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAC3F,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,YAAY,EAAE,MAAM,GACnB,MAAM,CAAA;AAWT,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,iBAAiB,GAAG,EAAE,IAAI,qBAAqB,CAE1F;AAED,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,iBAAiB,GAAG,EAAE,IAAI,wBAAwB,CAEhG;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAS7D"}
|
package/lib-es/utils.js
CHANGED
|
@@ -13,4 +13,12 @@ export function isSendTransactionIntent(tx) {
|
|
|
13
13
|
export function isStakingTransactionIntent(tx) {
|
|
14
14
|
return tx.intentType === 'staking';
|
|
15
15
|
}
|
|
16
|
+
export function isHttpTooManyRequests(error) {
|
|
17
|
+
return (error instanceof Error &&
|
|
18
|
+
'response' in error &&
|
|
19
|
+
typeof error.response === 'object' &&
|
|
20
|
+
error.response !== null &&
|
|
21
|
+
'status' in error.response &&
|
|
22
|
+
error.response.status === 429);
|
|
23
|
+
}
|
|
16
24
|
//# sourceMappingURL=utils.js.map
|
package/lib-es/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,SAAS,MAAM,cAAc,CAAA;AAOpC,MAAM,UAAU,qBAAqB,CACnC,SAAgC,EAChC,YAAqB;IAErB,IAAI,SAAS,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,EAAqB;IAC3D,OAAO,EAAE,CAAC,UAAU,KAAK,aAAa,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,EAAqB;IAC9D,OAAO,EAAE,CAAC,UAAU,KAAK,SAAS,CAAA;AACpC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAGtC,OAAO,SAAS,MAAM,cAAc,CAAA;AAOpC,MAAM,UAAU,qBAAqB,CACnC,SAAgC,EAChC,YAAqB;IAErB,IAAI,SAAS,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,EAAqB;IAC3D,OAAO,EAAE,CAAC,UAAU,KAAK,aAAa,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,EAAqB;IAC9D,OAAO,EAAE,CAAC,UAAU,KAAK,SAAS,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,UAAU,IAAI,KAAK;QACnB,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;QAClC,KAAK,CAAC,QAAQ,KAAK,IAAI;QACvB,QAAQ,IAAI,KAAK,CAAC,QAAQ;QAC1B,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,CAC9B,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-module-framework",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "Ledger framework for Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -9,15 +9,21 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/LedgerHQ/
|
|
12
|
+
"url": "https://github.com/LedgerHQ/coin-modules.git"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/LedgerHQ/
|
|
15
|
+
"url": "https://github.com/LedgerHQ/coin-modules/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/LedgerHQ/
|
|
17
|
+
"homepage": "https://github.com/LedgerHQ/coin-modules/tree/main/libs/coin-module-framework",
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
+
"files": [
|
|
22
|
+
"lib",
|
|
23
|
+
"lib-es",
|
|
24
|
+
"src",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
21
27
|
"typesVersions": {
|
|
22
28
|
"*": {
|
|
23
29
|
"lib/*": [
|
|
@@ -81,8 +87,8 @@
|
|
|
81
87
|
"cross-env": "^7.0.3",
|
|
82
88
|
"jest": "30.2.0",
|
|
83
89
|
"jest-sonar": "0.2.16",
|
|
84
|
-
"oxfmt": "0.
|
|
85
|
-
"oxlint": "1.
|
|
90
|
+
"oxfmt": "0.75.0",
|
|
91
|
+
"oxlint": "1.90.0",
|
|
86
92
|
"@swc/jest": "0.2.39",
|
|
87
93
|
"@swc/core": "1.15.11"
|
|
88
94
|
},
|
|
@@ -13,6 +13,14 @@ describe('rejectBalanceOptions', () => {
|
|
|
13
13
|
expect(getBalance).not.toHaveBeenCalled()
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
+
it('should throw an exception when validator options are provided', async () => {
|
|
17
|
+
const getBalance = jest.fn().mockResolvedValueOnce([])
|
|
18
|
+
await expect(
|
|
19
|
+
rejectBalanceOptions(getBalance, { knownValidatorIds: ['pool.near'], listValidators: false })
|
|
20
|
+
).rejects.toThrow(InvalidParameterError)
|
|
21
|
+
expect(getBalance).not.toHaveBeenCalled()
|
|
22
|
+
})
|
|
23
|
+
|
|
16
24
|
it('should call getBalance when options is not provided', async () => {
|
|
17
25
|
const getBalance = jest.fn().mockResolvedValueOnce([])
|
|
18
26
|
await expect(rejectBalanceOptions(getBalance)).resolves.toEqual([])
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { InvalidBlockHeightError } from '../../errors'
|
|
5
|
+
import { assertBlockHeight } from './assertBlockHeight'
|
|
6
|
+
|
|
7
|
+
describe('assertBlockHeight', () => {
|
|
8
|
+
it.each([1, 935980197, Number.MAX_SAFE_INTEGER])('accepts %d', (height) => {
|
|
9
|
+
expect(() => assertBlockHeight(height)).not.toThrow()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it.each([0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY, Number.MAX_SAFE_INTEGER + 1])(
|
|
13
|
+
'rejects %d with an InvalidBlockHeightError carrying the height',
|
|
14
|
+
(height) => {
|
|
15
|
+
const error = (() => {
|
|
16
|
+
try {
|
|
17
|
+
assertBlockHeight(height)
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return e
|
|
20
|
+
}
|
|
21
|
+
})()
|
|
22
|
+
|
|
23
|
+
expect(error).toBeInstanceOf(InvalidBlockHeightError)
|
|
24
|
+
expect(error).toHaveProperty('height', height)
|
|
25
|
+
expect(error).toHaveProperty('message', `Invalid block height: ${height}`)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { InvalidBlockHeightError } from '../../errors'
|
|
5
|
+
|
|
6
|
+
export function assertBlockHeight(height: number): void {
|
|
7
|
+
if (!Number.isSafeInteger(height) || height <= 0) {
|
|
8
|
+
throw new InvalidBlockHeightError(`Invalid block height: ${height}`, { height })
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/api/impl.ts
CHANGED
|
@@ -86,6 +86,24 @@ export type ApiMethodKeysAreExhaustive = AssertNever<
|
|
|
86
86
|
Exclude<keyof CoinModuleApi<CurrencyConfig>, ApiMethodKey>
|
|
87
87
|
>
|
|
88
88
|
|
|
89
|
+
/** An opt-in read option: a field of the method's options that changes what it returns. */
|
|
90
|
+
export type ReadOption = 'feesAsset'
|
|
91
|
+
|
|
92
|
+
/** A method that takes a {@link ReadOption}. */
|
|
93
|
+
export type ReadOptionMethod = 'listOperations' | 'getBlock'
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The read options a module honours, per method.
|
|
97
|
+
*
|
|
98
|
+
* A read option changes the meaning of an existing output, and JavaScript ignores arguments a
|
|
99
|
+
* method does not read. A module must therefore declare each option it honours: `withDefaults`
|
|
100
|
+
* rejects an opted-in call to a method that does not declare it, instead of returning the
|
|
101
|
+
* legacy output.
|
|
102
|
+
*/
|
|
103
|
+
export type ReadOptionsDeclaration = {
|
|
104
|
+
readonly [M in ReadOptionMethod]?: readonly ReadOption[]
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
/**
|
|
90
108
|
* Authoring type for a coin-module implementation.
|
|
91
109
|
*
|
|
@@ -109,4 +127,7 @@ export type CoinModuleImpl<
|
|
|
109
127
|
MemoType extends Memo = MemoNotSupported,
|
|
110
128
|
TxDataType extends TxData = TxDataNotSupported,
|
|
111
129
|
> = Omit<CoinModuleApi<ConfigType, MemoType, TxDataType>, OptionalApiKey> &
|
|
112
|
-
Partial<Pick<CoinModuleApi<ConfigType, MemoType, TxDataType>, OptionalApiKey>>
|
|
130
|
+
Partial<Pick<CoinModuleApi<ConfigType, MemoType, TxDataType>, OptionalApiKey>> & {
|
|
131
|
+
/** The read options this module honours. See {@link ReadOptionsDeclaration}. */
|
|
132
|
+
readOptions?: ReadOptionsDeclaration
|
|
133
|
+
}
|
package/src/api/types.ts
CHANGED
|
@@ -84,10 +84,35 @@ export type Operation<MemoType extends Memo = MemoNotSupported> = {
|
|
|
84
84
|
* This can include things like status, error messages, swap info, etc.
|
|
85
85
|
*/
|
|
86
86
|
details?: Record<string, unknown>
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The transaction this operation belongs to.
|
|
90
|
+
*
|
|
91
|
+
* When the caller sets {@link ListOperationsOptions.feesAsset}, these rules apply:
|
|
92
|
+
*
|
|
93
|
+
* 1. When {@link tx.feesAsset} is absent, the fee is in the native coin.
|
|
94
|
+
* 2. A consumer debits {@link tx.fees} once, in {@link tx.feesAsset}, from {@link tx.feesPayer}. A failed transaction
|
|
95
|
+
* also pays.
|
|
96
|
+
* 3. Operations never include the fee movement, in any asset. When a chain emits the fee as token transfers, the
|
|
97
|
+
* module removes them.
|
|
98
|
+
* 4. When the fee is the only effect of a transaction on the account, the account gets one operation with
|
|
99
|
+
* {@link Operation.value} 0 that carries {@link tx.fees}, {@link tx.feesAsset} and {@link tx.feesPayer}.
|
|
100
|
+
* 5. {@link tx.fees} is the amount the chain debited, never a value converted from another unit.
|
|
101
|
+
*/
|
|
87
102
|
tx: {
|
|
88
103
|
hash: string // transaction hash
|
|
89
104
|
block: BlockInfo // block metadata, empty string for block hash if not available directly and no reorg possible
|
|
90
|
-
|
|
105
|
+
|
|
106
|
+
/** The network fees paid, in base units of {@link feesAsset}, or of the native coin when it is absent. */
|
|
107
|
+
fees: bigint
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The asset that paid {@link fees}. Absent means the native coin.
|
|
111
|
+
*
|
|
112
|
+
* Set only when the caller sets {@link ListOperationsOptions.feesAsset}.
|
|
113
|
+
*/
|
|
114
|
+
feesAsset?: AssetInfo
|
|
115
|
+
|
|
91
116
|
// address that paid for this transaction's fees.
|
|
92
117
|
// optional as it may be unknown (e.g. the information is not available in the context of the operation).
|
|
93
118
|
// if it is unknown, it's expected that none of the sender addresses paid for the fees
|
|
@@ -130,6 +155,17 @@ export type Block = {
|
|
|
130
155
|
|
|
131
156
|
/**
|
|
132
157
|
* A transaction belonging to a {@link Block}, not specific to a particular account/address.
|
|
158
|
+
*
|
|
159
|
+
* When the caller sets {@link GetBlockOptions.feesAsset}, these rules apply:
|
|
160
|
+
*
|
|
161
|
+
* 1. When {@link feesAsset} is absent, the fee is in the native coin.
|
|
162
|
+
* 2. A consumer debits {@link fees} once, in {@link feesAsset}, from {@link feesPayer}. A failed transaction also
|
|
163
|
+
* pays.
|
|
164
|
+
* 3. {@link operations} never include the fee movement, in any asset. When a chain emits the fee as token transfers,
|
|
165
|
+
* the module removes them.
|
|
166
|
+
* 4. A transaction whose only effect is its fee is still included, with its fee fields. Its {@link operations} can be
|
|
167
|
+
* empty.
|
|
168
|
+
* 5. {@link fees} is the amount the chain debited, never a value converted from another unit.
|
|
133
169
|
*/
|
|
134
170
|
export type BlockTransaction = {
|
|
135
171
|
/** The transaction hash/digest (globally unique identifier). */
|
|
@@ -156,9 +192,19 @@ export type BlockTransaction = {
|
|
|
156
192
|
/** Network specific details for this transaction. */
|
|
157
193
|
details?: Record<string, unknown>
|
|
158
194
|
|
|
159
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The fee amount paid for this transaction, in base units of {@link feesAsset}, or of the native coin when it is
|
|
197
|
+
* absent. Always positive or zero.
|
|
198
|
+
*/
|
|
160
199
|
fees: bigint
|
|
161
200
|
|
|
201
|
+
/**
|
|
202
|
+
* The asset that paid {@link fees}. Absent means the native coin.
|
|
203
|
+
*
|
|
204
|
+
* Set only when the caller sets {@link GetBlockOptions.feesAsset}.
|
|
205
|
+
*/
|
|
206
|
+
feesAsset?: AssetInfo
|
|
207
|
+
|
|
162
208
|
/** The address that paid for this transaction's fees. */
|
|
163
209
|
feesPayer?: string
|
|
164
210
|
}
|
|
@@ -517,6 +563,26 @@ export type ListOperationsOptions = {
|
|
|
517
563
|
* Implementation must raise a "not supported" error if order is set and not supported.
|
|
518
564
|
*/
|
|
519
565
|
order?: 'asc' | 'desc'
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Report the asset that paid each fee, as `feesAsset` in {@link Operation.tx}, under the rules stated there.
|
|
569
|
+
*
|
|
570
|
+
* When it is not set, the output is the legacy one: `fees` is read as native. A module that honours this option
|
|
571
|
+
* declares it in `CoinModuleImpl.readOptions`; otherwise `withDefaults` rejects the call.
|
|
572
|
+
*/
|
|
573
|
+
feesAsset?: boolean
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Options for {@link CoinModuleApi#getBlock}. */
|
|
577
|
+
export type GetBlockOptions = {
|
|
578
|
+
/**
|
|
579
|
+
* Report the asset that paid each fee in {@link BlockTransaction.feesAsset}, under the rules on
|
|
580
|
+
* {@link BlockTransaction}.
|
|
581
|
+
*
|
|
582
|
+
* When it is not set, the output is the legacy one: `fees` is read as native. A module that honours this option
|
|
583
|
+
* declares it in `CoinModuleImpl.readOptions`; otherwise `withDefaults` rejects the call.
|
|
584
|
+
*/
|
|
585
|
+
feesAsset?: boolean
|
|
520
586
|
}
|
|
521
587
|
|
|
522
588
|
/** A network validator */
|
|
@@ -601,6 +667,29 @@ export type BalanceOptions = {
|
|
|
601
667
|
* `knownAssets` is empty.
|
|
602
668
|
*/
|
|
603
669
|
scanAssetsMinHeight?: number
|
|
670
|
+
|
|
671
|
+
// Hints: coin module may respect these requirements or ignore it.
|
|
672
|
+
// A module that ignores them behaves as without them: it lists the validators, and fails when the
|
|
673
|
+
// listing fails.
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Validators the caller knows for this account (the validators of the positions it stored),
|
|
677
|
+
* read unconditionally on top of those the delegation listing returns.
|
|
678
|
+
*
|
|
679
|
+
* Nothing is stored module-side: the caller keeps this list and passes it back on every call.
|
|
680
|
+
* When the listing fails, positions are returned for these validators alone, none when the list
|
|
681
|
+
* is empty. Absent means the caller knows nothing: a listing failure fails the call.
|
|
682
|
+
*/
|
|
683
|
+
knownValidatorIds?: string[] | undefined
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Whether to call the delegation listing. Absent means `true`.
|
|
687
|
+
*
|
|
688
|
+
* `false` returns positions for {@link knownValidatorIds} alone, without calling the listing.
|
|
689
|
+
* A caller passes it only when it knows no position can have been added since its list was
|
|
690
|
+
* built. Ignored when {@link knownValidatorIds} is absent.
|
|
691
|
+
*/
|
|
692
|
+
listValidators?: boolean | undefined
|
|
604
693
|
}
|
|
605
694
|
|
|
606
695
|
export type StakesOptions = {
|
|
@@ -668,10 +757,15 @@ export type CoinModuleApi<
|
|
|
668
757
|
*
|
|
669
758
|
* @param context the {@link Context} carrying the coin config accessor and logger
|
|
670
759
|
* @param height the block height to query
|
|
760
|
+
* @param options see {@link GetBlockOptions}
|
|
671
761
|
* @returns the complete block with transactions
|
|
672
762
|
* @throws "not supported" if the blockchain does not support querying full blocks
|
|
673
763
|
*/
|
|
674
|
-
getBlock: (
|
|
764
|
+
getBlock: (
|
|
765
|
+
context: Context<ConfigType>,
|
|
766
|
+
height: number,
|
|
767
|
+
options?: GetBlockOptions
|
|
768
|
+
) => Promise<Block>
|
|
675
769
|
|
|
676
770
|
/**
|
|
677
771
|
* Perform a direct, read-only smart-contract call against the underlying node or indexer.
|
|
@@ -5,13 +5,18 @@ import type { CurrencyConfig, Context } from '../config'
|
|
|
5
5
|
import type { CoinModuleImpl } from './impl'
|
|
6
6
|
import type {
|
|
7
7
|
Balance,
|
|
8
|
+
Block,
|
|
8
9
|
BlockInfo,
|
|
9
10
|
CraftedTransaction,
|
|
10
11
|
FeeEstimation,
|
|
12
|
+
GetBlockOptions,
|
|
11
13
|
ListOperationsOptions,
|
|
14
|
+
Operation,
|
|
15
|
+
Page,
|
|
12
16
|
TransactionIntent,
|
|
13
17
|
} from './types'
|
|
14
|
-
import {
|
|
18
|
+
import { InvalidParameterError } from '../errors'
|
|
19
|
+
import { isNotSupportedStub, notSupported } from './notSupported'
|
|
15
20
|
import { withDefaults } from './withDefaults'
|
|
16
21
|
|
|
17
22
|
const stubIntent: TransactionIntent = {
|
|
@@ -187,4 +192,122 @@ describe('withDefaults', () => {
|
|
|
187
192
|
expect(() => api.getStakes(ctx, 'addr')).toThrow('getStakes is not supported')
|
|
188
193
|
})
|
|
189
194
|
})
|
|
195
|
+
|
|
196
|
+
describe('read options', () => {
|
|
197
|
+
const block: Block = { info: { height: 1, hash: 'h', time: new Date(0) }, transactions: [] }
|
|
198
|
+
const page: Page<Operation> = { items: [] }
|
|
199
|
+
const listOperations = jest.fn((_ctx: Ctx, _addr: string, _opts: ListOperationsOptions) =>
|
|
200
|
+
Promise.resolve(page)
|
|
201
|
+
)
|
|
202
|
+
const getBlock = jest.fn((_ctx: Ctx, _height: number, _opts?: GetBlockOptions) =>
|
|
203
|
+
Promise.resolve(block)
|
|
204
|
+
)
|
|
205
|
+
const withBlock: CoinModuleImpl<Cfg> = { ...minimalModule, listOperations, getBlock }
|
|
206
|
+
|
|
207
|
+
beforeEach(() => {
|
|
208
|
+
listOperations.mockClear()
|
|
209
|
+
getBlock.mockClear()
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('passes declared methods through untouched', async () => {
|
|
213
|
+
const api = withDefaults({
|
|
214
|
+
...withBlock,
|
|
215
|
+
readOptions: { listOperations: ['feesAsset'], getBlock: ['feesAsset'] },
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
expect(api.listOperations).toBe(listOperations)
|
|
219
|
+
expect(api.getBlock).toBe(getBlock)
|
|
220
|
+
expect(api.supportsReadOption('listOperations', 'feesAsset')).toBe(true)
|
|
221
|
+
expect(api.supportsReadOption('getBlock', 'feesAsset')).toBe(true)
|
|
222
|
+
await expect(api.getBlock(ctx, 1, { feesAsset: true })).resolves.toBe(block)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('rejects an opted-in call to a method that does not declare the option', async () => {
|
|
226
|
+
const api = withDefaults(withBlock)
|
|
227
|
+
|
|
228
|
+
expect(api.supportsReadOption('listOperations', 'feesAsset')).toBe(false)
|
|
229
|
+
expect(api.supportsReadOption('getBlock', 'feesAsset')).toBe(false)
|
|
230
|
+
await expect(
|
|
231
|
+
api.listOperations(ctx, 'addr', { minHeight: 0, feesAsset: true })
|
|
232
|
+
).rejects.toThrow(
|
|
233
|
+
new InvalidParameterError('listOperations does not support the feesAsset option')
|
|
234
|
+
)
|
|
235
|
+
await expect(api.getBlock(ctx, 1, { feesAsset: true })).rejects.toThrow(
|
|
236
|
+
new InvalidParameterError('getBlock does not support the feesAsset option')
|
|
237
|
+
)
|
|
238
|
+
expect(listOperations).not.toHaveBeenCalled()
|
|
239
|
+
expect(getBlock).not.toHaveBeenCalled()
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it('calls through unchanged when the option is not set', async () => {
|
|
243
|
+
const api = withDefaults(withBlock)
|
|
244
|
+
const options: ListOperationsOptions = { minHeight: 0, feesAsset: false }
|
|
245
|
+
|
|
246
|
+
await expect(api.listOperations(ctx, 'addr', options)).resolves.toBe(page)
|
|
247
|
+
await expect(api.getBlock(ctx, 1)).resolves.toBe(block)
|
|
248
|
+
await expect(api.getBlock(ctx, 2, {})).resolves.toBe(block)
|
|
249
|
+
expect(listOperations).toHaveBeenCalledWith(ctx, 'addr', options)
|
|
250
|
+
expect(getBlock.mock.calls).toEqual([
|
|
251
|
+
[ctx, 1],
|
|
252
|
+
[ctx, 2, {}],
|
|
253
|
+
])
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it('keeps the receiver of a guarded method', async () => {
|
|
257
|
+
const impl = {
|
|
258
|
+
...minimalModule,
|
|
259
|
+
page,
|
|
260
|
+
listOperations(
|
|
261
|
+
this: { page: Page<Operation> },
|
|
262
|
+
_ctx: Ctx,
|
|
263
|
+
_addr: string,
|
|
264
|
+
_opts: ListOperationsOptions
|
|
265
|
+
) {
|
|
266
|
+
return Promise.resolve(this.page)
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
const api = withDefaults(impl)
|
|
270
|
+
|
|
271
|
+
await expect(api.listOperations(ctx, 'addr', { minHeight: 0 })).resolves.toBe(page)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('guards each method on its own declaration', async () => {
|
|
275
|
+
const api = withDefaults({ ...withBlock, readOptions: { getBlock: ['feesAsset'] } })
|
|
276
|
+
|
|
277
|
+
expect(api.supportsReadOption('getBlock', 'feesAsset')).toBe(true)
|
|
278
|
+
expect(api.supportsReadOption('listOperations', 'feesAsset')).toBe(false)
|
|
279
|
+
await expect(api.getBlock(ctx, 1, { feesAsset: true })).resolves.toBe(block)
|
|
280
|
+
await expect(
|
|
281
|
+
api.listOperations(ctx, 'addr', { minHeight: 0, feesAsset: true })
|
|
282
|
+
).rejects.toThrow(InvalidParameterError)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
it('keeps a listOperations stub tagged', () => {
|
|
286
|
+
const api = withDefaults({
|
|
287
|
+
...minimalModule,
|
|
288
|
+
listOperations: notSupported('listOperations'),
|
|
289
|
+
readOptions: { listOperations: ['feesAsset'] },
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
expect(isNotSupportedStub(api.listOperations)).toBe(true)
|
|
293
|
+
expect(api.supportsReadOption('listOperations', 'feesAsset')).toBe(false)
|
|
294
|
+
expect(() => api.listOperations(ctx, 'addr', { minHeight: 0, feesAsset: true })).toThrow(
|
|
295
|
+
'listOperations is not supported'
|
|
296
|
+
)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it('keeps the getBlock fallback stub when getBlock is not implemented', () => {
|
|
300
|
+
const api = withDefaults({ ...minimalModule, readOptions: { getBlock: ['feesAsset'] } })
|
|
301
|
+
const rewrapped = withDefaults(api)
|
|
302
|
+
|
|
303
|
+
for (const resolved of [api, rewrapped]) {
|
|
304
|
+
expect(isNotSupportedStub(resolved.getBlock)).toBe(true)
|
|
305
|
+
expect(resolved.supports('getBlock')).toBe(false)
|
|
306
|
+
expect(resolved.supportsReadOption('getBlock', 'feesAsset')).toBe(false)
|
|
307
|
+
expect(() => resolved.getBlock(ctx, 1, { feesAsset: true })).toThrow(
|
|
308
|
+
'getBlock is not supported'
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
})
|
|
190
313
|
})
|