UNPKG

@blockfrost/blockfrost-cardano-cli

Version:

Drop-in(ish) replacement for cardano-cli powered by Blockfrost

69 lines (68 loc) 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable camelcase */ const blockfrost_js_1 = require("@blockfrost/blockfrost-js"); const fs = require("fs"); const stdout_stderr_1 = require("stdout-stderr"); const blockfrostService = require("../../../services/blockfrost"); const stake_distribution_1 = require("../stake-distribution"); // import * as nock from 'nock'; // import path = require('path'); const stake_distribution_nock_test_1 = require("./__mocks__/stake-distribution-nock.test"); describe('query stake-distribution', () => { beforeEach(() => { jest .spyOn(blockfrostService, 'createBlockfrostClient') .mockImplementation((network) => { // omit check for missing env variable for project id return new blockfrost_js_1.BlockFrostAPI({ projectId: 'testnet123', network, }); }); }); afterEach(() => { jest.restoreAllMocks(); }); it('should print raw response', async () => { stdout_stderr_1.stdout.start(); (0, stake_distribution_nock_test_1.loadRecord)(); // uncomment this to export nock record (don't forget to remove createBlockfrostClient mock from beforeEach) // after export wrap the output in export const loadRecord = () => {...} // nock.recorder.rec({ // use_separator: false, // logging: content => // fs.appendFileSync(path.join(__dirname, `../__mocks__/stake-distribution-nock.test.ts`), content), // }); await stake_distribution_1.StakeDistribution.run(['--testnet', '--json']); // nock.restore(); stdout_stderr_1.stdout.stop(); const output = stdout_stderr_1.stdout.output; const poolForSanityCheck = 'pool1luenk0hazsrdj2ah6dakhv4w70xs3v46zu3zh8sdfdqav0j07un'; const result = JSON.parse(output); const pool = result.find((p) => p.pool_id === poolForSanityCheck); expect(pool).toMatchObject({ pool_id: 'pool1luenk0hazsrdj2ah6dakhv4w70xs3v46zu3zh8sdfdqav0j07un', numerator: 2106917892, denominator: 14706196085570308, }); expect(result).toMatchSnapshot(); }); it('should print pretty response', async () => { (0, stake_distribution_nock_test_1.loadRecord)(); stdout_stderr_1.stdout.start(); await stake_distribution_1.StakeDistribution.run(['--testnet']); stdout_stderr_1.stdout.stop(); const output = stdout_stderr_1.stdout.output; expect(output).toMatchSnapshot(); }); it('should save the response to --out-file', async () => { (0, stake_distribution_nock_test_1.loadRecord)(); jest.spyOn(fs, 'writeFileSync').mockImplementation((_path, _data) => { // do nothing }); await stake_distribution_1.StakeDistribution.run(['--testnet', '--out-file', 'filename']); expect(fs.writeFileSync).toHaveBeenCalledTimes(1); expect(fs.writeFileSync).toMatchSnapshot(); }); });