-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: read current password when constructing v3 wallet (#261)
* fix: read current password when constructing v3 wallet * refactor: add readWalletPasswordOrThrow helper
- Loading branch information
Showing
8 changed files
with
68 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
transform: { '^.+\\.ts?$': 'ts-jest' }, | ||
testEnvironment: 'node', | ||
testRegex: '/test/.*\\.spec\\.ts$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,46 @@ | ||
import { existsSync, unlinkSync, writeFileSync } from 'fs-extra' | ||
import { configYamlExists, readConfigYaml, readWalletPasswordOrThrow, writeConfigYaml } from '../src/config-yaml' | ||
|
||
jest.mock('env-paths', () => | ||
jest.fn().mockImplementation(() => ({ | ||
data: 'test/data', | ||
config: 'test/data', | ||
cache: 'test/data', | ||
log: 'test/data', | ||
temp: 'test/data', | ||
})), | ||
) | ||
|
||
describe('config-yaml module', () => { | ||
beforeEach(cleanUp) | ||
afterAll(cleanUp) | ||
|
||
test('check existence', () => { | ||
expect(configYamlExists()).toBe(false) | ||
writeFileSync('test/data/config.yaml', '') | ||
expect(configYamlExists()).toBe(true) | ||
}) | ||
|
||
test('read and write', () => { | ||
writeFileSync('test/data/config.yaml', 'test: true') | ||
writeConfigYaml({ | ||
abc: 123, | ||
}) | ||
expect(readConfigYaml()).toHaveProperty('test', 'true') | ||
expect(readConfigYaml()).toHaveProperty('abc', '123') | ||
}) | ||
|
||
test('read password', () => { | ||
expect(() => readWalletPasswordOrThrow()).toThrow('Attempted to read password, but config.yaml is not found') | ||
writeFileSync('test/data/config.yaml', 'test: true') | ||
expect(() => readWalletPasswordOrThrow()).toThrow('Attempted to read password, but config.yaml does not contain it') | ||
writeFileSync('test/data/config.yaml', 'password: test') | ||
expect(readWalletPasswordOrThrow()).toBe('test') | ||
}) | ||
}) | ||
|
||
function cleanUp() { | ||
if (existsSync('test/data/config.yaml')) { | ||
unlinkSync('test/data/config.yaml') | ||
} | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.