Fix derive not returning (needsSubscription issues) (#658)

Fix derive not subscribing (needsSubscription issues)
This commit is contained in:
Jaco Greeff
2019-01-31 20:46:56 +01:00
committed by GitHub
parent 76673a4d25
commit ea7ecec7a3
11 changed files with 35 additions and 12 deletions
+13 -1
View File
@@ -480,7 +480,19 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
const sectionName = _sectionName as keyof DeriveInterface;
result[sectionName] = Object.keys(derive[sectionName]).reduce((section, methodName) => {
const method = (...params: any[]) => onCall((derive[sectionName] as any)[methodName], params);
// FIXME The callback extraction we do way too much - de-dupe
const method = (...args: Array<any>) => {
let callback: CodecCallback | undefined;
let params = args;
if (args.length && isFunction(args[args.length - 1])) {
callback = args[args.length - 1];
params = args.slice(0, args.length - 1);
}
return onCall((derive[sectionName] as any)[methodName], params, callback, !!callback);
};
section[methodName] = method;
return section;
+12 -1
View File
@@ -13,7 +13,10 @@ describe.skip('e2e queries', () => {
let api;
beforeEach(async (done) => {
api = await Api.create();
if (!api) {
api = await Api.create();
}
jest.setTimeout(30000);
done();
});
@@ -44,6 +47,14 @@ describe.skip('e2e queries', () => {
});
});
it('subscribes to derive', (done) => {
api.derive.chain.subscribeNewHead((header) => {
expect(header.blockNumber.isZero()).toBe(false);
done();
});
});
it('subscribes to queries', (done) => {
api.query.system.accountNonce(keyring.ferdie.address(), (nonce) => {
expect(nonce instanceof BN).toBe(true);