-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from CityOfZion/dev
[Release] neon-wallet v0.2.2
- Loading branch information
Showing
12 changed files
with
181 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { wallet } from 'neon-js' | ||
|
||
import { wifLoginActions } from '../../app/actions/authActions' | ||
|
||
describe('authActions', () => { | ||
describe('wifLoginActions', () => { | ||
describe('request', () => { | ||
const wif = 'KxB52D1FGe5xBn6YeezNwj7grhkHZxq7bv2tmaCPoT4rxApMwMvU' | ||
const address = 'ASJQLBnhAs6fSgBv2R7KtRZjC8A9fAmcNW' | ||
const privateKey = '1c7a992d0e68b7b23cb430ba596bd68cecde042410d81e9e95ee19dc1bcd739d' | ||
|
||
test('returns an action object', () => { | ||
expect(wifLoginActions.request({ wif })).toEqual({ | ||
batch: false, | ||
type: 'AUTH/REQ/REQUEST', | ||
meta: { | ||
id: 'AUTH', | ||
type: 'REQ/REQUEST' | ||
}, | ||
payload: { | ||
fn: expect.any(Function) | ||
} | ||
}) | ||
}) | ||
|
||
describe('with valid WIF', () => { | ||
let wifMock, keyMock, accountMock | ||
|
||
beforeEach(() => { | ||
wifMock = jest.spyOn(wallet, 'isWIF').mockImplementation((str) => false) | ||
keyMock = jest.spyOn(wallet, 'isPrivateKey').mockImplementation((str) => true) | ||
accountMock = jest.spyOn(wallet, 'Account').mockImplementation((str) => ({ WIF: wif, address })) | ||
}) | ||
|
||
afterEach(() => { | ||
wifMock.mockRestore() | ||
keyMock.mockRestore() | ||
accountMock.mockRestore() | ||
}) | ||
|
||
test('returns authenticated account data', () => { | ||
const request = wifLoginActions.request({ wif }) | ||
expect(request.payload.fn({})).toEqual({ wif, address, isHardwareLogin: false }) | ||
}) | ||
}) | ||
|
||
describe('with valid private key', () => { | ||
let wifMock, keyMock, accountMock | ||
|
||
beforeEach(() => { | ||
wifMock = jest.spyOn(wallet, 'isWIF').mockImplementation((str) => false) | ||
keyMock = jest.spyOn(wallet, 'isPrivateKey').mockImplementation((str) => true) | ||
accountMock = jest.spyOn(wallet, 'Account').mockImplementation((str) => ({ WIF: wif, address })) | ||
}) | ||
|
||
afterEach(() => { | ||
wifMock.mockRestore() | ||
keyMock.mockRestore() | ||
accountMock.mockRestore() | ||
}) | ||
|
||
test('returns authenticated account data', () => { | ||
const request = wifLoginActions.request({ wif: privateKey }) | ||
expect(request.payload.fn({})).toEqual({ wif, address, isHardwareLogin: false }) | ||
}) | ||
}) | ||
|
||
describe('with invalid private key', () => { | ||
let wifMock, keyMock | ||
|
||
beforeEach(() => { | ||
wifMock = jest.spyOn(wallet, 'isWIF').mockImplementation((str) => false) | ||
keyMock = jest.spyOn(wallet, 'isPrivateKey').mockImplementation((str) => false) | ||
}) | ||
|
||
afterEach(() => { | ||
wifMock.mockRestore() | ||
keyMock.mockRestore() | ||
}) | ||
|
||
test('throws an error', () => { | ||
const request = wifLoginActions.request({ wif }) | ||
expect(() => request.payload.fn({})).toThrowError('That is not a valid private key') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('retry', () => { | ||
const wif = 'KxB52D1FGe5xBn6YeezNwj7grhkHZxq7bv2tmaCPoT4rxApMwMvU' | ||
|
||
test('returns an action object', () => { | ||
expect(wifLoginActions.retry({ wif })).toEqual({ | ||
batch: false, | ||
type: 'AUTH/REQ/RETRY', | ||
meta: { | ||
id: 'AUTH', | ||
type: 'REQ/RETRY' | ||
}, | ||
payload: { | ||
fn: expect.any(Function) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('cancel', () => { | ||
test('returns an action object', () => { | ||
expect(wifLoginActions.cancel()).toEqual({ | ||
batch: false, | ||
type: 'AUTH/REQ/CANCEL', | ||
meta: { | ||
id: 'AUTH', | ||
type: 'REQ/CANCEL' | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('reset', () => { | ||
test('returns an action object', () => { | ||
expect(wifLoginActions.reset()).toEqual({ | ||
batch: false, | ||
type: 'AUTH/REQ/RESET', | ||
meta: { | ||
id: 'AUTH', | ||
type: 'REQ/RESET' | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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
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
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