anyblock new oracle

This commit is contained in:
Alexey 2020-10-20 17:39:50 +03:00
parent 4c6acfd559
commit a05a1e62d4
3 changed files with 38 additions and 3 deletions

@ -1,6 +1,6 @@
{
"name": "gas-price-oracle",
"version": "0.2.0",
"version": "0.2.1",
"description": "Gas Price Oracle library for Ethereum dApps.",
"main": "lib/index.js",
"homepage": "https://github.com/peppersec/gas-price-oracle",

@ -55,6 +55,17 @@ const gasNow: OffChainOracle = {
additionalDataProperty: 'data',
};
const anyblock: OffChainOracle = {
name: 'anyblock',
url: 'https://api.anyblock.tools/ethereum/latest-minimum-gasprice',
instantPropertyName: 'instant',
fastPropertyName: 'fast',
standardPropertyName: 'standard',
lowPropertyName: 'slow',
denominator: 1,
additionalDataProperty: null,
};
const chainlink: OnChainOracle = {
name: 'chainlink',
callData: '0x50d25bcd',
@ -64,6 +75,7 @@ const chainlink: OnChainOracle = {
export const offChainOracles: { [key: string]: OffChainOracle } = {
ethgasstation,
anyblock,
gasNow,
poa,
etherchain,

@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-var-requires */
import { GasPrice } from '../src/types';
import { GasPrice, OffChainOracle } from '../src/types';
import mockery from 'mockery';
import chai from 'chai';
import { onChainOracles } from '../src/config';
import { onChainOracles, offChainOracles } from '../src/config';
import { GasPriceOracle } from '../src/index';
chai.use(require('chai-as-promised'));
@ -204,6 +204,29 @@ describe('fetchMedianGasPriceOffChain', function () {
});
});
describe('askOracle', function () {
it('all oracles should answer', async function () {
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
try {
const gas: GasPrice = await oracle.askOracle(o);
gas.instant.should.be.a('number');
gas.fast.should.be.a('number');
gas.standard.should.be.a('number');
gas.low.should.be.a('number');
gas.instant.should.be.at.least(gas.fast); // greater than or equal to the given number.
gas.fast.should.be.at.least(gas.standard);
gas.standard.should.be.at.least(gas.low);
gas.low.should.not.be.equal(0);
} catch (e) {
console.error(`Failed to get data from ${o.name} oracle`);
throw new Error(e);
}
}
});
});
after('after', function () {
after(function () {
mockery.disable();