rpc-core e2e tests in typescript (#956)

* WIP rpc-core e2e tests in Typescript

* WIP

* Subscribe_storage test

* Subscribe_storage test

* StorageChangeSet Index workaround

* name random account

* name random account

* rename from krumme-lanke to alexander, test for types

* ALICE doesn't exist on Alex -> change subscription to session.currentIndex

* removed unused import 'Balance'
This commit is contained in:
Stefanie Doll
2019-05-29 11:39:08 +02:00
committed by GitHub
parent 761682373d
commit 7e1d4cd2bd
5 changed files with 48 additions and 36 deletions
@@ -2,43 +2,50 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import storage from '@polkadot/storage';
import { BlockNumber, Index, SignedBlock, StorageChangeSet } from '@polkadot/types';
import storage from '@polkadot/storage/static';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '../../src';
describe.skip('e2e krumme lanke', () => {
let api;
const randomAccount = '5HTqyWJHAVUieZnpb1V8gK4T1E4mnhkrUVSSzWBQd6kYgsVJ';
describe.skip('e2e Alexander - Polkadot', () => {
let api: Rpc;
beforeEach(() => {
jest.setTimeout(30000);
api = new Rpc(new WsProvider('ws://127.0.0.1:9944'));
api = new Rpc(new WsProvider('wss://poc3-rpc.polkadot.io/'));
});
it('subscribes to storage', (done) => {
api.state
return (
api.state
.subscribeStorage(
[
[storage.system.accountNonce, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
[storage.balances.freeBalance, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
[storage.system.accountNonce, randomAccount],
[storage.session.currentIndex]
],
(data) => {
(data: StorageChangeSet) => {
expect(data).toHaveLength(2);
expect(data[0].toNumber()).toEqual(0);
expect(data[1].toNumber()).not.toEqual(0);
expect(data).toEqual(
expect.arrayContaining([
expect.any(BlockNumber),
expect.any(Index)
])
);
done();
}
)
.then((subscriptionId) => {
console.log('stoarge subscriptionId =', subscriptionId);
});
}).then((subscriptionId: number) => {
console.log('stoarge subscriptionId =', subscriptionId);
})
);
});
it('retrieves a block by hash (krumme lanke #1)', () => {
return api.chain
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
.then((block) => {
.then((block: SignedBlock) => {
expect(block).toBeDefined();
})
.catch((error) => {
@@ -51,7 +58,7 @@ describe.skip('e2e krumme lanke', () => {
it('retrieves a block by hash (krumme lanke #2)', () => {
return api.chain
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
.then((block) => {
.then((block: SignedBlock) => {
expect(block).toBeDefined();
})
.catch((error) => {
@@ -2,12 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ChainProperties, PendingExtrinsics } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '../../src';
describe.skip('e2e basics', () => {
let api;
let api: Rpc;
beforeEach(() => {
jest.setTimeout(30000);
@@ -17,8 +18,8 @@ describe.skip('e2e basics', () => {
it('retrieves the pending extrinsics', () => {
return api.author
.pendingExtrinsics()
.then((extrinsics) => {
console.error('extrinsics', extrinsics);
.then((extrinsics: PendingExtrinsics) => {
console.log('extrinsics', extrinsics);
})
.catch((error) => {
console.error(error);
@@ -30,8 +31,8 @@ describe.skip('e2e basics', () => {
it('retrieves the system properties', () => {
return api.system
.properties()
.then((properties) => {
console.error('properties', properties);
.then((properties: ChainProperties) => {
console.log('properties', properties);
})
.catch((error) => {
console.error(error);
@@ -2,12 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Header, RuntimeVersion } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '../../src';
describe.skip('e2e chain', () => {
let api;
let api: Rpc;
beforeEach(() => {
jest.setTimeout(30000);
@@ -15,18 +16,18 @@ describe.skip('e2e chain', () => {
});
it('subscribes via subscribeNewHead', (done) => {
let count = 0;
let count: number = 0;
// tslint:disable-next-line
api.chain
.subscribeNewHead((header) => {
.subscribeNewHead((header: Header) => {
expect(header).toBeDefined();
if (++count === 3) {
done();
}
})
.then((subscriptionId) => {
.then((subscriptionId: number) => {
console.log('newHead: subscriptionId =', subscriptionId);
});
});
@@ -34,7 +35,7 @@ describe.skip('e2e chain', () => {
it('retrieves the runtime version', () => {
return api.chain
.getRuntimeVersion()
.then((version) => {
.then((version: RuntimeVersion) => {
console.error('version', version);
})
.catch((error) => {
@@ -2,14 +2,16 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Bytes, Metadata, Moment } from '@polkadot/types';
import storage from '@polkadot/storage/static';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '../../src';
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
describe.skip('e2e state', () => {
let api;
let api: Rpc;
beforeEach(() => {
jest.setTimeout(30000);
@@ -21,7 +23,7 @@ describe.skip('e2e state', () => {
.getStorage([
storage.substrate.code
])
.then((code) => {
.then((code: Bytes) => {
console.error(code.toHex().substr(0, 256), '...');
})
.catch((error) => {
@@ -34,7 +36,7 @@ describe.skip('e2e state', () => {
it('retrieves the wasm metadata', () => {
return api.state
.getMetadata()
.then((meta) => {
.then((meta: Metadata) => {
console.error(JSON.stringify(meta.toJSON()));
})
.catch((error) => {
@@ -49,7 +51,7 @@ describe.skip('e2e state', () => {
.getStorage([
storage.balances.freeBalance, ALICE
])
.then((balance) => {
.then((balance: Balance) => {
console.error(balance);
expect(balance.isZero()).not.toEqual(true);
@@ -66,7 +68,7 @@ describe.skip('e2e state', () => {
.getStorage([
storage.timestamp.now
])
.then((moment) => {
.then((moment: Moment) => {
console.error(moment);
expect(moment.toNumber()).not.toEqual(0);
@@ -2,13 +2,14 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageChangeSet } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import storage from '@polkadot/storage/static';
import Rpc from '../../src';
describe.skip('e2e subscriptions', () => {
let api;
let api: Rpc;
beforeEach(() => {
jest.setTimeout(30000);
@@ -16,17 +17,17 @@ describe.skip('e2e subscriptions', () => {
});
it('retrieves current timestamp', (done) => {
let count = 0;
let count: number = 0;
return api.state
.subscribeStorage([[storage.timestamp.now]], (data) => {
.subscribeStorage([[storage.timestamp.now]], (data: StorageChangeSet) => {
expect(data).toBeDefined();
if (++count === 3) {
done();
}
})
.then((subscriptionId) => {
.then((subscriptionId: number) => {
console.log('newHead: subscriptionId =', subscriptionId);
});
});