Remove extra_* namespace (#65)
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
// Copyright 2017-2018 Jaco Greeff
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { InterfaceMethodDefinition } from '../types';
|
||||
|
||||
/**
|
||||
@name getBlockNumber
|
||||
@signature extra_getBlockNumber (): BlockNumber
|
||||
@summary Retrieves the best blockNumber
|
||||
@description
|
||||
Returns the best blockNumber available on the client
|
||||
*/
|
||||
module.exports = ({
|
||||
isSubscription: true,
|
||||
inputs: [],
|
||||
output: { type: 'BlockNumber' }
|
||||
}: InterfaceMethodDefinition);
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2017-2018 Jaco Greeff
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { InterfaceMethodDefinition } from '../types';
|
||||
|
||||
/**
|
||||
@name getClientTime
|
||||
@signature extra_getClientTime (): U64
|
||||
@summary Retrieves the current time
|
||||
@description
|
||||
Returns the current time on the running node
|
||||
*/
|
||||
module.exports = ({
|
||||
isSubscription: true,
|
||||
inputs: [],
|
||||
output: { type: 'U64' }
|
||||
}: InterfaceMethodDefinition);
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2017-2018 Jaco Greeff
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { InterfaceDefinition } from '../types';
|
||||
|
||||
const getBlockNumber = require('./getBlockNumber');
|
||||
const getClientTime = require('./getClientTime');
|
||||
|
||||
/**
|
||||
@summary Extended methods not available in all clients.
|
||||
*/
|
||||
module.exports = ({
|
||||
methods: {
|
||||
getBlockNumber,
|
||||
getClientTime
|
||||
}
|
||||
}: InterfaceDefinition);
|
||||
@@ -7,7 +7,6 @@ import type { InterfaceDefinitions } from './types';
|
||||
|
||||
const author = require('./author');
|
||||
const chain = require('./chain');
|
||||
const extra = require('./extra');
|
||||
const state = require('./state');
|
||||
|
||||
/**
|
||||
@@ -16,6 +15,5 @@ const state = require('./state');
|
||||
module.exports = ({
|
||||
author,
|
||||
chain,
|
||||
extra,
|
||||
state
|
||||
}: InterfaceDefinitions);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
export type InterfaceTypes = 'author' | 'chain' | 'extra' | 'state';
|
||||
export type InterfaceTypes = 'author' | 'chain' | 'state';
|
||||
|
||||
export type FormatInputType = 'Bytes' | 'H256' | 'HeaderHash' | 'String';
|
||||
|
||||
|
||||
@@ -45,11 +45,6 @@ module.exports = function mocks ({ subscriptions }: MockState): void {
|
||||
setInterval(() => {
|
||||
newHead = makeBlockHeader(newHead.number);
|
||||
|
||||
updateSubs('extra_getBlockNumber', `0x${(newHead.number).toString(16)}`);
|
||||
updateSubs('chain_newHead', newHead);
|
||||
updateSubs('subscribe_newHead', newHead);
|
||||
}, 5000);
|
||||
|
||||
setInterval(() => {
|
||||
updateSubs('extra_getClientTime', `0x${Date.now().toString(16)}`);
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ const METHODS = Array.prototype.concat.apply(
|
||||
return Object
|
||||
.keys(interfaces[section].methods)
|
||||
.filter((method) => interfaces[section].methods[method].isSubscription)
|
||||
.map((method) => `${section}_${method}`);
|
||||
.map((method) => `subscribe_${method}`);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('state', () => {
|
||||
expect(
|
||||
state.subscriptions
|
||||
).toMatchObject({
|
||||
'extra_getBlockNumber': {
|
||||
'subscribe_newHead': {
|
||||
callbacks: {},
|
||||
lastValue: null
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('subscribe', () => {
|
||||
});
|
||||
|
||||
it('returns a subscription id', () => {
|
||||
return subscribe(state, 'extra_getBlockNumber', [() => void 0]).then((id) => {
|
||||
return subscribe(state, 'subscribe_newHead', [() => void 0]).then((id) => {
|
||||
expect(id).toEqual(state.subscriptionId);
|
||||
});
|
||||
});
|
||||
@@ -27,16 +27,16 @@ describe('subscribe', () => {
|
||||
it('stores the mapping values', () => {
|
||||
const cb = () => void 0;
|
||||
|
||||
return subscribe(state, 'extra_getBlockNumber', [cb]).then((id) => {
|
||||
expect(state.subscriptionMap[id]).toEqual('extra_getBlockNumber');
|
||||
expect(state.subscriptions['extra_getBlockNumber'].callbacks[id]).toEqual(cb);
|
||||
return subscribe(state, 'subscribe_newHead', [cb]).then((id) => {
|
||||
expect(state.subscriptionMap[id]).toEqual('subscribe_newHead');
|
||||
expect(state.subscriptions['subscribe_newHead'].callbacks[id]).toEqual(cb);
|
||||
});
|
||||
});
|
||||
|
||||
it('calls back with the last known value', (done) => {
|
||||
state.subscriptions['extra_getBlockNumber'].lastValue = 'testValue';
|
||||
state.subscriptions['subscribe_newHead'].lastValue = 'testValue';
|
||||
|
||||
subscribe(state, 'extra_getBlockNumber', [(_, value) => {
|
||||
subscribe(state, 'subscribe_newHead', [(_, value) => {
|
||||
expect(value).toEqual('testValue');
|
||||
done();
|
||||
}]);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { MockState } from './types';
|
||||
|
||||
module.exports = async function subscribe (self: MockState, _: string, id: number): Promise<boolean> {
|
||||
module.exports = async function unsubscribe (self: MockState, _: string, id: number): Promise<boolean> {
|
||||
const method = self.subscriptionMap[id];
|
||||
|
||||
self.l.debug(() => ['unsubscribe', id, method]);
|
||||
|
||||
@@ -13,23 +13,23 @@ describe('unsubscribe', () => {
|
||||
beforeEach(() => {
|
||||
state = createState();
|
||||
|
||||
return subscribe(state, 'extra_getBlockNumber', [() => void 0]).then((_id) => {
|
||||
return subscribe(state, 'subscribe_newHead', [() => void 0]).then((_id) => {
|
||||
id = _id;
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on unknown ids', () => {
|
||||
return unsubscribe(state, 'extra_getBlockNumber', 5).catch((error) => {
|
||||
return unsubscribe(state, 'subscribe_newHead', 5).catch((error) => {
|
||||
expect(error.message).toMatch(/Unable to find/);
|
||||
});
|
||||
});
|
||||
|
||||
it('unsubscribes successfully', () => {
|
||||
return unsubscribe(state, 'extra_getBlockNumber', id);
|
||||
return unsubscribe(state, 'subscribe_newHead', id);
|
||||
});
|
||||
|
||||
it('fails on double unsubscribe', () => {
|
||||
return unsubscribe(state, 'extra_getBlockNumber', id)
|
||||
return unsubscribe(state, 'subscribe_newHead', id)
|
||||
.then(() => unsubscribe(state, id))
|
||||
.catch((error) => {
|
||||
expect(error.message).toMatch(/Unable to find/);
|
||||
@@ -37,9 +37,9 @@ describe('unsubscribe', () => {
|
||||
});
|
||||
|
||||
it('clears the subscriptions', () => {
|
||||
return unsubscribe(state, 'extra_getBlockNumber', id).then(() => {
|
||||
return unsubscribe(state, 'subscribe_newHead', id).then(() => {
|
||||
expect(state.subscriptionMap[id]).not.toBeDefined();
|
||||
expect(state.subscriptions['extra_getBlockNumber'].callbacks[id]).not.toBeDefined();
|
||||
expect(state.subscriptions['subscribe_newHead'].callbacks[id]).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user