E2E testing (#177)

* Move e2e tests to provider

* Rx subscriptions

* Import @polkadot/api-provider, fix package names

* Decrease verbosity, skip all e2e tests
This commit is contained in:
Jaco Greeff
2018-10-01 14:11:43 +02:00
committed by GitHub
parent d230c05d16
commit 876c34c532
11 changed files with 204 additions and 23 deletions
+4 -4
View File
@@ -28,10 +28,6 @@
"url": "https://github.com/polkadot-js/api/issues"
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-provider#readme",
"devDependencies": {
"mock-socket": "^8.0.2",
"nock": "^9.6.1"
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@polkadot/storage": "^0.30.5",
@@ -42,5 +38,9 @@
"eventemitter3": "^3.1.0",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
},
"devDependencies": {
"mock-socket": "^8.0.2",
"nock": "^9.6.1"
}
}
@@ -1,28 +0,0 @@
// Copyright 2017-2018 @polkadot/api-provider authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Api from '../../api/src';
import Ws from '../src/ws';
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;
});
});
});
@@ -1,49 +0,0 @@
// Copyright 2017-2018 @polkadot/api-provider authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Api from '../../api/src';
import Ws from '../src/ws';
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;
});
});
});
@@ -1,67 +0,0 @@
// Copyright 2017-2018 @polkadot/api-provider 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 Api from '../../api/src';
import Ws from '../src/ws';
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;
});
});
});
@@ -1,81 +0,0 @@
// Copyright 2017-2018 @polkadot/api-provider 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/testing';
import Api from '../../api/src';
import Ws from '../src/ws';
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;
});
});
});