@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
80 lines • 4.09 kB
JavaScript
;
// Copyright 2017-2025 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const apiRegistry_1 = require("../../apiRegistry");
const sanitizeNumbers_1 = require("../../sanitize/sanitizeNumbers");
const registries_1 = require("../../test-helpers/registries");
const registries_2 = require("../../test-helpers/registries");
const mock_1 = require("../test-helpers/mock");
const referendaEntries_1 = require("../test-helpers/mock/data/referendaEntries");
const fetchOnGoingReferenda21275366_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchOnGoingReferenda21275366.json"));
const PalletsOnGoingReferendaService_1 = require("./PalletsOnGoingReferendaService");
// Mocking APIs for block #13641102
const getHeader13641102 = (_hash) => Promise.resolve().then(() => mock_1.mockBlock13641102.header);
const mockHistoricApi13641102 = {
query: {},
registry: registries_1.polkadotRegistryV9300,
};
const mockApi13641102 = {
rpc: {
chain: {
getHeader: getHeader13641102,
},
},
at: (_hash) => mockHistoricApi13641102,
};
// Mock PalletsOnGoingReferendaService instance for block #13641102
const palletsOnGoingReferendaService13641102 = new PalletsOnGoingReferendaService_1.PalletsOnGoingReferendaService('mock');
// Mocking APIs for block #21275366
const getHeader21275366 = (_hash) => Promise.resolve().then(() => mock_1.mockBlock21275366.header);
const referendaEntriesAt21275366 = () => Promise.resolve().then(() => (0, referendaEntries_1.referendaEntries)());
const mockHistoricApi21275366 = {
registry: registries_2.polkadotRegistryV1000001,
query: {
referenda: {
referendumInfoFor: {
entries: referendaEntriesAt21275366,
},
},
},
};
const mockApi21275366 = {
rpc: {
chain: {
getHeader: getHeader21275366,
},
},
at: (_hash) => mockHistoricApi21275366,
};
// Mock PalletsOnGoingReferendaService instance for block #21275366
const palletsOnGoingReferendaService21275366 = new PalletsOnGoingReferendaService_1.PalletsOnGoingReferendaService('mock');
describe('PalletOnGoingReferendaService', () => {
describe('derivePalletOnGoingReferenda', () => {
it('throws error for block 13641102', async () => {
jest.spyOn(apiRegistry_1.ApiPromiseRegistry, 'getApi').mockImplementation(() => mockApi13641102);
await expect(palletsOnGoingReferendaService13641102.derivePalletOnGoingReferenda(mock_1.blockHash13641102)).rejects.toStrictEqual(new Error(`The runtime does not include the module 'api.query.referenda' at this block height: 13641102`));
});
it('works for block 21275366 (Polkadot) & returns 7 referendas, 2 of which are runtime upgrades', async () => {
jest.spyOn(apiRegistry_1.ApiPromiseRegistry, 'getApi').mockImplementation(() => mockApi21275366);
expect((0, sanitizeNumbers_1.sanitizeNumbers)(await palletsOnGoingReferendaService21275366.derivePalletOnGoingReferenda(mock_1.blockHash21275366))).toStrictEqual(fetchOnGoingReferenda21275366_json_1.default);
});
});
});
//# sourceMappingURL=PalletsOnGoingReferendaService.spec.js.map