bitcore-node
Version:
A blockchain indexing node with extended capabilities using bitcore
107 lines • 4.64 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bitcore_client_1 = require("bitcore-client");
const chai_1 = require("chai");
const config_1 = __importDefault(require("../../../src/config"));
const wallet_1 = require("../../../src/models/wallet");
const walletAddress_1 = require("../../../src/models/walletAddress");
const rpc_1 = require("../../../src/rpc");
const api_1 = require("../../../src/services/api");
const event_1 = require("../../../src/services/event");
const integration_1 = require("../../helpers/integration");
let lockedWallet;
const walletName = 'Test Wallet';
const password = 'iamsatoshi';
const chain = 'BTC';
const network = 'regtest';
const chainConfig = config_1.default.chains[chain][network];
const creds = chainConfig.rpc;
const rpc = new rpc_1.AsyncRPC(creds.username, creds.password, creds.host, creds.port);
describe('Wallet Model', function () {
const suite = this;
this.timeout(50000);
before(integration_1.intBeforeHelper);
after(async () => (0, integration_1.intAfterHelper)(suite));
before(async () => {
await event_1.Event.start();
await api_1.Api.start();
});
after(async () => {
await event_1.Event.stop();
await api_1.Api.stop();
});
describe('Wallet Create', () => {
it('should return a locked wallet on create', async () => {
const baseUrl = 'http://localhost:3000/api';
lockedWallet = await bitcore_client_1.Wallet.create({
name: walletName,
chain,
network,
baseUrl,
password
});
(0, chai_1.expect)(lockedWallet).to.have.includes({
name: walletName,
chain,
network,
baseUrl: 'http://localhost:3000/api'
});
(0, chai_1.expect)(lockedWallet).to.have.property('pubKey');
(0, chai_1.expect)(lockedWallet).to.have.property('password');
(0, chai_1.expect)(lockedWallet).to.have.property('authKey');
(0, chai_1.expect)(lockedWallet).to.have.property('encryptionKey');
const findCreatedWallet = await wallet_1.WalletStorage.collection
.find({
name: walletName,
chain,
network
})
.toArray();
(0, chai_1.expect)(findCreatedWallet[0]).to.includes({
name: walletName,
chain,
network,
path: null,
singleAddress: null
});
(0, chai_1.expect)(findCreatedWallet[0]).to.have.property('pubKey');
(0, chai_1.expect)(findCreatedWallet[0]).to.have.property('path');
(0, chai_1.expect)(findCreatedWallet[0]).to.have.property('singleAddress');
});
});
describe('Wallet functions', () => {
let address1;
it('should generate addresses using rpc then import to wallet', async () => {
address1 = await rpc.getnewaddress('');
const importAddressJSON = {
keys: [{ address: address1 }]
};
const unlockedWallet = await lockedWallet.unlock(password);
await unlockedWallet.importKeys(importAddressJSON);
const findWalletResult = await wallet_1.WalletStorage.collection.findOne({
name: walletName,
chain,
network
}, { sort: { _id: -1 } });
(0, chai_1.expect)(findWalletResult?._id).to.exist;
const findAddressResult = await walletAddress_1.WalletAddressStorage.collection
.find({
wallet: findWalletResult?._id,
chain,
network,
address: address1
})
.toArray();
(0, chai_1.expect)(findAddressResult[0]).to.exist;
(0, chai_1.expect)(findAddressResult[0]).to.have.deep.property('chain', chain);
(0, chai_1.expect)(findAddressResult[0]).to.have.deep.property('network', network);
(0, chai_1.expect)(findAddressResult[0]).to.have.deep.property('wallet', findWalletResult?._id);
(0, chai_1.expect)(findAddressResult[0]).to.have.deep.property('address', address1);
(0, chai_1.expect)(findAddressResult[0]).to.have.deep.property('processed', true);
});
});
});
//# sourceMappingURL=wallet.spec.js.map