diff --git a/package.json b/package.json index dc331ba..ce6e576 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/config.ts b/src/config.ts index 2c3d7c4..6b8c6f7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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, diff --git a/tests/index.test.ts b/tests/index.test.ts index 3b8e2ae..9b68fa6 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -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) { + 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();