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

Fixing estimate gas in case histogram is not available #4387

Merged
merged 1 commit into from
Feb 1, 2017
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
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