@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
130 lines • 5.1 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nock_1 = __importDefault(require("nock"));
const Client_1 = __importDefault(require("../../Client"));
describe('current oracle price', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/oracle/prices/current')
.reply(200, {
data: {
timestamp: '2021-08-10T18:09:48.000000Z',
price: 1549650000,
block: 959820,
},
});
it('gets the current price', async () => {
var _a;
const client = new Client_1.default();
const price = await client.oracle.getCurrentPrice();
expect((_a = price === null || price === void 0 ? void 0 : price.price) === null || _a === void 0 ? void 0 : _a.integerBalance).toBe(1549650000);
expect(price.height).toBe(959820);
expect(price.timestamp).toBe('2021-08-10T18:09:48.000000Z');
});
});
describe('listPrices', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/oracle/prices')
.reply(200, {
data: [
{
timestamp: '2021-08-10T18:09:48.000000Z',
price: 1549650000,
block: 959820,
},
{
timestamp: '2021-08-10T16:34:02.000000Z',
price: 1425951500,
block: 959740,
},
],
});
it('lists oracle prices', async () => {
var _a, _b;
const client = new Client_1.default();
const list = await client.oracle.listPrices();
const [price1, price2] = await list.take(2);
expect((_a = price1 === null || price1 === void 0 ? void 0 : price1.price) === null || _a === void 0 ? void 0 : _a.integerBalance).toBe(1549650000);
expect(price1.timestamp).toBe('2021-08-10T18:09:48.000000Z');
expect(price1.height).toBe(959820);
expect((_b = price2 === null || price2 === void 0 ? void 0 : price2.price) === null || _b === void 0 ? void 0 : _b.integerBalance).toBe(1425951500);
expect(price2.timestamp).toBe('2021-08-10T16:34:02.000000Z');
expect(price2.height).toBe(959740);
});
});
describe('oracle price at block', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/oracle/prices/385010')
.reply(200, {
data: {
timestamp: '2020-06-23T15:45:33.000000Z',
price: 42040700,
block: 385010,
},
});
it('gets the price at the specified block', async () => {
var _a;
const client = new Client_1.default();
const price = await client.oracle.getPriceAtBlock(385010);
expect((_a = price === null || price === void 0 ? void 0 : price.price) === null || _a === void 0 ? void 0 : _a.integerBalance).toBe(42040700);
expect(price.height).toBe(385010);
expect(price.timestamp).toBe('2020-06-23T15:45:33.000000Z');
});
});
describe('oracle predicted price exists', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/oracle/predictions')
.reply(200, {
data: [
{
price: 42040700,
time: 1594410146,
},
],
});
it('gets the oracle price prediction', async () => {
var _a, _b;
const client = new Client_1.default();
const price = await client.oracle.getPredictedPrice();
expect((_b = (_a = price[0]) === null || _a === void 0 ? void 0 : _a.price) === null || _b === void 0 ? void 0 : _b.integerBalance).toBe(42040700);
expect(price[0].time).toBe(1594410146);
});
});
describe('oracle predicted price has multiple values', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/oracle/predictions')
.reply(200, {
data: [
{
price: 42040700,
time: 1594410146,
},
{
price: 42040701,
time: 1594410147,
},
],
});
it('gets the first oracle price prediction', async () => {
var _a, _b;
const client = new Client_1.default();
const price = await client.oracle.getPredictedPrice();
expect(price.length).toBe(2);
expect((_b = (_a = price[0]) === null || _a === void 0 ? void 0 : _a.price) === null || _b === void 0 ? void 0 : _b.integerBalance).toBe(42040700);
expect(price[0].time).toBe(1594410146);
});
});
describe('oracle predicted price is empty', () => {
(0, nock_1.default)('https://api.helium.io').get('/v1/oracle/predictions').reply(200, {
data: [],
});
it('gets a response with empty data', async () => {
const client = new Client_1.default();
const price = await client.oracle.getPredictedPrice();
expect(price).toBeInstanceOf(Array);
expect(price.length).toBe(0);
});
});
//# sourceMappingURL=Oracle.spec.js.map