UNPKG

@helium/http

Version:

HTTP library for interacting with the Helium blockchain API

183 lines 6.5 kB
"use strict"; 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 }); const nock_1 = __importDefault(require("nock")); const address_1 = __importStar(require("@helium/address")); const Client_1 = __importDefault(require("../../Client")); describe('list from account', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/accounts/my-address/roles') .reply(200, { data: [ { type: 'payment_v2', time: 1586629801, role: 'payee', height: 12345, hash: 'fake-hash-1', }, { type: 'rewards_v2', time: 1586629801, role: 'payee', height: 12345, hash: 'fake-hash-2', }, ], }); it('lists roles of recent activity for an account', async () => { const client = new Client_1.default(); const list = await client.account('my-address').roles.list(); const roles = (await list.take(2)); expect(roles[0].hash).toBe('fake-hash-1'); expect(roles[1].hash).toBe('fake-hash-2'); }); }); address_1.default.fromB58 = jest.fn(() => new address_1.default(0, address_1.NetTypes.MAINNET, 0, new Uint8Array())); describe('list from hotspot', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/hotspots/fake-hotspot-address/roles') .reply(200, { data: [ { type: 'rewards_v2', time: 1638804232, role: 'reward_gateway', height: 1127817, hash: 'fake-hash-1', }, { type: 'poc_receipts_v1', time: 1638804232, role: 'challenger', height: 1127818, hash: 'fake-hash-2', }, { type: 'poc_request_v1', time: 1638804232, role: 'challenger', height: 1127819, hash: 'fake-hash-3', }, { type: 'poc_request_v1', time: 1638804232, role: 'challenger', height: 1127820, hash: 'fake-hash-4', }, { type: 'poc_receipts_v1', time: 1638804232, role: 'challengee', height: 1127821, hash: 'fake-hash-5', }, { type: 'rewards_v2', time: 1638804232, role: 'reward_gateway', height: 1127822, hash: 'fake-hash-6', }, { type: 'poc_receipts_v1', time: 1638804232, role: 'challenger', height: 1127823, hash: 'fake-hash-7', }, ], }); it('lists roles of recent activity for a hotspot', async () => { const client = new Client_1.default(); const list = await client.hotspot('fake-hotspot-address').roles.list(); const roles = (await list.take(7)); const txn0 = roles[0]; const txn1 = roles[1]; const txn2 = roles[2]; const txn3 = roles[3]; const txn4 = roles[4]; const txn5 = roles[5]; const txn6 = roles[6]; expect(txn0.type).toBe('rewards_v2'); expect(txn1.role).toBe('challenger'); expect(txn2.height).toBe(1127819); expect(txn3.hash).toBe('fake-hash-4'); expect(txn4.role).toBe('challengee'); expect(txn5.role).toBe('reward_gateway'); expect(txn6.type).toBe('poc_receipts_v1'); }); }); describe('list from validator', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/validators/fake-validator-address/roles') .reply(200, { data: [ { type: 'validator_heartbeat_v1', time: 1638820953, role: 'validator', height: 1128100, hash: 'fake-hash-1', }, { type: 'validator_heartbeat_v1', time: 1638814204, role: 'validator', height: 1128105, hash: 'fake-hash-2', }, { type: 'validator_heartbeat_v1', time: 1638808868, role: 'validator', height: 1128110, hash: 'fake-hash-3', }, { type: 'validator_heartbeat_v1', time: 1638803130, role: 'validator', height: 1128115, hash: 'fake-hash-4', }, ], }); it('lists roles of recent activity for a validator', async () => { const client = new Client_1.default(); const list = await client.validator('fake-validator-address').roles.list(); const [txn0, txn1, txn2, txn3] = (await list.take(4)); expect(txn0.time).toBe(1638820953); expect(txn1.type).toBe('validator_heartbeat_v1'); expect(txn2.hash).toBe('fake-hash-3'); expect(txn3.hash).toBe('fake-hash-4'); }); }); //# sourceMappingURL=Roles.spec.js.map