Fixing estimate gas in case histogram is not available (#4387)

This commit is contained in:
Tomasz Drwięga 2017-02-01 16:18:22 +01:00 committed by Gav Wood
parent 3bdd32f9ec
commit fb7c6c2867
2 changed files with 31 additions and 1 deletions

View File

@ -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]) => {

View File

@ -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 });