Fix Geth account import (#4641)

* Fix Geth import - actually pass addresses through

* Work from addresses returned via RPC

* Display actual addresses imported (not selected)

* Update tests to cover bug fixed
This commit is contained in:
Jaco Greeff 2017-02-23 15:04:58 +01:00 committed by Arkadiy Paronyan
parent e60fa751eb
commit 3651095651
5 changed files with 39 additions and 16 deletions

View File

@ -207,7 +207,7 @@ export default class Parity {
importGethAccounts (accounts) { importGethAccounts (accounts) {
return this._transport return this._transport
.execute('parity_importGethAccounts', inAddresses) .execute('parity_importGethAccounts', inAddresses(accounts))
.then(outAddresses); .then(outAddresses);
} }

View File

@ -73,6 +73,21 @@ describe('api/rpc/parity', () => {
}); });
}); });
describe('importGethAccounts', () => {
const ACCOUNTS = ['0x63cf90d3f0410092fc0fca41846f596223979195'];
let scope;
beforeEach(() => {
scope = mockHttp([{ method: 'parity_importGethAccounts', reply: { result: ACCOUNTS } }]);
});
it('passes the addresses through', () => {
return instance.importGethAccounts(ACCOUNTS).then((result) => {
expect(scope.body['parity_importGethAccounts'].params).to.deep.equal([ACCOUNTS]);
});
});
});
describe('minGasPrice', () => { describe('minGasPrice', () => {
it('returns the min gasprice, formatted', () => { it('returns the min gasprice, formatted', () => {
mockHttp([{ method: 'parity_minGasPrice', reply: { result: '0x123456' } }]); mockHttp([{ method: 'parity_minGasPrice', reply: { result: '0x123456' } }]);

View File

@ -27,7 +27,7 @@ export default class AccountDetailsGeth extends Component {
} }
render () { render () {
const { gethAddresses } = this.props.store; const { gethImported } = this.props.store;
return ( return (
<div> <div>
@ -36,12 +36,12 @@ export default class AccountDetailsGeth extends Component {
id='createAccount.accountDetailsGeth.imported' id='createAccount.accountDetailsGeth.imported'
defaultMessage='You have imported {number} addresses from the Geth keystore:' defaultMessage='You have imported {number} addresses from the Geth keystore:'
values={ { values={ {
number: gethAddresses.length number: gethImported.length
} } } }
/> />
</div> </div>
<div className={ styles.address }> <div className={ styles.address }>
{ this.formatAddresses(gethAddresses) } { this.formatAddresses(gethImported) }
</div> </div>
</div> </div>
); );

View File

@ -35,7 +35,7 @@ function createApi () {
}, },
parity: { parity: {
generateSecretPhrase: sinon.stub().resolves('some account phrase'), generateSecretPhrase: sinon.stub().resolves('some account phrase'),
importGethAccounts: sinon.stub().resolves(), importGethAccounts: sinon.stub().resolves(GETH_ADDRESSES),
listGethAccounts: sinon.stub().resolves(GETH_ADDRESSES), listGethAccounts: sinon.stub().resolves(GETH_ADDRESSES),
newAccountFromPhrase: sinon.stub().resolves(ADDRESS), newAccountFromPhrase: sinon.stub().resolves(ADDRESS),
newAccountFromSecret: sinon.stub().resolves(ADDRESS), newAccountFromSecret: sinon.stub().resolves(ADDRESS),

View File

@ -32,6 +32,7 @@ export default class Store {
@observable description = ''; @observable description = '';
@observable gethAccountsAvailable = []; @observable gethAccountsAvailable = [];
@observable gethAddresses = []; @observable gethAddresses = [];
@observable gethImported = [];
@observable isBusy = false; @observable isBusy = false;
@observable isWindowsPhrase = false; @observable isWindowsPhrase = false;
@observable name = ''; @observable name = '';
@ -124,6 +125,10 @@ export default class Store {
this.gethAccountsAvailable = [].concat(gethAccountsAvailable); this.gethAccountsAvailable = [].concat(gethAccountsAvailable);
} }
@action setGethImported = (gethImported) => {
this.gethImported = gethImported;
}
@action setWindowsPhrase = (isWindowsPhrase = false) => { @action setWindowsPhrase = (isWindowsPhrase = false) => {
this.isWindowsPhrase = isWindowsPhrase; this.isWindowsPhrase = isWindowsPhrase;
} }
@ -234,20 +239,23 @@ export default class Store {
createAccountFromGeth = (timestamp = Date.now()) => { createAccountFromGeth = (timestamp = Date.now()) => {
return this._api.parity return this._api.parity
.importGethAccounts(this.gethAddresses.peek()) .importGethAccounts(this.gethAddresses.peek())
.then(() => { .then((gethImported) => {
return Promise.all(this.gethAddresses.map((address) => { console.log('createAccountFromGeth', gethImported);
return this._api.parity.setAccountName(address, 'Geth Import');
})); this.setGethImported(gethImported);
})
.then(() => { return Promise
return Promise.all(this.gethAddresses.map((address) => { .all(gethImported.map((address) => {
return this._api.parity.setAccountMeta(address, { return this._api.parity.setAccountName(address, 'Geth Import');
timestamp }))
.then(() => {
return Promise.all(gethImported.map((address) => {
return this._api.parity.setAccountMeta(address, { timestamp });
}));
}); });
}));
}) })
.catch((error) => { .catch((error) => {
console.error('createAccount', error); console.error('createAccountFromGeth', error);
throw error; throw error;
}); });
} }