ghost-portal/packages/apps-config/src/endpoints/index.spec.ts
Nikos Kontakis e202dda584
Integrate substrate connect with Apps (#5644)
* integrate apps with smoldot init

* Add a new category for substrate connect light clients to be grouped under. Add translations; Alter Api.tsx in order to choose between light clients and/or url addresses

* remove supportedLightClient array that was introduced. SubstrateConnect already has the information included and will return error if no supported network is found

* rollback 'hacky' changes in order to proceed with better implementation

* alter configuration of testing and production networks in order to introduce light client type

* upgrade substrate connect to 0.3.7

* implementation for integrating substrate-connect

* merge from latest master

* Add substrate/connect version to 0.3.10

* fix merge conflicts

* introduce function for correctly creating the provider URLs and update URLs

* Fix mistaken typos

* fix linter issue about rpc-provider@npm:^4.10.1 missing

* move substrate-connect for react-api to dependencies

* Fix lint issues

* Add tests for substrate-connect light clients urls and fix for ws

* Update packages/react-api/src/Api.tsx

Co-authored-by: Jaco <jacogr@gmail.com>

* Remove duplicated code

* add exceptions in jest config (transformIgnorePatterns)

* minor fixes

* fix typo errors

* minor yarn update

* Alter urls to string | union type (revert urls for json-rpc)

* fix erroneously changed url

* fix yarn.lock

* Stub mock for tests of substrate connect

* fix yarn

* Update yarn.lock

* Update yarn.lock

* Update packages/apps/src/Endpoints/index.tsx

Co-authored-by: Jaco <jacogr@gmail.com>

* Update packages/apps-config/src/endpoints/util.ts

Co-authored-by: Jaco <jacogr@gmail.com>

* Fix Pr comments

* Fix function that was recreated in every rerender

* Update packages/apps/src/Endpoints/index.tsx

Co-authored-by: Jaco <jacogr@gmail.com>

* Fix 2nd bundle of PR comments

* Fix function on PR comment

* filter light clients out of auto-selected sidebar networks

* Update package.json

Co-authored-by: Jaco <jacogr@gmail.com>

* Update packages/react-api/package.json

Co-authored-by: Jaco <jacogr@gmail.com>

* run install

* update yarn.lock from master

* sync yarn.lock from master

* Alter implementation to avoid white screen and make sure that API returned from substrate-connect works

* Update packages/page-accounts/src/CreateAccount.slow.spec.tsx

* Update packages/page-bounties/src/Bounties.slow.spec.tsx

Co-authored-by: Jaco <jacogr@gmail.com>
2021-07-12 06:51:21 +02:00

83 lines
2.4 KiB
TypeScript

// Copyright 2017-2021 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { assert, isNumber, isString } from '@polkadot/util';
import { createWsEndpoints } from '.';
interface Endpoint {
name: string;
ws: string;
}
interface LightClientEndpoint {
name: string;
param: string;
}
const allEndpoints = createWsEndpoints((k: string, v?: string) => v || k);
describe('WS urls are all valid', (): void => {
allEndpoints
.filter(({ value }) =>
value &&
isString(value) &&
!value.includes('127.0.0.1') &&
!value.includes('substrate-connect')
)
.map(({ text, value }): Endpoint => ({
name: text as string,
ws: value
}))
.forEach(({ name, ws }) =>
it(`${name} @ ${ws}`, (): void => {
assert(ws.startsWith('wss://'), `${name} @ ${ws} should start with wss://`);
})
);
});
describe('light client urls are all valid', (): void => {
allEndpoints
.filter(({ value }) =>
value &&
isString(value) &&
value.includes('substrate-connect')
)
.map(({ text, value }): LightClientEndpoint => ({
name: text as string,
param: value
}))
.forEach(({ name, param }) =>
it(`${name} @ ${param}`, (): void => {
assert(param.substr(param.indexOf('-')) === '-substrate-connect', `${name} @ ${param} should end with '-substrate-connect'`);
})
);
});
describe('urls are sorted', (): void => {
let hasDevelopment = false;
let lastHeader = '';
const filtered = allEndpoints.filter(({ isHeader, isUnreachable, text }): boolean => {
hasDevelopment = hasDevelopment || (!!isHeader && text === 'Development');
return !isUnreachable && !hasDevelopment;
});
filtered.forEach(({ isHeader, text }, index): void => {
if (isHeader) {
lastHeader = text as string;
} else {
it(`${lastHeader}:: ${text as string}`, (): void => {
assert((
filtered[index - 1].isHeader ||
filtered[index - 1].linked ||
(isNumber(filtered[index - 1].paraId) && (filtered[index - 1].paraId as number) < 2000) ||
filtered[index - 1].text === '' ||
text === filtered[index - 1].text ||
(text as string).localeCompare(filtered[index - 1].text as string) === 1
), `${lastHeader}:: ${text as string} needs to be before ${filtered[index - 1].text as string}`);
});
}
});
});