fix mocha testing!
This commit is contained in:
parent
d4b2ac1ad4
commit
b382e2b99f
10 changed files with 305 additions and 221 deletions
|
|
@ -11,9 +11,11 @@ var config = {
|
|||
requiredCopayers: 2,
|
||||
totalCopayers: 3,
|
||||
},
|
||||
insight: {
|
||||
host: 'localhost',
|
||||
port: 3001
|
||||
blockchain: {
|
||||
host: 'test.insight.is',
|
||||
port: 80
|
||||
// host: 'localhost',
|
||||
// port: 3001
|
||||
},
|
||||
verbose: 1,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ angular.module('copay.home').controller('HomeController',
|
|||
$location.path('signin');
|
||||
}
|
||||
else {
|
||||
$scope.addrs = $rootScope.wallet.publicKeyRing.getAddresses();
|
||||
$scope.addrs = $rootScope.wallet.getAddressesStr();
|
||||
$scope.selectedAddr = $scope.addrs[0];
|
||||
}
|
||||
|
||||
$scope.newAddr = function() {
|
||||
var a = $rootScope.wallet.generateAddress();
|
||||
$scope.addrs.push({ addrStr: a.toString('hex') });
|
||||
$scope.addrs.push({ addrStr: a.toString() });
|
||||
};
|
||||
|
||||
$scope.selectAddr = function(addr) {
|
||||
|
|
|
|||
|
|
@ -16,29 +16,22 @@ angular.module('copay.send').controller('SendController',
|
|||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
||||
|
||||
// From @cmgustavo's wallet
|
||||
var unspentTest = [{
|
||||
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
||||
"vout": 1,
|
||||
"amount": 10,
|
||||
"confirmations":7
|
||||
}];
|
||||
w.listUnspent(function (unspentTest) {
|
||||
console.log('[send.js.19:unspentTest:]',unspentTest); //TODO
|
||||
|
||||
unspentTest[0].address = pkr.generateAddress(false).toString();
|
||||
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(false);
|
||||
|
||||
console.log('[send.js.29:txp:] BEFORE',txp); //TODO
|
||||
|
||||
txp.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'123456789',
|
||||
unspentTest,
|
||||
w.privateKey,
|
||||
opts
|
||||
);
|
||||
txp.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'123456789',
|
||||
unspentTest,
|
||||
w.privateKey,
|
||||
opts
|
||||
);
|
||||
console.log('[send.js.29:txp:] READY:',txp); //TODO
|
||||
|
||||
Network.storeOpenWallet();
|
||||
Network.sendTxProposals();
|
||||
$rootScope.$digest;
|
||||
Network.storeOpenWallet();
|
||||
Network.sendTxProposals();
|
||||
$rootScope.$digest;
|
||||
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ var bitcore = require('bitcore');
|
|||
|
||||
function Insight(opts) {
|
||||
opts = opts || {};
|
||||
this.host = 'test.insight.is';
|
||||
this.port = '80';
|
||||
this.host = opts.host || 'localhost';
|
||||
this.port = opts.port || '3001';
|
||||
this.scheme = opts.scheme || 'http';
|
||||
}
|
||||
|
||||
function _asyncForEach(array, fn, callback) {
|
||||
|
|
@ -40,7 +41,7 @@ Insight.prototype.getBalance = function(unspent) {
|
|||
Insight.prototype.listUnspent = function(addresses, cb) {
|
||||
var self = this;
|
||||
|
||||
if (!addresses || !addresses.length) return cb();
|
||||
if (!addresses || !addresses.length) return cb([]);
|
||||
|
||||
var all = [];
|
||||
|
||||
|
|
@ -48,8 +49,11 @@ Insight.prototype.listUnspent = function(addresses, cb) {
|
|||
var options = {
|
||||
host: self.host,
|
||||
port: self.port,
|
||||
scheme: self.scheme,
|
||||
method: 'GET',
|
||||
path: '/api/addr/' + addr + '/utxo'
|
||||
path: '/api/addr/' + addr + '/utxo',
|
||||
|
||||
headers: { 'Access-Control-Request-Headers' : '' }
|
||||
};
|
||||
|
||||
self._request(options, function(err, res) {
|
||||
|
|
@ -74,7 +78,6 @@ Insight.prototype.sendRawTransaction = function(rawtx, cb) {
|
|||
data: 'rawtx='+rawtx,
|
||||
headers: { 'content-type' : 'application/x-www-form-urlencoded' }
|
||||
};
|
||||
|
||||
this._request(options, function(err,res) {
|
||||
if (err) return cb();
|
||||
return cb(res.txid);
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
}
|
||||
if (!haveIt) {
|
||||
if (self.isComplete()) {
|
||||
console.log('[PublicKeyRing.js.318] REPEATED KEY', epk); //TODO
|
||||
//console.log('[PublicKeyRing.js.318] REPEATED KEY', epk); //TODO
|
||||
throw new Error('trying to add more pubkeys, when PKR isComplete at merge');
|
||||
}
|
||||
self.copayersBIP32.push(new BIP32(epk));
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ function TxProposals(opts) {
|
|||
this.walletId = opts.walletId;
|
||||
this.network = opts.networkName === 'livenet' ?
|
||||
bitcore.networks.livenet : bitcore.networks.testnet;
|
||||
this.publicKeyRing = opts.publicKeyRing;
|
||||
this.txps = [];
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +135,10 @@ TxProposals.prototype._mergeBuilder = function(myTxps, theirTxps, mergeInfo) {
|
|||
});
|
||||
};
|
||||
|
||||
TxProposals.prototype.add = function(data) {
|
||||
this.txps.push( new TxProposal(data) );
|
||||
};
|
||||
|
||||
TxProposals.prototype.merge = function(t) {
|
||||
if (this.network.name !== t.network.name)
|
||||
throw new Error('network mismatch in:', t);
|
||||
|
|
@ -157,44 +160,6 @@ TxProposals.prototype.merge = function(t) {
|
|||
return mergeInfo.stats;
|
||||
};
|
||||
|
||||
TxProposals.prototype.create = function(toAddress, amountSatStr, utxos, priv, opts) {
|
||||
var pkr = this.publicKeyRing;
|
||||
opts = opts || {};
|
||||
|
||||
var amountSat = bitcore.bignum(amountSatStr);
|
||||
|
||||
if (! pkr.isComplete() ) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
||||
var opts = {
|
||||
remainderOut: opts.remainderOut || { address: pkr.generateAddress(true).toString() }
|
||||
};
|
||||
|
||||
var b = new Builder(opts)
|
||||
.setUnspent(utxos)
|
||||
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
||||
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
||||
;
|
||||
|
||||
var signRet;
|
||||
if (priv) {
|
||||
b.sign( priv.getAll(pkr.addressIndex, pkr.changeAddressIndex) );
|
||||
}
|
||||
var me = {};
|
||||
if (priv) me[priv.id] = Date.now();
|
||||
|
||||
this.txps.push(
|
||||
new TxProposal({
|
||||
signedBy: priv && b.signaturesAdded ? me : {},
|
||||
seenBy: priv ? me : {},
|
||||
builder: b,
|
||||
})
|
||||
);
|
||||
return 1;
|
||||
};
|
||||
|
||||
TxProposals.prototype.sign = function(index) {
|
||||
};
|
||||
|
||||
module.exports = require('soop')(TxProposals);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var imports = require('soop').imports();
|
||||
|
||||
var bitcore = require('bitcore');
|
||||
var coinUtil = bitcore.util;
|
||||
var bitcore = require('bitcore');
|
||||
var coinUtil = bitcore.util;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var http = require('http');
|
||||
var Builder = bitcore.TransactionBuilder;
|
||||
var http = require('http');
|
||||
|
||||
var Storage = imports.Storage;
|
||||
var Network = imports.Network;
|
||||
var Blockchain = imports.Blockchain;
|
||||
var Storage = imports.Storage;
|
||||
var Network = imports.Network;
|
||||
var Blockchain = imports.Blockchain;
|
||||
|
||||
var copay = copay || require('../../../copay');
|
||||
var copay = copay || require('../../../copay');
|
||||
|
||||
function Wallet(config) {
|
||||
this._startInterface(config);
|
||||
|
|
@ -56,7 +57,6 @@ Wallet.prototype.create = function(opts) {
|
|||
|
||||
this.txProposals = new copay.TxProposals({
|
||||
walletId: this.id,
|
||||
publicKeyRing: this.publicKeyRing,
|
||||
networkName: this.networkName,
|
||||
});
|
||||
this.log('\t### TxProposals Initialized');
|
||||
|
|
@ -167,8 +167,56 @@ Wallet.prototype.getAddresses = function() {
|
|||
return this.publicKeyRing.getAddresses();
|
||||
};
|
||||
|
||||
Wallet.prototype.getAddressesStr = function() {
|
||||
var ret = [];
|
||||
this.publicKeyRing.getAddresses().forEach(function(a) {
|
||||
ret.push(a.toString());
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Wallet.prototype.listUnspent = function(cb) {
|
||||
this.blockchain.listUnspent(this.getAddresses(), cb);
|
||||
this.blockchain.listUnspent(this.getAddressesStr(), cb);
|
||||
};
|
||||
|
||||
Wallet.prototype.createTx = function(toAddress, amountSatStr, utxos, opts) {
|
||||
var pkr = this.publicKeyRing;
|
||||
var priv = this.privateKey;
|
||||
opts = opts || {};
|
||||
|
||||
var amountSat = bitcore.bignum(amountSatStr);
|
||||
|
||||
if (! pkr.isComplete() ) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
||||
if (!opts.remainderOut) {
|
||||
opts.remainderOut ={ address: pkr.generateAddress(true).toString() };
|
||||
};
|
||||
|
||||
var b = new Builder(opts)
|
||||
.setUnspent(utxos)
|
||||
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
||||
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
||||
;
|
||||
|
||||
var signRet;
|
||||
if (priv) {
|
||||
b.sign( priv.getAll(pkr.addressIndex, pkr.changeAddressIndex) );
|
||||
}
|
||||
var me = {};
|
||||
if (priv) me[priv.id] = Date.now();
|
||||
|
||||
this.txProposals.add({
|
||||
signedBy: priv && b.signaturesAdded ? me : {},
|
||||
seenBy: priv ? me : {},
|
||||
builder: b,
|
||||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.sign = function(txp) {
|
||||
};
|
||||
|
||||
// // HERE? not sure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue