@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
96 lines • 4.21 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.challengeFixture = void 0;
const nock_1 = __importDefault(require("nock"));
const address_1 = __importStar(require("@helium/address"));
const Client_1 = __importDefault(require("../../Client"));
address_1.default.fromB58 = jest.fn(() => new address_1.default(0, address_1.NetTypes.MAINNET, 0, new Uint8Array()));
// eslint-disable-next-line import/prefer-default-export
const challengeFixture = (params = {}) => (Object.assign({ type: 'poc_receipts_v1', time: 1589918979, signature: 'fake-sig', secret: 'fake-secret', path: [
{
witnesses: [],
receipt: {
timestamp: 1589918521291550000,
signature: 'fake-sig',
signal: 0,
origin: 'p2p',
gateway: 'fake-gateway',
data: 'bLU',
},
challengee: 'fake-challengee',
},
], onion_key_hash: 'fake-onion-key-hash', height: 339367, hash: 'fake-hash', fee: 0, challenger_owner: 'fake-challenger-owner', challenger_lon: -171.00671674931, challenger_loc: 'fake-challenger-loc', challenger_lat: 148.845751328918, challenger: 'fake-challenger' }, params));
exports.challengeFixture = challengeFixture;
describe('get', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/challenges/fake-hash')
.reply(200, {
data: (0, exports.challengeFixture)(),
});
it('retrieves a challenge by hash', async () => {
const client = new Client_1.default();
const challenge = await client.challenges.get('fake-hash');
expect(challenge.hash).toBe('fake-hash');
});
});
describe('list', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/challenges')
.reply(200, {
data: [
(0, exports.challengeFixture)({ hash: 'fake-hash-1' }),
(0, exports.challengeFixture)({ hash: 'fake-hash-2' }),
],
});
it('lists challenges', async () => {
const client = new Client_1.default();
const list = await client.challenges.list();
const challenges = await list.take(2);
expect(challenges[0].hash).toBe('fake-hash-1');
expect(challenges[1].hash).toBe('fake-hash-2');
});
});
describe('list from account', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/accounts/fake-address/challenges')
.reply(200, {
data: [
(0, exports.challengeFixture)({ hash: 'fake-hash-1' }),
(0, exports.challengeFixture)({ hash: 'fake-hash-2' }),
],
});
it('lists challenges from an account', async () => {
const client = new Client_1.default();
const list = await client.account('fake-address').challenges.list();
const challenges = await list.take(2);
expect(challenges[0].hash).toBe('fake-hash-1');
expect(challenges[1].hash).toBe('fake-hash-2');
});
});
//# sourceMappingURL=Challenges.spec.js.map