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:
+24
-17
@@ -2,43 +2,50 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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 WsProvider from '@polkadot/rpc-provider/ws';
|
||||||
|
|
||||||
import Rpc from '../../src';
|
import Rpc from '../../src';
|
||||||
|
|
||||||
describe.skip('e2e krumme lanke', () => {
|
const randomAccount = '5HTqyWJHAVUieZnpb1V8gK4T1E4mnhkrUVSSzWBQd6kYgsVJ';
|
||||||
let api;
|
|
||||||
|
describe.skip('e2e Alexander - Polkadot', () => {
|
||||||
|
let api: Rpc;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.setTimeout(30000);
|
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) => {
|
it('subscribes to storage', (done) => {
|
||||||
api.state
|
return (
|
||||||
|
api.state
|
||||||
.subscribeStorage(
|
.subscribeStorage(
|
||||||
[
|
[
|
||||||
[storage.system.accountNonce, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
|
[storage.system.accountNonce, randomAccount],
|
||||||
[storage.balances.freeBalance, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
|
[storage.session.currentIndex]
|
||||||
],
|
],
|
||||||
(data) => {
|
(data: StorageChangeSet) => {
|
||||||
expect(data).toHaveLength(2);
|
expect(data).toHaveLength(2);
|
||||||
expect(data[0].toNumber()).toEqual(0);
|
expect(data).toEqual(
|
||||||
expect(data[1].toNumber()).not.toEqual(0);
|
expect.arrayContaining([
|
||||||
|
expect.any(BlockNumber),
|
||||||
|
expect.any(Index)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}
|
}).then((subscriptionId: number) => {
|
||||||
)
|
console.log('stoarge subscriptionId =', subscriptionId);
|
||||||
.then((subscriptionId) => {
|
})
|
||||||
console.log('stoarge subscriptionId =', subscriptionId);
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves a block by hash (krumme lanke #1)', () => {
|
it('retrieves a block by hash (krumme lanke #1)', () => {
|
||||||
return api.chain
|
return api.chain
|
||||||
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
|
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
|
||||||
.then((block) => {
|
.then((block: SignedBlock) => {
|
||||||
expect(block).toBeDefined();
|
expect(block).toBeDefined();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -51,7 +58,7 @@ describe.skip('e2e krumme lanke', () => {
|
|||||||
it('retrieves a block by hash (krumme lanke #2)', () => {
|
it('retrieves a block by hash (krumme lanke #2)', () => {
|
||||||
return api.chain
|
return api.chain
|
||||||
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
|
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
|
||||||
.then((block) => {
|
.then((block: SignedBlock) => {
|
||||||
expect(block).toBeDefined();
|
expect(block).toBeDefined();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
+6
-5
@@ -2,12 +2,13 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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 WsProvider from '@polkadot/rpc-provider/ws';
|
||||||
|
|
||||||
import Rpc from '../../src';
|
import Rpc from '../../src';
|
||||||
|
|
||||||
describe.skip('e2e basics', () => {
|
describe.skip('e2e basics', () => {
|
||||||
let api;
|
let api: Rpc;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.setTimeout(30000);
|
jest.setTimeout(30000);
|
||||||
@@ -17,8 +18,8 @@ describe.skip('e2e basics', () => {
|
|||||||
it('retrieves the pending extrinsics', () => {
|
it('retrieves the pending extrinsics', () => {
|
||||||
return api.author
|
return api.author
|
||||||
.pendingExtrinsics()
|
.pendingExtrinsics()
|
||||||
.then((extrinsics) => {
|
.then((extrinsics: PendingExtrinsics) => {
|
||||||
console.error('extrinsics', extrinsics);
|
console.log('extrinsics', extrinsics);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -30,8 +31,8 @@ describe.skip('e2e basics', () => {
|
|||||||
it('retrieves the system properties', () => {
|
it('retrieves the system properties', () => {
|
||||||
return api.system
|
return api.system
|
||||||
.properties()
|
.properties()
|
||||||
.then((properties) => {
|
.then((properties: ChainProperties) => {
|
||||||
console.error('properties', properties);
|
console.log('properties', properties);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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 WsProvider from '@polkadot/rpc-provider/ws';
|
||||||
|
|
||||||
import Rpc from '../../src';
|
import Rpc from '../../src';
|
||||||
|
|
||||||
describe.skip('e2e chain', () => {
|
describe.skip('e2e chain', () => {
|
||||||
let api;
|
let api: Rpc;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.setTimeout(30000);
|
jest.setTimeout(30000);
|
||||||
@@ -15,18 +16,18 @@ describe.skip('e2e chain', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('subscribes via subscribeNewHead', (done) => {
|
it('subscribes via subscribeNewHead', (done) => {
|
||||||
let count = 0;
|
let count: number = 0;
|
||||||
|
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
api.chain
|
api.chain
|
||||||
.subscribeNewHead((header) => {
|
.subscribeNewHead((header: Header) => {
|
||||||
expect(header).toBeDefined();
|
expect(header).toBeDefined();
|
||||||
|
|
||||||
if (++count === 3) {
|
if (++count === 3) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((subscriptionId) => {
|
.then((subscriptionId: number) => {
|
||||||
console.log('newHead: subscriptionId =', subscriptionId);
|
console.log('newHead: subscriptionId =', subscriptionId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -34,7 +35,7 @@ describe.skip('e2e chain', () => {
|
|||||||
it('retrieves the runtime version', () => {
|
it('retrieves the runtime version', () => {
|
||||||
return api.chain
|
return api.chain
|
||||||
.getRuntimeVersion()
|
.getRuntimeVersion()
|
||||||
.then((version) => {
|
.then((version: RuntimeVersion) => {
|
||||||
console.error('version', version);
|
console.error('version', version);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -2,14 +2,16 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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 storage from '@polkadot/storage/static';
|
||||||
|
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||||
|
|
||||||
import Rpc from '../../src';
|
import Rpc from '../../src';
|
||||||
|
|
||||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||||
|
|
||||||
describe.skip('e2e state', () => {
|
describe.skip('e2e state', () => {
|
||||||
let api;
|
let api: Rpc;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.setTimeout(30000);
|
jest.setTimeout(30000);
|
||||||
@@ -21,7 +23,7 @@ describe.skip('e2e state', () => {
|
|||||||
.getStorage([
|
.getStorage([
|
||||||
storage.substrate.code
|
storage.substrate.code
|
||||||
])
|
])
|
||||||
.then((code) => {
|
.then((code: Bytes) => {
|
||||||
console.error(code.toHex().substr(0, 256), '...');
|
console.error(code.toHex().substr(0, 256), '...');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -34,7 +36,7 @@ describe.skip('e2e state', () => {
|
|||||||
it('retrieves the wasm metadata', () => {
|
it('retrieves the wasm metadata', () => {
|
||||||
return api.state
|
return api.state
|
||||||
.getMetadata()
|
.getMetadata()
|
||||||
.then((meta) => {
|
.then((meta: Metadata) => {
|
||||||
console.error(JSON.stringify(meta.toJSON()));
|
console.error(JSON.stringify(meta.toJSON()));
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -49,7 +51,7 @@ describe.skip('e2e state', () => {
|
|||||||
.getStorage([
|
.getStorage([
|
||||||
storage.balances.freeBalance, ALICE
|
storage.balances.freeBalance, ALICE
|
||||||
])
|
])
|
||||||
.then((balance) => {
|
.then((balance: Balance) => {
|
||||||
console.error(balance);
|
console.error(balance);
|
||||||
|
|
||||||
expect(balance.isZero()).not.toEqual(true);
|
expect(balance.isZero()).not.toEqual(true);
|
||||||
@@ -66,7 +68,7 @@ describe.skip('e2e state', () => {
|
|||||||
.getStorage([
|
.getStorage([
|
||||||
storage.timestamp.now
|
storage.timestamp.now
|
||||||
])
|
])
|
||||||
.then((moment) => {
|
.then((moment: Moment) => {
|
||||||
console.error(moment);
|
console.error(moment);
|
||||||
|
|
||||||
expect(moment.toNumber()).not.toEqual(0);
|
expect(moment.toNumber()).not.toEqual(0);
|
||||||
+5
-4
@@ -2,13 +2,14 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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 WsProvider from '@polkadot/rpc-provider/ws';
|
||||||
import storage from '@polkadot/storage/static';
|
import storage from '@polkadot/storage/static';
|
||||||
|
|
||||||
import Rpc from '../../src';
|
import Rpc from '../../src';
|
||||||
|
|
||||||
describe.skip('e2e subscriptions', () => {
|
describe.skip('e2e subscriptions', () => {
|
||||||
let api;
|
let api: Rpc;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.setTimeout(30000);
|
jest.setTimeout(30000);
|
||||||
@@ -16,17 +17,17 @@ describe.skip('e2e subscriptions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves current timestamp', (done) => {
|
it('retrieves current timestamp', (done) => {
|
||||||
let count = 0;
|
let count: number = 0;
|
||||||
|
|
||||||
return api.state
|
return api.state
|
||||||
.subscribeStorage([[storage.timestamp.now]], (data) => {
|
.subscribeStorage([[storage.timestamp.now]], (data: StorageChangeSet) => {
|
||||||
expect(data).toBeDefined();
|
expect(data).toBeDefined();
|
||||||
|
|
||||||
if (++count === 3) {
|
if (++count === 3) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((subscriptionId) => {
|
.then((subscriptionId: number) => {
|
||||||
console.log('newHead: subscriptionId =', subscriptionId);
|
console.log('newHead: subscriptionId =', subscriptionId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user