* Adjust * Better, need a BoundedVec solution... * Composites * Storage optional types * Better... not perfect * v14 tests passing * Always perform asLatest * Keep portable registry seperate * Cleanup derived types * Cleanups * Adjust * Cleanups * Pass wraps * Rename types (PortableRegistry) -> lookup * Back on-track... * SiLookup strings * Allow building * unsafe create on registry * createTypeUnsafe typing * Adjust * Fix bool check * Remove WrappedConstructor * Additional * Additional cleanups * On-demand even type creation * Rework * Adjust * Revert createClass to master (with adjustments) * Running through v14 * Registry from master * Run against v14 * Adjust * Adjust * Adjust generation (non-complete) * Adjust * Definition from metadata (round 1) * Some linting fixes * v13 * Adjust * Dedupe * Some linting * Additional linting (md generation, not all) * md additional * calls update * Additional linting * Cleanups * Remove extra arg * Remove unneeded assert * Revert < 12 index adjustments * Cleanups * v13 compat types * Some tests * Registry revert * Additional test fixes * Adjust sorting * Adjust tests with lookups * CodeClimate cleanups * Additional tests * Compat with prev-generation args * Error & events compat args * Fix Error/Event metadata creation * Fix lookup circular * Registry types * Adjust * Adjust lookup generation * Short-circuit full type (with lookupIndex) * Defaults for type expansion * Tuple with extra spaces removed * Fill in generated types * Checks * Adjust generation * Adjust tests * Adjust * Adjust type encoding * Adjust * Use registry for name generation * Update v13 lookup generation * Adjust looup with typeDef (optional) * Format lookup definitions * Start with TS interface generation * Adjust * Adjust * Adjust * Don't short-cisrcuit type evaluation * Adjust * Correct plain imports * Adjust * Don't remove already-set lookupName * Bytes * Cleanups * Adjust with unused * Embed non-named structs * Enum without name throws error * Case-sensitivity on path duplication * s/lookupNameOrig/lookupNameRoot/ * Don't export Lookup* type interfaces * Shortcut lookup * Adjust * Revert api/Decorate * Adjust import name generation * Don't clobber root lookups * Root exports * Remove duplicated fields creation * Adjust less-important name parts * Cleanups & imports * Adjust with correct imports * Storage optionality * Rebuild, fix (some) tests * Extract identity BitFlags * Additional cleanups * Adjust * No IdentityFields override * v13 for extrinsic test * Dedupe getUniqTypes * Simplify? * Adjust * Update sorting * Adjust expansion * Dedupe * Strip generics, sub-part * matching * Name matching * Align * Adjust set matching * hex/json split * naming * v13 for extrinsic injection test * Adjust test signature * Dedupe tests * Adjust * Update import * augment @polkadot/types/lookup * Sort import names * Handle BitSequence in PortableRegistry * Use Kusama-dev v14 metadata * Merge bitSequence support * Polkadot/Substrate split * Template formatting * Hobbling along * Adjust * Recode subs * Fix circular in dual fashion * Adjust * Also generate Substrate * Exclude Substrate types from Polkadot * Remove duplicate phantoms * Cleanup lookup typegen * Additional * Extract names with params (as applicable) * Ensure path is always available * renames * Metadata v14 only has combined Map * v14 Map conversion de-duped * Substrate Map conversion * v13 tests * Apply suggestions from code review * Housekeeping * v14 bump * NMap -> Map (& others removed) * Adjust generation * Decorate linting * Tuple & non-tuple types * hashers check * Condense * Additional asTuple check * Consistent pre-v14 Map handling * Fix metadata tests * Fix (some) tests * Fix test expectations * Fail create early * Additional fixes * Additional * Movement * Remove CodecArg * Dump it * Apply param expansion * Remove only * Allow no-args to StorageKey * linting * multi fixes * Map adjustments * Rebuild * Rebuild * Rebuild * Latest * Bump metadata * Rewrite * Fix lookup formatting * Rebuild after merge * Latest substrate v14 * Rebuild * Rebuild (+ no enum trailing ,) * trigger * Fix JSON checks * Remove unneeded check * Bump Kusama/Polkadot * Dedupe testUtil * Metadata v14
103 lines
3.0 KiB
TypeScript
103 lines
3.0 KiB
TypeScript
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
|
|
import { from, Observable } from 'rxjs';
|
|
|
|
import { ApiRx } from '@polkadot/api/rx';
|
|
import { MockProvider } from '@polkadot/rpc-provider/mock';
|
|
import { TypeRegistry } from '@polkadot/types/create';
|
|
|
|
import { ExactDerive } from '.';
|
|
|
|
const testFunction = (api: ApiRx): any => {
|
|
return <S extends keyof ExactDerive, M extends keyof (typeof api.derive[S])>(section: S, method: M, inputs: any[]): void => {
|
|
describe(`derive.${section}.${method}`, (): void => {
|
|
it('should be a function', (): void => {
|
|
expect(typeof api.derive[section][method]).toBe('function');
|
|
});
|
|
|
|
it('should return an Observable', (): void => {
|
|
expect((api.derive[section][method] as any)(...inputs)).toBeInstanceOf(Observable);
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
describe('derive', (): void => {
|
|
const registry = new TypeRegistry();
|
|
|
|
describe('builtin', (): void => {
|
|
const api = new ApiRx({ provider: new MockProvider(registry), registry });
|
|
|
|
beforeAll((done): void => {
|
|
api.isReady.subscribe(() => done());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await api.disconnect();
|
|
});
|
|
|
|
testFunction(api)('accounts', 'idAndIndex', []);
|
|
testFunction(api)('accounts', 'idToIndex', []);
|
|
testFunction(api)('accounts', 'indexes', []);
|
|
testFunction(api)('accounts', 'indexToId', []);
|
|
|
|
testFunction(api)('balances', 'all', []);
|
|
testFunction(api)('balances', 'fees', []);
|
|
testFunction(api)('balances', 'votingBalance', []);
|
|
testFunction(api)('balances', 'votingBalances', []);
|
|
|
|
testFunction(api)('chain', 'bestNumber', []);
|
|
testFunction(api)('chain', 'bestNumberFinalized', []);
|
|
|
|
testFunction(api)('democracy', 'proposals', []);
|
|
testFunction(api)('democracy', 'referendums', []);
|
|
|
|
testFunction(api)('elections', 'info', []);
|
|
|
|
testFunction(api)('session', 'eraLength', []);
|
|
testFunction(api)('session', 'eraProgress', []);
|
|
testFunction(api)('session', 'sessionProgress', []);
|
|
|
|
testFunction(api)('staking', 'account', []);
|
|
testFunction(api)('staking', 'stashes', []);
|
|
});
|
|
|
|
describe('custom', (): void => {
|
|
const api = new ApiRx({
|
|
derives: {
|
|
balances: {
|
|
fees: (): any => (): Observable<any> => from(['a', 'b'])
|
|
},
|
|
custom: {
|
|
test: (): any => (): Observable<any> => from([1, 2, 3])
|
|
}
|
|
},
|
|
provider: new MockProvider(registry),
|
|
registry,
|
|
throwOnConnect: true
|
|
});
|
|
|
|
beforeAll((done): void => {
|
|
api.isReady.subscribe(() => done());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await api.disconnect();
|
|
});
|
|
|
|
// override
|
|
testFunction(api)('balances', 'fees', ['a', 'b']);
|
|
|
|
// new
|
|
testFunction(api)('custom', 'test', [1, 2, 3]);
|
|
|
|
// existing
|
|
testFunction(api)('chain', 'bestNumber', []);
|
|
});
|
|
});
|