Add parity_accountsInfo as available subscription (#4273)

This commit is contained in:
Jaco Greeff 2017-01-23 19:39:49 +01:00 committed by Gav Wood
parent 1c6e9bc772
commit ea44555f44
3 changed files with 26 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import Signer from './signer';
const events = { const events = {
'logging': { module: 'logging' }, 'logging': { module: 'logging' },
'eth_blockNumber': { module: 'eth' }, 'eth_blockNumber': { module: 'eth' },
'parity_accountsInfo': { module: 'personal' },
'parity_allAccountsInfo': { module: 'personal' }, 'parity_allAccountsInfo': { module: 'personal' },
'eth_accounts': { module: 'personal' }, 'eth_accounts': { module: 'personal' },
'signer_requestsToConfirm': { module: 'signer' } 'signer_requestsToConfirm': { module: 'signer' }

View File

@ -45,10 +45,14 @@ export default class Personal {
} }
_accountsInfo = () => { _accountsInfo = () => {
return this._api.parity return Promise
.allAccountsInfo() .all([
.then((info) => { this._api.parity.accountsInfo(),
this._updateSubscriptions('parity_allAccountsInfo', null, info); this._api.parity.allAccountsInfo()
])
.then(([info, allInfo]) => {
this._updateSubscriptions('parity_accountsInfo', null, info);
this._updateSubscriptions('parity_allAccountsInfo', null, allInfo);
}); });
} }

View File

@ -27,6 +27,7 @@ const TEST_LIST = ['0xfa64203C044691aA57251aF95f4b48d85eC00Dd5'];
function stubApi (accounts, info) { function stubApi (accounts, info) {
const _calls = { const _calls = {
accountsInfo: [],
allAccountsInfo: [], allAccountsInfo: [],
listAccounts: [] listAccounts: []
}; };
@ -34,6 +35,12 @@ function stubApi (accounts, info) {
return { return {
_calls, _calls,
parity: { parity: {
accountsInfo: () => {
const stub = sinon.stub().resolves(info || TEST_INFO)();
_calls.accountsInfo.push(stub);
return stub;
},
allAccountsInfo: () => { allAccountsInfo: () => {
const stub = sinon.stub().resolves(info || TEST_INFO)(); const stub = sinon.stub().resolves(info || TEST_INFO)();
@ -87,6 +94,10 @@ describe('api/subscriptions/personal', () => {
expect(personal.isStarted).to.be.true; expect(personal.isStarted).to.be.true;
}); });
it('calls parity_accountsInfo', () => {
expect(api._calls.accountsInfo.length).to.be.ok;
});
it('calls parity_allAccountsInfo', () => { it('calls parity_allAccountsInfo', () => {
expect(api._calls.allAccountsInfo.length).to.be.ok; expect(api._calls.allAccountsInfo.length).to.be.ok;
}); });
@ -97,7 +108,8 @@ describe('api/subscriptions/personal', () => {
it('updates subscribers', () => { it('updates subscribers', () => {
expect(cb.firstCall).to.have.been.calledWith('eth_accounts', null, TEST_LIST); expect(cb.firstCall).to.have.been.calledWith('eth_accounts', null, TEST_LIST);
expect(cb.secondCall).to.have.been.calledWith('parity_allAccountsInfo', null, TEST_INFO); expect(cb.secondCall).to.have.been.calledWith('parity_accountsInfo', null, TEST_INFO);
expect(cb.thirdCall).to.have.been.calledWith('parity_allAccountsInfo', null, TEST_INFO);
}); });
}); });
@ -113,6 +125,10 @@ describe('api/subscriptions/personal', () => {
}); });
it('calls personal_accountsInfo', () => { it('calls personal_accountsInfo', () => {
expect(api._calls.accountsInfo.length).to.be.ok;
});
it('calls personal_allAccountsInfo', () => {
expect(api._calls.allAccountsInfo.length).to.be.ok; expect(api._calls.allAccountsInfo.length).to.be.ok;
}); });