add network to address model
This commit is contained in:
parent
c7ffacac93
commit
d8524fed2a
|
@ -17,6 +17,7 @@ Address.create = function(opts) {
|
|||
x.isChange = opts.isChange;
|
||||
x.path = opts.path;
|
||||
x.publicKeys = opts.publicKeys;
|
||||
x.network = Bitcore.Address(x.address).toObject().network;
|
||||
return x;
|
||||
};
|
||||
|
||||
|
@ -26,6 +27,7 @@ Address.fromObj = function(obj) {
|
|||
x.createdOn = obj.createdOn;
|
||||
x.address = obj.address;
|
||||
x.walletId = obj.walletId;
|
||||
x.network = obj.network;
|
||||
x.isChange = obj.isChange;
|
||||
x.path = obj.path;
|
||||
x.publicKeys = obj.publicKeys;
|
||||
|
|
|
@ -84,13 +84,12 @@ WalletService.initialize = function(opts, cb) {
|
|||
|
||||
|
||||
WalletService.shutDown = function(cb) {
|
||||
if (initialized) {
|
||||
if (!initialized) return cb();
|
||||
storage.disconnect(function(err) {
|
||||
if (err) return cb(err);
|
||||
initialized = false;
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
WalletService.getInstance = function() {
|
||||
|
|
|
@ -80,10 +80,16 @@ helpers.getSignedCopayerOpts = function(opts) {
|
|||
return opts;
|
||||
};
|
||||
|
||||
helpers.createAndJoinWallet = function(m, n, cb) {
|
||||
helpers.createAndJoinWallet = function(m, n, opts, cb) {
|
||||
if (_.isFunction(opts)) {
|
||||
cb = opts;
|
||||
opts = {};
|
||||
}
|
||||
opts = opts || {};
|
||||
|
||||
var server = new WalletService();
|
||||
var copayerIds = [];
|
||||
var offset = helpers.offset || 0;
|
||||
var offset = opts.offset || 0;
|
||||
|
||||
var walletOpts = {
|
||||
name: 'a wallet',
|
||||
|
@ -241,10 +247,7 @@ describe('Wallet service', function() {
|
|||
WalletService.initialize({
|
||||
storage: storage,
|
||||
blockchainExplorer: blockchainExplorer,
|
||||
}, function() {
|
||||
helpers.offset = 0;
|
||||
done();
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
after(function(done) {
|
||||
|
@ -673,6 +676,8 @@ describe('Wallet service', function() {
|
|||
server.createAddress({}, function(err, address) {
|
||||
should.not.exist(err);
|
||||
address.should.exist;
|
||||
address.walletId.should.equal(wallet.id);
|
||||
address.network.should.equal('livenet');
|
||||
address.address.should.equal('3KxttbKQQPWmpsnXZ3rB4mgJTuLnVR7frg');
|
||||
address.isChange.should.be.false;
|
||||
address.path.should.equal('m/2147483647/0/0');
|
||||
|
@ -2138,8 +2143,9 @@ describe('Wallet service', function() {
|
|||
async.series([
|
||||
|
||||
function(next) {
|
||||
helpers.offset = 1;
|
||||
helpers.createAndJoinWallet(1, 1, function(s, w) {
|
||||
helpers.createAndJoinWallet(1, 1, {
|
||||
offset: 1
|
||||
}, function(s, w) {
|
||||
server2 = s;
|
||||
wallet2 = w;
|
||||
|
||||
|
@ -3057,10 +3063,7 @@ describe('Blockchain monitor', function() {
|
|||
WalletService.initialize({
|
||||
storage: storage,
|
||||
blockchainExplorer: blockchainExplorer,
|
||||
}, function() {
|
||||
helpers.offset = 0;
|
||||
done();
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var chai = require('chai');
|
||||
var sinon = require('sinon');
|
||||
var should = chai.should();
|
||||
|
||||
var Address = require('../../lib/model/address');
|
||||
|
||||
describe('Address', function() {
|
||||
it('should create livenet address', function() {
|
||||
var x = Address.create({
|
||||
address: '3KxttbKQQPWmpsnXZ3rB4mgJTuLnVR7frg',
|
||||
walletId: '123',
|
||||
isChange: false,
|
||||
path: 'm/0/1',
|
||||
publicKeys: ['123', '456'],
|
||||
});
|
||||
should.exist(x.createdOn);
|
||||
x.network.should.equal('livenet');
|
||||
});
|
||||
it('should create testnet address', function() {
|
||||
var x = Address.create({
|
||||
address: 'mp5xaa4uBj16DJt1fuA3D9fejHuCzeb7hj',
|
||||
walletId: '123',
|
||||
isChange: false,
|
||||
path: 'm/0/1',
|
||||
publicKeys: ['123', '456'],
|
||||
});
|
||||
x.network.should.equal('testnet');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue