Ensure apiAt.<section>.<method>.key(...) passes through the correct arguments (#5283)

This commit is contained in:
Jaco
2022-10-21 10:23:54 +03:00
committed by GitHub
parent b66d62548a
commit be95356999
4 changed files with 12 additions and 10 deletions
+2
View File
@@ -6,6 +6,8 @@ Changes:
- Cater for latest Substrate `DispatchError` (additional preimage statuses)
- Adjust `api.derive.democracy.*` to return `imageHash` as `HexString` (as applicable, supports current-gen preimages)
- Ensure `apiAt.<section>.<method>.key(...)` passes through the correct arguments
- Apply fallback for Weight downgrades (V2 >> V1 detection)
- Update to latest Substrate metadata
- Polkadot 9291 & Westend 9300 upgrade blocks
+1 -5
View File
@@ -791,11 +791,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
key.method === creator.method;
decorated.key = (...args: unknown[]): string =>
u8aToHex(compactStripLength(creator(
creator.meta.type.isPlain
? undefined
: args
))[1]);
u8aToHex(compactStripLength(creator(...args))[1]);
decorated.keyPrefix = (...keys: unknown[]): string =>
u8aToHex(creator.keyPrefix(...keys));
@@ -46,6 +46,11 @@ export const NO_RAW_ARGS: RawArgs = {
keys: []
};
/** @internal */
function filterDefined (a: unknown): boolean {
return !isUndefined(a);
}
/** @internal */
function assertArgs ({ method, section }: CreateItemFn, { args, keys }: RawArgs): void {
if (!Array.isArray(args)) {
@@ -112,11 +117,6 @@ export function createKeyRaw (registry: Registry, itemFn: CreateItemBase, args:
);
}
/** @internal */
function filterDefined (a: unknown): boolean {
return !isUndefined(a);
}
/** @internal */
function createKey (registry: Registry, itemFn: CreateItemFn, args: RawArgs): Uint8Array {
assertArgs(itemFn, args);
@@ -36,6 +36,10 @@ describe('decorateStorage', (): void => {
expect(() => query.timestamp.now()).not.toThrow();
});
it('should return a value if the storage function has the correct arguments', (): void => {
expect(() => query.staking.erasStakers(1, keyring.alice.address)).not.toThrow();
});
it('should return the correct length-prefixed storage key', (): void => {
expect(
u8aToHex(query.system.account(keyring.alice.address))