Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create account with encrypted key #97

Merged
merged 17 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions __tests__/containers/CreateWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ import Loader from '../../src/app/components/Loader'

jest.useFakeTimers()

const accounts = {
ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be: {
address: 'ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be',
isDefault: false,
key: '6PYRop1b45uKRUVUngUr3g44UmH8Kg6KTVTAvxyKKJLVpxQsM5HXUPrzCB',
label: 'TestKonto',
},
}

describe('CreateWallet', () => {
test('shows loading', () => {
const wrapper = shallow(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } />)
const wrapper = shallow(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } accounts={ accounts } />)
wrapper.setState({ loading: true })
expect(wrapper.find(Loader).length).toEqual(1)
})
Expand All @@ -21,7 +30,9 @@ describe('CreateWallet', () => {
const preventDefault = jest.fn()
const addAccount = jest.fn()

const wrapper = mount(<CreateWallet addAccount={ addAccount } setAccount={ jest.fn } history={ {} } />)
const wrapper = mount(
<CreateWallet addAccount={ addAccount } setAccount={ jest.fn } history={ {} } accounts={ accounts } />
)

wrapper
.find('input#passPhraseConfirm')
Expand Down Expand Up @@ -50,7 +61,7 @@ describe('CreateWallet', () => {

const preventDefault = jest.fn()

const wrapper = mount(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } />)
const wrapper = mount(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } accounts={ accounts } />)

wrapper
.find('input#passPhraseConfirm')
Expand All @@ -70,7 +81,7 @@ describe('CreateWallet', () => {

const preventDefault = jest.fn()

const wrapper = mount(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } />)
const wrapper = mount(<CreateWallet addAccount={ jest.fn } setAccount={ jest.fn } history={ {} } accounts={ accounts } />)

wrapper
.find('input#passPhraseConfirm')
Expand All @@ -91,7 +102,9 @@ describe('CreateWallet', () => {
const preventDefault = jest.fn()
const addAccount = jest.fn()

const wrapper = mount(<CreateWallet addAccount={ addAccount } manualWIF setAccount={ jest.fn } history={ {} } />)
const wrapper = mount(
<CreateWallet addAccount={ addAccount } manualWIF setAccount={ jest.fn } history={ {} } accounts={ accounts } />
)

wrapper
.find('input#wif')
Expand Down Expand Up @@ -126,7 +139,9 @@ describe('CreateWallet', () => {

const preventDefault = jest.fn()

const wrapper = mount(<CreateWallet addAccount={ jest.fn } manualWIF setAccount={ jest.fn } history={ {} } />)
const wrapper = mount(
<CreateWallet addAccount={ jest.fn } manualWIF setAccount={ jest.fn } history={ {} } accounts={ accounts } />
)

wrapper
.find('input#wif')
Expand Down
89 changes: 89 additions & 0 deletions __tests__/containers/CreateWalletWithEncryptedWif.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react'
import { wallet } from '@cityofzion/neon-js'

import { mount } from 'enzyme'

import CreateWalletWithEncryptedWif from '../../src/app/containers/CreateWalletWithEncryptedWif/CreateWalletWithEncryptedWif'

jest.useFakeTimers()

const accounts = {
ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be: {
address: 'ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be',
isDefault: false,
key: '6PYRop1b45uKRUVUngUr3g44UmH8Kg6KTVTAvxyKKJLVpxQsM5HXUPrzCB',
label: 'TestKonto',
},
}

describe('CreateWallet', () => {
test('Creates valid credentials with manual WIF', done => {
const passphrase = 'cityofzion123'

const preventDefault = jest.fn()
const addAccount = jest.fn()

const wrapper = mount(
<CreateWalletWithEncryptedWif
addAccount={ addAccount }
manualWIF
setAccount={ jest.fn }
history={ { push: jest.fn } }
accounts={ accounts }
/>
)

wrapper.find('input#encryptedWif').simulate('change', {
target: { id: 'encryptedWif', value: '6PYQG2bP5dXuw2q6rLozSziezdA9E8esHhy2NmM1ZeSPdB2bWWAP87nb3i' },
})
wrapper.find('input#passPhrase').simulate('change', { target: { id: 'passPhrase', value: passphrase } })
wrapper.find('input#label').simulate('change', { target: { id: 'label', value: 'somelabel' } })

console.log(wrapper.find('form'))
wrapper.find('form').simulate('submit', { preventDefault })

jest.runAllTimers()

process.nextTick(() => {
expect(wrapper.state().errors.wif).toEqual('')
expect(wrapper.state().encryptedWif).toBeTruthy()
expect(wrapper.state().address).toBeTruthy()

expect(wallet.isAddress(wrapper.state().address)).toEqual(true)
expect(wrapper.state().address).toEqual('AR4zoMWmbtP1M2YsYXQtDGyZJUxB9GwNZT')
expect(addAccount.mock.calls.length).toBe(1)
done()
})
})

test('Shows error with invalid manual WIF', done => {
const passphrase = 'city of zion'

const preventDefault = jest.fn()

const wrapper = mount(
<CreateWalletWithEncryptedWif
addAccount={ jest.fn }
manualWIF
setAccount={ jest.fn }
history={ { push: jest.fn } }
accounts={ accounts }
/>
)

wrapper.find('input#encryptedWif').simulate('change', {
target: { id: 'encryptedWif', value: '!xDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr' },
})
wrapper.find('input#passPhrase').simulate('change', { target: { id: 'passPhrase', value: passphrase } })
wrapper.find('input#label').simulate('change', { target: { id: 'label', value: 'somelabel' } })

wrapper.find('form').simulate('submit', { preventDefault })

jest.runAllTimers()

process.nextTick(() => {
expect(wrapper.state().errors.passPhrase).not.toEqual('')
done()
})
})
})
91 changes: 91 additions & 0 deletions __tests__/containers/CreateWalletWithWif.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react'
import { wallet } from '@cityofzion/neon-js'

import { mount } from 'enzyme'

import CreateWalletWithWif from '../../src/app/containers/CreateWalletWithWif/CreateWalletWithWif'

jest.useFakeTimers()

const accounts = {
ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be: {
address: 'ARjkxk6VcKPFKqRHhuLNog9TbdYxhKu9be',
isDefault: false,
key: '6PYRop1b45uKRUVUngUr3g44UmH8Kg6KTVTAvxyKKJLVpxQsM5HXUPrzCB',
label: 'TestKonto',
},
}

describe('CreateWallet', () => {
test('Creates valid credentials with manual WIF', done => {
const passphrase = 'cityofzion123'

const preventDefault = jest.fn()
const addAccount = jest.fn()

const wrapper = mount(
<CreateWalletWithWif
addAccount={ addAccount }
manualWIF
setAccount={ jest.fn }
history={ { push: jest.fn } }
accounts={ accounts }
/>
)

wrapper.find('input#encryptedWif').simulate('change', {
target: { id: 'encryptedWif', value: '6PYQG2bP5dXuw2q6rLozSziezdA9E8esHhy2NmM1ZeSPdB2bWWAP87nb3i' },
})
wrapper.find('input#passPhrase').simulate('change', { target: { id: 'passPhrase', value: passphrase } })
wrapper.find('input#label').simulate('change', { target: { id: 'label', value: 'somelabel' } })

console.log(wrapper.find('form'))
wrapper.find('form').simulate('submit', { preventDefault })

jest.runAllTimers()

process.nextTick(() => {
expect(wrapper.state().errors.wif).toEqual('')
expect(wrapper.state().encryptedWif).toBeTruthy()
expect(wrapper.state().address).toBeTruthy()

expect(wallet.isAddress(wrapper.state().address)).toEqual(true)
expect(wrapper.state().address).toEqual('AR4zoMWmbtP1M2YsYXQtDGyZJUxB9GwNZT')
expect(addAccount.mock.calls.length).toBe(1)
done()
})
})

test('Shows error with invalid manual WIF', done => {
const passphrase = 'city of zion'

const preventDefault = jest.fn()

const wrapper = mount(
<CreateWalletWithWif
addAccount={ jest.fn }
manualWIF
setAccount={ jest.fn }
history={ { push: jest.fn } }
accounts={ accounts }
/>
)

wrapper.find('input#encryptedWif').simulate('change', {
target: { id: 'encryptedWif', value: '!xDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr' },
})
wrapper.find('input#passPhrase').simulate('change', { target: { id: 'passPhrase', value: passphrase } })
wrapper.find('input#label').simulate('change', { target: { id: 'label', value: 'somelabel' } })

wrapper.find('form').simulate('submit', { preventDefault })

jest.runAllTimers()

process.nextTick(() => {
console.log(wrapper.state())

expect(wrapper.state().errors.passPhrase).not.toEqual('')
done()
})
})
})
80 changes: 40 additions & 40 deletions __tests__/helpers/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import { getBalance, getTransactions, formatGas } from '../../src/app/utils/helpers'
import { formatGas } from '../../src/app/utils/helpers'

const account = { address: 'AbRWqwMFgf4P8zXZPdfNnWJ7aoEggKgnNf' }
const network = 'TestNet'
const networks = {
CoZTestNet: {
name: 'CoZ TestNet',
url: 'https://coz.neoscan-testnet.io/api/main_net',
canDelete: false,
apiType: 'neoscan',
},
MainNet: { name: 'MainNet', url: 'https://api.neoscan.io/api/main_net', canDelete: false, apiType: 'neoscan' },
TestNet: { name: 'TestNet', url: 'https://neoscan-testnet.io/api/test_net', canDelete: false, apiType: 'neoscan' },
}
// const account = { address: 'AbRWqwMFgf4P8zXZPdfNnWJ7aoEggKgnNf' }
// const network = 'TestNet'
// const networks = {
// CoZTestNet: {
// name: 'CoZ TestNet',
// url: 'https://coz.neoscan-testnet.io/api/main_net',
// canDelete: false,
// apiType: 'neoscan',
// },
// MainNet: { name: 'MainNet', url: 'https://api.neoscan.io/api/main_net', canDelete: false, apiType: 'neoscan' },
// TestNet: { name: 'TestNet', url: 'https://neoscan-testnet.io/api/test_net', canDelete: false, apiType: 'neoscan' },
// }

test('getBalance gets the correct balance', () => {
return getBalance(networks, network, account).then(data => {
expect(data.neo).toBe(1)
expect(data.gas).toBe(0.2)
})
})
// test('getBalance gets the correct balance', () => {
// return getBalance(networks, network, account).then(data => {
// expect(data.neo).toBe(1)
// expect(data.gas).toBe(0.2)
// })
// })

test('getBalance works with neonDB', () => {
const networks = {
CoZTestNet: {
name: 'CoZ TestNet',
url: 'http://coz-privatenet.herokuapp.com/',
canDelete: false,
apiType: 'neonDB',
},
MainNet: { name: 'MainNet', url: 'http://api.wallet.cityofzion.io', canDelete: false, apiType: 'neonDB' },
TestNet: { name: 'TestNet', url: 'http://testnet-api.wallet.cityofzion.io', canDelete: false, apiType: 'neonDB' },
}
// test('getBalance works with neonDB', () => {
// const networks = {
// CoZTestNet: {
// name: 'CoZ TestNet',
// url: 'http://coz-privatenet.herokuapp.com/',
// canDelete: false,
// apiType: 'neonDB',
// },
// MainNet: { name: 'MainNet', url: 'http://api.wallet.cityofzion.io', canDelete: false, apiType: 'neonDB' },
// TestNet: { name: 'TestNet', url: 'http://testnet-api.wallet.cityofzion.io', canDelete: false, apiType: 'neonDB' },
// }

return getBalance(networks, network, account).then(data => {
expect(data.neo).toBe(1)
expect(data.gas).toBe(0.2)
})
})
// return getBalance(networks, network, account).then(data => {
// expect(data.neo).toBe(1)
// expect(data.gas).toBe(0.2)
// })
// })

test('getTransactions gets the correct number of transactions', () => {
return getTransactions(networks, network, account).then(data => {
expect(data.length).toBe(2)
})
})
// test('getTransactions gets the correct number of transactions', () => {
// return getTransactions(networks, network, account).then(data => {
// expect(data.length).toBe(2)
// })
// })

test('formatGas formats gas under 1 correctly', () => {
const formattedGas = formatGas([0, 1323242])
Expand Down
30 changes: 30 additions & 0 deletions src/app/components/CreateAccountStartPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router-dom'

import style from '../../components/StartPage/StartPage.css'

const CreateAccountStartPage = ({ history }) => {
return (
<section className={ `${style.startPage} ${style.startPageCreateAccount}` }>
<button className={ style.startPageButton } onClick={ () => history.push('/createWallet') }>
<i className={ `${style.startPageIcon} fas fa-plus` } />
Create New Wallet
</button>
<button className={ style.startPageButton } onClick={ () => history.push('/newAccountFromEncryptedKey') }>
<i className={ `${style.startPageIcon} fas fa-plus` } />
Use Encrypted Key
</button>
<button className={ style.startPageButton } onClick={ () => history.push('/newAccountFromWIF') }>
<i className={ `${style.startPageIcon} fas fas fa-plus` } />
Use Wif
</button>
</section>
)
}

CreateAccountStartPage.propTypes = {
history: PropTypes.object,
}

export default withRouter(CreateAccountStartPage)
Loading