fix unkown rpc (#5325)

* fix unkown rpc

* fix
This commit is contained in:
Xiliang Chen
2022-11-10 07:32:23 +02:00
committed by GitHub
parent 5c81e4fd3b
commit 521fa2026d
3 changed files with 15 additions and 3 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ import { memo, RpcCore } from '@polkadot/rpc-core';
import { WsProvider } from '@polkadot/rpc-provider';
import { expandMetadata, GenericExtrinsic, Metadata, typeDefinitions, TypeRegistry } from '@polkadot/types';
import { getSpecRuntime } from '@polkadot/types-known';
import { arrayChunk, arrayFlatten, assertReturn, BN, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, stringCamelCase, stringify, stringUpperFirst, u8aConcatStrict, u8aToHex } from '@polkadot/util';
import { arrayChunk, arrayFlatten, assertReturn, BN, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, stringCamelCase, stringUpperFirst, u8aConcatStrict, u8aToHex } from '@polkadot/util';
import { blake2AsHex } from '@polkadot/util-crypto';
import { createSubmittable } from '../submittable';
@@ -413,7 +413,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
private _rpcSubmitter<ApiType extends ApiTypes> (decorateMethod: DecorateMethod<ApiType>): DecoratedRpc<ApiType, RpcInterface> {
const method = (method: string, ...params: any[]) => {
return from(this._rpcCore.provider.send<AnyJson>(method, params.map((p) => stringify(p))));
return from(this._rpcCore.provider.send<AnyJson>(method, params));
};
return decorateMethod(method) as DecoratedRpc<ApiType, RpcInterface>;
+10
View File
@@ -155,4 +155,14 @@ describe('ApiPromise', (): void => {
await api.disconnect();
});
});
describe('api.rpc(...)', (): void => {
it('allows sending rpc call', async (): Promise<void> => {
const { api } = await createTransfer();
expect(await api.rpc('dev_echo', 'hello', 'world')).toEqual(['hello', 'world']);
await api.disconnect();
});
});
});
+3 -1
View File
@@ -72,7 +72,9 @@ export class MockProvider implements ProviderInterface {
system_name: () => 'mockClient',
system_properties: () => ({ ss58Format: 42 }),
system_upgradedToTripleRefCount: () => this.registry.createType('bool', true),
system_version: () => '9.8.7'
system_version: () => '9.8.7',
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, sort-keys
dev_echo: (_, params: any) => params
};
public subscriptions: MockStateSubscriptions = SUBSCRIPTIONS.reduce((subs, name): MockStateSubscriptions => {