-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New import/export file. Rename hash to genesis (#1877)
* fix: rename hash to genesis * Tests for DP text parser (#1878) * feat: adding tests for text parser * fix: linter * fix: adding more cases * fix: add test for multiple derivation path * fix: add test for multiple dp in one genesis * fix: soft \ hard naming * fix: import files (#1880) --------- Co-authored-by: Anastasiia Sokolova <[email protected]> --------- Co-authored-by: Anastasiia Sokolova <[email protected]>
- Loading branch information
1 parent
055aaae
commit c932a4a
Showing
3 changed files
with
195 additions
and
11 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
170 changes: 170 additions & 0 deletions
170
src/renderer/features/wallets/ImportKeys/lib/__tests__/import-keys-utils-text.test.ts
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,170 @@ | ||
import { importKeysUtils } from '../import-keys-utils'; | ||
|
||
describe('entities/dynamicDerivations/import-keys-utils/parseTextFile', () => { | ||
test('should return null for invalid version', () => { | ||
const fileContent = `version: 2\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef`; | ||
expect(importKeysUtils.parseTextFile(fileContent)).toBeNull(); | ||
}); | ||
|
||
test('should return null for invalid public address', () => { | ||
const fileContent = `version: 1\npublic address: invalid_address`; | ||
expect(importKeysUtils.parseTextFile(fileContent)).toBeNull(); | ||
}); | ||
|
||
test('should return null for missing derivation paths', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef`; | ||
expect(importKeysUtils.parseTextFile(fileContent)).toBeNull(); | ||
}); | ||
|
||
test('should parse text file with regular path', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//path: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//path', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with soft and hard path', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//hard/soft//hard/soft: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//hard/soft//hard/soft', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with soft path and shards', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n/soft_path//0...10: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '/soft_path', | ||
sharded: '10', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with hard path and shards', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//hard_path//0...10: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//hard_path', | ||
sharded: '10', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with sharded keys and different derivations', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//hard/soft//hard//0...10: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//hard/soft//hard', | ||
sharded: '10', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with difficult symbols in dp', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//polkadot//~!@#$%^&*(*)_+QWE'1234567890-=//0...10: name [type]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: `//polkadot//~!@#$%^&*(*)_+QWE'1234567890-=`, | ||
sharded: '10', | ||
name: 'name', | ||
type: 'type', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with multiple genesis and derivation paths', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//path1: name1 [type1]\ngenesis: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\n//path2: name2 [type2]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//path1', | ||
name: 'name1', | ||
type: 'type1', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
{ | ||
derivationPath: '//path2', | ||
name: 'name2', | ||
type: 'type2', | ||
chainId: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should parse text file with multiple derivation paths for one genesis', () => { | ||
const fileContent = `version: 1\npublic address: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\ngenesis: 0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\n//path1: name1 [type1]\n//path2: name2 [type2]`; | ||
const parsedData = importKeysUtils.parseTextFile(fileContent); | ||
expect(parsedData).toEqual({ | ||
version: '1', | ||
publicAddress: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', | ||
derivationPaths: [ | ||
{ | ||
derivationPath: '//path1', | ||
name: 'name1', | ||
type: 'type1', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
{ | ||
derivationPath: '//path2', | ||
name: 'name2', | ||
type: 'type2', | ||
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
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