Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixing estimate gas in case histogram is not available (#4387)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and gavofyork committed Feb 1, 2017
1 parent 3bdd32f commit fb7c6c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/src/ui/GasPriceEditor/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ export default class GasPriceEditor {
@action loadDefaults () {
Promise
.all([
this._api.parity.gasPriceHistogram(),
// NOTE fetching histogram may fail if there is not enough data.
// We fallback to empty histogram.
this._api.parity.gasPriceHistogram().catch(() => ({
bucket_bounds: [],
counts: []
})),
this._api.eth.gasPrice()
])
.then(([histogram, _price]) => {
Expand Down
25 changes: 25 additions & 0 deletions js/src/ui/GasPriceEditor/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ describe('ui/GasPriceEditor/store', () => {
});
});

describe('constructor (defaults) when histogram not available', () => {
const api = {
eth: {
gasPrice: sinon.stub().resolves(GASPRICE)
},
parity: {
gasPriceHistogram: sinon.stub().rejects('Data not available')
}
};

beforeEach(() => {
store = new Store(api, { gasLimit: GASLIMIT });
});

it('retrieves the histogram and gasPrice', done => {
expect(api.eth.gasPrice).to.have.been.called;
expect(api.parity.gasPriceHistogram).to.have.been.called;

setImmediate(() => {
expect(store.histogram).not.to.be.null;
done();
});
});
});

describe('setters', () => {
beforeEach(() => {
store = new Store(null, { gasLimit: GASLIMIT });
Expand Down

0 comments on commit fb7c6c2

Please sign in to comment.