forked from polkadot-js/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…lkadot-js#133) * fix: Detect chain specs that enable test environment and dev accounts Issue polkadot-js#130 * test: refactor moving chain checker into meaningful function name * fix: Detect check specs requiring backward compatibility encoding for Issue polkadot-js#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` paritytech/polkadot@3426552
- Loading branch information
Showing
6 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 25 additions & 0 deletions
25
packages/ui-react-rx/src/util/shouldUseLatestChain.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |