Skip to content

Commit

Permalink
Merge pull request #2510 from ethereum/issue/2500
Browse files Browse the repository at this point in the history
Unhandled promise rejection of EthSendTransactionMethod fixed.
  • Loading branch information
nivida committed Mar 18, 2019
2 parents 4bd1410 + f0eb85e commit 99732d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ addons:
packages:
- g++-4.8
before_script:
- npm i -g typescript@next
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
install:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {

if (!this.parameters[0].gasPrice) {
if (!this.moduleInstance.defaultGasPrice) {
this.moduleInstance.currentProvider.send('eth_gasPrice', []).then((gasPrice) => {
this.parameters[0].gasPrice = gasPrice;
this.moduleInstance.currentProvider
.send('eth_gasPrice', [])
.then((gasPrice) => {
this.parameters[0].gasPrice = gasPrice;

this.execute();
});
this.execute();
})
.catch((error) => {
this.handleError(error, false, 0);
});

return this.promiEvent;
}
Expand All @@ -81,13 +86,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {
if (this.moduleInstance.accounts.wallet[this.parameters[0].from]) {
this.sendRawTransaction(this.moduleInstance.accounts.wallet[this.parameters[0].from].privateKey).catch(
(error) => {
if (this.callback) {
this.callback(error, null);
}

this.promiEvent.reject(error);
this.promiEvent.emit('error', error);
this.promiEvent.removeAllListeners();
this.handleError(error, false, 0);
}
);

Expand All @@ -97,13 +96,7 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {

if (this.hasCustomSigner()) {
this.sendRawTransaction().catch((error) => {
if (this.callback) {
this.callback(error, null);
}

this.promiEvent.reject(error);
this.promiEvent.emit('error', error);
this.promiEvent.removeAllListeners();
this.handleError(error, false, 0);
});

return this.promiEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,25 @@ describe('EthSendTransactionMethodTest', () => {
expect(providerMock.send).toHaveBeenNthCalledWith(1, 'eth_gasPrice', []);
});

it('calls execute and the gasPrice will be defined with "eth_gasPrice" and returns with a reject promise', async () => {
providerMock.send = jest.fn(() => {
return Promise.reject(new Error('Nope'));
});

const transaction = {
from: 0,
gas: 1,
nonce: 1,
chainId: 1
};

method.parameters = [transaction];

await expect(method.execute()).rejects.toThrow('Nope');

expect(providerMock.send).toHaveBeenNthCalledWith(1, 'eth_gasPrice', []);
});

it('calls execute and signs on the node', () => {
moduleInstanceMock.transactionSigner = transactionSignerMock;

Expand Down

0 comments on commit 99732d8

Please sign in to comment.