* fix: Detect chain specs that enable test environment and dev accounts Issue #130
* test: refactor moving chain checker into meaningful function name
* fix: Detect check specs requiring backward compatibility encoding for Issue #130
* remove comment
* remove comment and restore source maps
* fix: Fix the license information in test files
* refactor: Move cases into array with meaningful array. Cater for numbers
* refactor: Reduce how condensed the code is
* refactor: Use Polkadot isUndefined helper
* refactor: Move RegEx instantiation outside function so not called every time
* refactor: Move new utility functions and associated tests into ui-react-rx/src/util
* fix: Update to cater for renaming of poc-2 to staging
See commit updates since `poc-2` has been renamed to `staging` 3426552c76
This commit is contained in:
parent
b96c450774
commit
62b1158c69
@ -6,6 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import isTestChain from '@polkadot/ui-react-rx/util/isTestChain';
|
||||
import classes from '@polkadot/ui-app/util/classes';
|
||||
import keyring from '@polkadot/ui-keyring/index';
|
||||
import Chain from '@polkadot/ui-react-rx/Chain';
|
||||
@ -17,7 +18,7 @@ import translate from './translate';
|
||||
type Props = I18nProps & {};
|
||||
|
||||
function updateTestInfo (chain?: string) {
|
||||
keyring.setTestMode(chain === 'dev');
|
||||
keyring.setTestMode(isTestChain(chain));
|
||||
}
|
||||
|
||||
function NodeInfo ({ className, style, t }: Props) {
|
||||
|
||||
@ -8,6 +8,8 @@ import { EncodingVersions } from '@polkadot/params/types';
|
||||
import { ApiProps } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import shouldUseLatestChain from '@polkadot/ui-react-rx/util/shouldUseLatestChain';
|
||||
import createWsProvider from '@polkadot/api-provider/ws';
|
||||
import createApi from '@polkadot/api-rx';
|
||||
import defaults from '@polkadot/api-rx/defaults';
|
||||
@ -26,9 +28,7 @@ type State = ApiProps & {
|
||||
};
|
||||
|
||||
function apiSupport (chain?: string): EncodingVersions {
|
||||
return chain === undefined || chain === 'poc-1'
|
||||
? 'poc-1'
|
||||
: 'latest';
|
||||
return shouldUseLatestChain(chain) ? 'latest' : 'poc-1';
|
||||
}
|
||||
|
||||
export default class Api extends React.PureComponent<Props, State> {
|
||||
|
||||
24
packages/ui-react-rx/src/util/isTestChain.spec.js
Normal file
24
packages/ui-react-rx/src/util/isTestChain.spec.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isTestChain from './isTestChain';
|
||||
|
||||
describe('check chain spec to configure keyring test mode and dev accounts availability', () => {
|
||||
it('enables test environment when chain specification matches text of dev or loc(al)', () => {
|
||||
const validTestModeChainSpecsWithDev = ['Development disorder', 'my development', 'a devotion to'];
|
||||
const validTestModeChainSpecsWithLoc = ['Local beer', 'one local beer', 'one good locust'];
|
||||
|
||||
for (let s of validTestModeChainSpecsWithDev.concat(validTestModeChainSpecsWithLoc)) {
|
||||
expect(isTestChain(s)).toEqual(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('disables keyring test mode when chain specification is not a test mode or undefined or number type', () => {
|
||||
const invalidTestModeChainSpecs = ['PoC-1 Testnet', 'Staging Testnet', 'future PoC-2 Testnet', 'a pocadot?', undefined, 0];
|
||||
|
||||
for (let s of invalidTestModeChainSpecs) {
|
||||
expect(isTestChain(s)).toEqual(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
17
packages/ui-react-rx/src/util/isTestChain.ts
Normal file
17
packages/ui-react-rx/src/util/isTestChain.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
|
||||
const re = new RegExp('(dev|loc)', 'i');
|
||||
|
||||
export default function isTestChain (chain?: string): boolean {
|
||||
if (isUndefined(chain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const match = re.test(chain.toString().toLowerCase());
|
||||
|
||||
return match ? true : false;
|
||||
}
|
||||
25
packages/ui-react-rx/src/util/shouldUseLatestChain.spec.js
Normal file
25
packages/ui-react-rx/src/util/shouldUseLatestChain.spec.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import shouldUseLatestChain from './shouldUseLatestChain';
|
||||
|
||||
describe('check chain spec to configure encoding', () => {
|
||||
it('enables PoC-1 encoding when chain specification is PoC-1 or undefined', () => {
|
||||
let validChainSpecWithPoC1 = ['try poc-1 now', 'testing PoC-1 Testnet'];
|
||||
const validChainSpecWithUndefinedOrNumber = [undefined];
|
||||
|
||||
for (let s of validChainSpecWithPoC1.concat(validChainSpecWithUndefinedOrNumber)) {
|
||||
expect(shouldUseLatestChain(s)).toEqual(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('enables Latest encoding when chain specification is NOT PoC-1 or undefined', () => {
|
||||
const invalidChainSpecWithoutPoC1OrUndefined = ['poc-2', 'PoC-2 Testnet', 'staging',
|
||||
'Staging Testnet', 'Local', 'Development', ' development', 'dev', 'Local', ' local ', 'loc', 0];
|
||||
|
||||
for (let s of invalidChainSpecWithoutPoC1OrUndefined) {
|
||||
expect(shouldUseLatestChain(s)).toEqual(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
17
packages/ui-react-rx/src/util/shouldUseLatestChain.ts
Normal file
17
packages/ui-react-rx/src/util/shouldUseLatestChain.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react-rx authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
|
||||
const re = new RegExp('(poc-1)', 'i');
|
||||
|
||||
export default function shouldUseLatestChain (chain?: string): boolean {
|
||||
if (isUndefined(chain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const match = re.test(chain.toString().toLowerCase());
|
||||
|
||||
return match ? false : true;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user