First stage renames, rpc-{core,provider,rx} (#220)
* Docs renames (& removal for re-gen) * Rename api, api-provider & api-rx * Apoi -> Rpc, RxApi -> RpcRx (classes) * Add .nodoc * Bump version * Link updates (summary) * Cleanup deleted (master version) * Deleted re-instated * More... ;) * Types... * Revert .nodoc
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Copyright 2017-2018 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import Ws from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Api from '../../src';
|
||||
|
||||
describe.skip('e2e basics', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.setTimeout(30000);
|
||||
api = new Api(new Ws('ws://127.0.0.1:9944'));
|
||||
});
|
||||
|
||||
it('retrieves the pending extrinsics', () => {
|
||||
return api.author
|
||||
.pendingExtrinsics()
|
||||
.then((extrinsics) => {
|
||||
console.error('extrinsics', extrinsics);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright 2017-2018 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import Ws from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Api from '../../src';
|
||||
|
||||
describe.skip('e2e chain', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.setTimeout(30000);
|
||||
api = new Api(new Ws('ws://127.0.0.1:9944'));
|
||||
});
|
||||
|
||||
it('subscribes to chain_newHead', (done) => {
|
||||
let count = 0;
|
||||
|
||||
// tslint:disable-next-line
|
||||
api.chain
|
||||
.newHead((error, data) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
}
|
||||
|
||||
expect(data).toBeDefined();
|
||||
|
||||
if (++count === 3) {
|
||||
done();
|
||||
}
|
||||
})
|
||||
.then((subscriptionId) => {
|
||||
console.log('newHead: subscriptionId =', subscriptionId);
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves the runtime version', () => {
|
||||
return api.chain
|
||||
.getRuntimeVersion()
|
||||
.then((version) => {
|
||||
console.error('version', version);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017-2018 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import storage from '@polkadot/storage';
|
||||
import Ws from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Api from '../../src';
|
||||
|
||||
describe.skip('e2e krumme lanke', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.setTimeout(30000);
|
||||
api = new Api(new Ws('ws://127.0.0.1:9944'));
|
||||
});
|
||||
|
||||
it('subscribes to storage', (done) => {
|
||||
api.state
|
||||
.subscribeStorage(
|
||||
[
|
||||
[storage.system.accountNonce, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
|
||||
[storage.balances.freeBalance, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
|
||||
],
|
||||
(error, data) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
}
|
||||
|
||||
expect(data).toHaveLength(2);
|
||||
expect(data[0].toNumber()).toEqual(0);
|
||||
expect(data[1].toNumber()).not.toEqual(0);
|
||||
|
||||
done();
|
||||
}
|
||||
)
|
||||
.then((subscriptionId) => {
|
||||
console.log('newHead: subscriptionId =', subscriptionId);
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves a block by hash (krumme lanke #1)', () => {
|
||||
return api.chain
|
||||
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
|
||||
.then((block) => {
|
||||
expect(block).toBeDefined();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves a block by hash (krumme lanke #2)', () => {
|
||||
return api.chain
|
||||
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
|
||||
.then((block) => {
|
||||
expect(block).toBeDefined();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2017-2018 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import Ws from '@polkadot/rpc-provider/ws';
|
||||
import storage from '@polkadot/storage/static';
|
||||
|
||||
import Api from '../../src';
|
||||
|
||||
const ALICE = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
|
||||
|
||||
describe.skip('e2e state', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.setTimeout(30000);
|
||||
api = new Api(new Ws('ws://127.0.0.1:9944'));
|
||||
});
|
||||
|
||||
it('retrieves code', () => {
|
||||
return api.state
|
||||
.getStorage([
|
||||
storage.substrate.code
|
||||
])
|
||||
.then((code) => {
|
||||
console.error(code.toHex().substr(0, 256), '...');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves the wasm metadata', () => {
|
||||
return api.state
|
||||
.getMetadata()
|
||||
.then((meta) => {
|
||||
console.error(JSON.stringify(meta.toJSON()));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves balances', () => {
|
||||
return api.state
|
||||
.getStorage([
|
||||
storage.balances.freeBalance, ALICE
|
||||
])
|
||||
.then((balance) => {
|
||||
console.error(balance);
|
||||
|
||||
expect(balance.toBn().isZero()).not.toEqual(true);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves timestamp', () => {
|
||||
return api.state
|
||||
.getStorage([
|
||||
storage.timestamp.now
|
||||
])
|
||||
.then((moment) => {
|
||||
console.error(moment);
|
||||
|
||||
expect(moment.toNumber()).not.toEqual(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2017-2018 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import Ws from '@polkadot/rpc-provider/ws';
|
||||
import storage from '@polkadot/storage/static';
|
||||
|
||||
import Api from '../../src';
|
||||
|
||||
describe.skip('e2e subscriptions', () => {
|
||||
let api;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.setTimeout(30000);
|
||||
api = new Api(new Ws('ws://127.0.0.1:9944'));
|
||||
});
|
||||
|
||||
it('retrieves current timestamp', (done) => {
|
||||
let count = 0;
|
||||
|
||||
return api.state
|
||||
.storage([[storage.timestamp.now]], (error, data) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
}
|
||||
|
||||
expect(data).toBeDefined();
|
||||
|
||||
if (++count === 3) {
|
||||
done();
|
||||
}
|
||||
})
|
||||
.then((subscriptionId) => {
|
||||
console.log('newHead: subscriptionId =', subscriptionId);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import nock from 'nock';
|
||||
|
||||
const TEST_HTTP_URL = 'http://localhost:9944';
|
||||
|
||||
function mockHttp (requests: any[]) {
|
||||
nock.cleanAll();
|
||||
|
||||
return requests.reduce((scope, request: any, index: number) => {
|
||||
return scope
|
||||
.post('/')
|
||||
.reply(request.code || 200, (uri: string, body: { id: string }) => {
|
||||
scope.body = scope.body || {};
|
||||
scope.body[request.method] = body;
|
||||
|
||||
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
|
||||
});
|
||||
}, nock(TEST_HTTP_URL));
|
||||
}
|
||||
|
||||
export {
|
||||
TEST_HTTP_URL,
|
||||
mockHttp
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Server } from 'mock-socket';
|
||||
|
||||
const TEST_WS_URL = 'ws://localhost:9955';
|
||||
|
||||
let server: Server;
|
||||
|
||||
type ErrorDef = {
|
||||
id: number,
|
||||
error: {
|
||||
code: number,
|
||||
message: string
|
||||
}
|
||||
};
|
||||
|
||||
type ReplyDef = {
|
||||
id: number,
|
||||
reply: {
|
||||
result: any
|
||||
}
|
||||
};
|
||||
|
||||
function createError ({ id, error: { code, message } }: ErrorDef) {
|
||||
return {
|
||||
id,
|
||||
jsonrpc: '2.0',
|
||||
error: {
|
||||
code,
|
||||
message
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createReply ({ id, reply: { result } }: ReplyDef) {
|
||||
return {
|
||||
id,
|
||||
jsonrpc: '2.0',
|
||||
result
|
||||
};
|
||||
}
|
||||
|
||||
function mockWs (requests: Array<{ method: string }>) {
|
||||
server = new Server(TEST_WS_URL);
|
||||
|
||||
let requestCount = 0;
|
||||
const scope: { body: { [index: string]: {} }, requests: number, server: Server, done: any } = {
|
||||
body: {},
|
||||
requests: 0,
|
||||
server,
|
||||
done: () =>
|
||||
server.stop(() => {
|
||||
// ignore
|
||||
})
|
||||
};
|
||||
|
||||
server.on('connection', (socket) => {
|
||||
// @ts-ignore definitions are wrong, this is 'on', not 'onmessage'
|
||||
socket.on('message', (body: {}) => {
|
||||
const request = requests[requestCount];
|
||||
// @ts-ignore Yes, SHOULD be fixed, this is a mess
|
||||
const response = request.error
|
||||
// @ts-ignore Yes, SHOULD be fixed, this is a mess
|
||||
? createError(request)
|
||||
// @ts-ignore Yes, SHOULD be fixed, this is a mess
|
||||
: createReply(request);
|
||||
|
||||
scope.body[request.method] = body;
|
||||
requestCount++;
|
||||
|
||||
socket.send(JSON.stringify(response));
|
||||
});
|
||||
});
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
export {
|
||||
TEST_WS_URL,
|
||||
mockWs
|
||||
};
|
||||
Reference in New Issue
Block a user