UNPKG

bitcoincore-node

Version:

A comprehensive Node.js package for interacting with Bitcoin Core via RPC. Create, sign, and broadcast Bitcoin transactions, manage wallets, and access blockchain data through an easy-to-use API interface. Perfect for developers building cryptocurrency ap

54 lines (53 loc) 2.49 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const BitcoinCore_1 = require("../lib/BitcoinCore"); const config = { username: 'mockuser', password: 'mockpassword', host: '127.0.0.1', port: 18332, }; describe('BitcoinCore', () => { let client; beforeEach(() => { client = new BitcoinCore_1.BitcoinCore(config); }); it('should initialize correctly with config', () => { expect(client).toBeInstanceOf(BitcoinCore_1.BitcoinCore); }); it('should call getBlockchainInfo successfully', () => __awaiter(void 0, void 0, void 0, function* () { // Mock the method const mockResponse = { chain: 'test', blocks: 1000 }; jest.spyOn(client, 'callMethod').mockResolvedValue(mockResponse); const result = yield client.blockchainRPC.getBlockchainInfo(); expect(result).toEqual(mockResponse); })); it('should throw an error if callMethod fails', () => __awaiter(void 0, void 0, void 0, function* () { jest.spyOn(client, 'callMethod').mockRejectedValue(new Error('RPC error')); yield expect(client.blockchainRPC.getBlockchainInfo()).rejects.toThrow('RPC error'); })); // it('should call sendToAddress with correct parameters', async () => { // const mockResponse = 'txid123'; // jest.spyOn(client as any, 'callMethod').mockResolvedValue(mockResponse); // const address = 'mockaddress'; // const amount = 0.5; // const result = await client.blockchainRPC.sendToAddress( // address, // amount // ); // expect(result).toBe(mockResponse); // expect(client['callMethod']).toHaveBeenCalledWith('sendtoaddress', [ // address, // amount, // ]); // }); });