Modify gas price statistics (#2947)
* gas price distribution + median + tests * put histogram in util * use the util histogram * remove the default gas price implementation * histogram rpc * fix empty corpus * Add JS ethcore_gasPriceHistogram * Fix typo (s/types/type/) & subsequent failing test * Fix return type & formatting * bucketBounds * Add jsapi e2e test verification
This commit is contained in:
@@ -70,6 +70,20 @@ export function outDate (date) {
|
||||
return new Date(outNumber(date).toNumber() * 1000);
|
||||
}
|
||||
|
||||
export function outHistogram (histogram) {
|
||||
if (histogram) {
|
||||
Object.keys(histogram).forEach((key) => {
|
||||
switch (key) {
|
||||
case 'bucketBounds':
|
||||
case 'counts':
|
||||
histogram[key] = histogram[key].map(outNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return histogram;
|
||||
}
|
||||
|
||||
export function outLog (log) {
|
||||
Object.keys(log).forEach((key) => {
|
||||
switch (key) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { outBlock, outAccountInfo, outAddress, outDate, outNumber, outPeers, outReceipt, outTransaction, outTrace } from './output';
|
||||
import { outBlock, outAccountInfo, outAddress, outDate, outHistogram, outNumber, outPeers, outReceipt, outTransaction, outTrace } from './output';
|
||||
import { isAddress, isBigNumber, isInstanceOf } from '../../../test/types';
|
||||
|
||||
describe('api/format/output', () => {
|
||||
@@ -120,6 +120,18 @@ describe('api/format/output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('outHistogram', () => {
|
||||
['bucketBounds', 'counts'].forEach((type) => {
|
||||
it(`formats ${type} as number arrays`, () => {
|
||||
expect(
|
||||
outHistogram({ [type]: [0x123, 0x456, 0x789] })
|
||||
).to.deep.equal({
|
||||
[type]: [new BigNumber(0x123), new BigNumber(0x456), new BigNumber(0x789)]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('outNumber', () => {
|
||||
it('returns a BigNumber equalling the value', () => {
|
||||
const bn = outNumber('0x123456');
|
||||
|
||||
@@ -27,6 +27,16 @@ describe('ethapi.ethcore', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('gasPriceHistogram', () => {
|
||||
it('returns and translates the target', () => {
|
||||
return ethapi.ethcore.gasPriceHistogram().then((result) => {
|
||||
expect(Object.keys(result)).to.deep.equal(['bucketBounds', 'counts']);
|
||||
expect(result.bucketBounds.length > 0).to.be.true;
|
||||
expect(result.counts.length > 0).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('netChain', () => {
|
||||
it('returns and the chain', () => {
|
||||
return ethapi.ethcore.netChain().then((value) => {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { inAddress, inData, inNumber16 } from '../../format/input';
|
||||
import { outAddress, outNumber, outPeers } from '../../format/output';
|
||||
import { outAddress, outHistogram, outNumber, outPeers } from '../../format/output';
|
||||
|
||||
export default class Ethcore {
|
||||
constructor (transport) {
|
||||
@@ -69,6 +69,12 @@ export default class Ethcore {
|
||||
.then(outNumber);
|
||||
}
|
||||
|
||||
gasPriceHistogram () {
|
||||
return this._transport
|
||||
.execute('ethcore_gasPriceHistogram')
|
||||
.then(outHistogram);
|
||||
}
|
||||
|
||||
generateSecretPhrase () {
|
||||
return this._transport
|
||||
.execute('ethcore_generateSecretPhrase');
|
||||
|
||||
@@ -104,6 +104,25 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
gasPriceHistogram: {
|
||||
desc: 'Returns a snapshot of the historic gas prices',
|
||||
params: [],
|
||||
returns: {
|
||||
type: Object,
|
||||
desc: 'Historic values',
|
||||
details: {
|
||||
bucketBounds: {
|
||||
type: Array,
|
||||
desc: 'Array of U256 bound values'
|
||||
},
|
||||
count: {
|
||||
type: Array,
|
||||
desc: 'Array of U64 counts'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
generateSecretPhrase: {
|
||||
desc: 'Creates a secret phrase that can be associated with an account',
|
||||
params: [],
|
||||
|
||||
Reference in New Issue
Block a user