all tests BUT hardcoded imports working

This commit is contained in:
Matias Alejo Garcia 2014-07-29 13:09:47 -03:00
parent 0ee93403f3
commit 578d05e638
5 changed files with 135 additions and 134 deletions

View File

@ -39,7 +39,7 @@ HDPath.indicesForPath = function(path) {
return { return {
isChange: s[3] === '1', isChange: s[3] === '1',
index: parseInt(s[4]), index: parseInt(s[4]),
cosigner: parseInt(s[2]) copayerIndex: parseInt(s[2])
}; };
}; };

View File

@ -190,12 +190,12 @@ PublicKeyRing.prototype.getAddress = function(index, isChange, id) {
}; };
// Overloaded to receive a PubkeyString or a consigner index // Overloaded to receive a PubkeyString or a consigner index
PublicKeyRing.prototype.getIndex = function(id) { PublicKeyRing.prototype.getHDParams = function(id) {
var copayerIndex = this.getCosigner(id); var copayerIndex = this.getCosigner(id);
var index = this.indexes.filter(function(i) { return i.copayerIndex == copayerIndex }); var index = this.indexes.filter(function(i) { return i.copayerIndex == copayerIndex });
if (index.length != 1) throw new Error('no index for copayerIndex'); if (index.length != 1) throw new Error('no index for copayerIndex');
return index[0]; return index[0];
}; };
PublicKeyRing.prototype.pathForAddress = function(address) { PublicKeyRing.prototype.pathForAddress = function(address) {
@ -214,10 +214,10 @@ PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange, pubkey) {
//generate a new address, update index. //generate a new address, update index.
PublicKeyRing.prototype.generateAddress = function(isChange, pubkey) { PublicKeyRing.prototype.generateAddress = function(isChange, pubkey) {
isChange = !!isChange; isChange = !!isChange;
var addrIndex = this.getIndex(pubkey); var HDParams = this.getHDParams(pubkey);
var index = isChange ? addrIndex.getChangeIndex() : addrIndex.getReceiveIndex(); var index = isChange ? HDParams.getChangeIndex() : HDParams.getReceiveIndex();
var ret = this.getAddress(index, isChange, addrIndex.copayerIndex); var ret = this.getAddress(index, isChange, HDParams.copayerIndex);
addrIndex.increment(isChange); HDParams.increment(isChange);
return ret; return ret;
}; };
@ -393,7 +393,7 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
var hasChanged = false; var hasChanged = false;
indexes.forEach(function(theirs) { indexes.forEach(function(theirs) {
var mine = self.getIndex(theirs.copayerIndex); var mine = self.getHDParams(theirs.copayerIndex);
hasChanged |= mine.merge(theirs); hasChanged |= mine.merge(theirs);
}); });

View File

@ -118,8 +118,8 @@ describe('PublicKeyRing model', function() {
}).should.throw(); }).should.throw();
} }
w2.getIndex(k.pub).getChangeIndex().should.equal(changeN); w2.getHDParams(k.pub).getChangeIndex().should.equal(changeN);
w2.getIndex(k.pub).getReceiveIndex().should.equal(addressN); w2.getHDParams(k.pub).getReceiveIndex().should.equal(addressN);
}); });
@ -174,8 +174,8 @@ describe('PublicKeyRing model', function() {
for (var i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
w.generateAddress(false, k.pub); w.generateAddress(false, k.pub);
w.getIndex(k.pub).getChangeIndex().should.equal(3); w.getHDParams(k.pub).getChangeIndex().should.equal(3);
w.getIndex(k.pub).getReceiveIndex().should.equal(2); w.getHDParams(k.pub).getReceiveIndex().should.equal(2);
}); });
it('should set backup ready', function() { it('should set backup ready', function() {
@ -251,8 +251,8 @@ describe('PublicKeyRing model', function() {
w2.merge(w).should.equal(true); w2.merge(w).should.equal(true);
w2.requiredCopayers.should.equal(3); w2.requiredCopayers.should.equal(3);
w2.totalCopayers.should.equal(5); w2.totalCopayers.should.equal(5);
w2.getIndex(k.pub).getChangeIndex().should.equal(2); w2.getHDParams(k.pub).getChangeIndex().should.equal(2);
w2.getIndex(k.pub).getReceiveIndex().should.equal(3); w2.getHDParams(k.pub).getReceiveIndex().should.equal(3);
w2.merge(w).should.equal(false); w2.merge(w).should.equal(false);
}); });
@ -440,24 +440,24 @@ describe('PublicKeyRing model', function() {
}); });
it('#getIndex should return the right one', function() { it('#getHDParams should return the right one', function() {
var config = { var config = {
networkName: 'livenet', networkName: 'livenet',
}; };
var p = new PublicKeyRing(config); var p = new PublicKeyRing(config);
var i = p.getIndex(HDPath.SHARED_INDEX); var i = p.getHDParams(HDPath.SHARED_INDEX);
should.exist(i); should.exist(i);
i.copayerIndex.should.equal(HDPath.SHARED_INDEX); i.copayerIndex.should.equal(HDPath.SHARED_INDEX);
}); });
it('#getIndex should throw error', function() { it('#getHDParams should throw error', function() {
var config = { var config = {
networkName: 'livenet', networkName: 'livenet',
}; };
var p = new PublicKeyRing(config); var p = new PublicKeyRing(config);
(function badCosigner() { (function badCosigner() {
return p.getIndex(54); return p.getHDParams(54);
}).should.throw(); }).should.throw();
}); });

View File

@ -23,8 +23,8 @@ var TxProposals = copay.TxProposals || require('../js/models/TxProposal');
var is_browser = (typeof process == 'undefined' || typeof process.versions === 'undefined') var is_browser = (typeof process == 'undefined' || typeof process.versions === 'undefined')
var PublicKeyRing = is_browser ? copay.PublicKeyRing : var PublicKeyRing = is_browser ? copay.PublicKeyRing :
require('soop').load('../js/models/core/PublicKeyRing', { require('soop').load('../js/models/core/PublicKeyRing', {
Storage: fakeStorage Storage: fakeStorage
}); });
var config = { var config = {
networkName: 'testnet', networkName: 'testnet',
@ -73,7 +73,7 @@ var vopts = {
describe('TxProposals model', function() { describe('TxProposals model', function() {
var isChange = false; var isChange = false;
var index = 0; var addressIndex = 0;
it('verify TXs', function(done) { it('verify TXs', function(done) {
@ -94,8 +94,8 @@ describe('TxProposals model', function() {
networkName: config.networkName, networkName: config.networkName,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -109,9 +109,9 @@ describe('TxProposals model', function() {
var tx = b.build(); var tx = b.build();
tx.isComplete().should.equal(false); tx.isComplete().should.equal(false);
var ringIndex = pkr.getIndex(pub); var ringIndex = pkr.getHDParams(pub);
b.sign(priv2.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.cosigner)); b.sign(priv2.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.copayerIndex));
b.sign(priv3.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.cosigner)); b.sign(priv3.getAll(ringIndex.getReceiveIndex(), ringIndex.getChangeIndex(), ringIndex.copayerIndex));
tx = b.build(); tx = b.build();
tx.isComplete().should.equal(true); tx.isComplete().should.equal(true);
@ -152,22 +152,23 @@ describe('TxProposals model', function() {
}; };
var b = new TransactionBuilder(opts) var b = new TransactionBuilder(opts)
.setUnspent(utxos) .setUnspent(utxos)
.setOutputs([{ .setOutputs([{
address: toAddress, address: toAddress,
amountSatStr: amountSatStr, amountSatStr: amountSatStr,
}]); }]);
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address); return pkr.pathForAddress(utxo.address);
}); });
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address); return pkr.pathForAddress(utxo.address);
}); });
b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths));
var signRet; var signRet;
if (priv) { if (priv) {
var pkeys = priv.getForPaths(inputChainPaths); var pkeys = priv.getForPaths(inputChainPaths);
@ -199,8 +200,8 @@ describe('TxProposals model', function() {
var start = new Date().getTime(); var start = new Date().getTime();
var pkr = createPKR([priv]); var pkr = createPKR([priv]);
var ts = Date.now(); var ts = Date.now();
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -225,8 +226,8 @@ describe('TxProposals model', function() {
var pkr = createPKR([priv]); var pkr = createPKR([priv]);
var ts = Date.now(); var ts = Date.now();
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -274,8 +275,8 @@ describe('TxProposals model', function() {
var w = new TxProposals({ var w = new TxProposals({
networkName: config.networkName, networkName: config.networkName,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -299,8 +300,8 @@ describe('TxProposals model', function() {
networkName: config.networkName, networkName: config.networkName,
publicKeyRing: w.publicKeyRing, publicKeyRing: w.publicKeyRing,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w2.add(createTx( w2.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -375,7 +376,7 @@ describe('TxProposals model', function() {
}; };
var addressToSign = pkr.generateAddress(false, pub); var addressToSign = pkr.generateAddress(false, pub);
unspentTest[0].address = addressToSign.toString(); unspentTest[0].address = addressToSign.toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
var tx, txb; var tx, txb;
var w = new TxProposals({ var w = new TxProposals({
@ -490,8 +491,8 @@ describe('TxProposals model', function() {
var w = new TxProposals({ var w = new TxProposals({
networkName: config.networkName, networkName: config.networkName,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -511,8 +512,8 @@ describe('TxProposals model', function() {
var w2 = new TxProposals({ var w2 = new TxProposals({
networkName: config.networkName, networkName: config.networkName,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w2.add(createTx( w2.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -530,8 +531,8 @@ describe('TxProposals model', function() {
var w3 = new TxProposals({ var w3 = new TxProposals({
networkName: config.networkName, networkName: config.networkName,
}); });
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w3.add(createTx( w3.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -593,8 +594,8 @@ describe('TxProposals model', function() {
}); });
var ts = Date.now(); var ts = Date.now();
unspentTest[0].address = pkr.getAddress(index, isChange, pub).toString(); unspentTest[0].address = pkr.getAddress(addressIndex, isChange, pub).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange, pub); unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(addressIndex, isChange, pub);
w.add(createTx( w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789', '123456789',
@ -682,46 +683,46 @@ describe('TxProposals model', function() {
var txpv1 = { var txpv1 = {
"creator": "0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0", "creator": "0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0",
"createdTs": 1406310417996, "createdTs": 1406310417996,
"seenBy": { "seenBy": {
"0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0": 1406310417996, "0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0": 1406310417996,
"02ba1599c64da4d80e25985be46c50e944b65f02e2b48c930528ce763d6710158f": 1406310418162 "02ba1599c64da4d80e25985be46c50e944b65f02e2b48c930528ce763d6710158f": 1406310418162
}, },
"signedBy": { "signedBy": {
"0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0": 1406310417996, "0361fb4252367715405a0d27f99cc74a671133292e8d725e009536d7257c8c01b0": 1406310417996,
"02ba1599c64da4d80e25985be46c50e944b65f02e2b48c930528ce763d6710158f": 1406310645549 "02ba1599c64da4d80e25985be46c50e944b65f02e2b48c930528ce763d6710158f": 1406310645549
}, },
"rejectedBy": {}, "rejectedBy": {},
"sentTs": 1406310645873, "sentTs": 1406310645873,
"sentTxid": "87296c50e8601437d63d556afb27c3b8e3819214be0a9d756d401a8286c0ec43", "sentTxid": "87296c50e8601437d63d556afb27c3b8e3819214be0a9d756d401a8286c0ec43",
"inputChainPaths": ["m/45'/0/1/1"], "inputChainPaths": ["m/45'/0/1/1"],
"comment": "test 6", "comment": "test 6",
"builderObj": { "builderObj": {
"version": 1, "version": 1,
"outs": [{ "outs": [{
"address": "mph66bnLvcn9KUSMrpikUBUZZkN2C1Z5tg", "address": "mph66bnLvcn9KUSMrpikUBUZZkN2C1Z5tg",
"amountSatStr": 100 "amountSatStr": 100
}], }],
"utxos": [{ "utxos": [{
"address": "2NEodmgBa4SH3VwE2asgW34vMYe8VThBZNo", "address": "2NEodmgBa4SH3VwE2asgW34vMYe8VThBZNo",
"txid": "8f8deda12dad6248e655054632a27f6891ebb37e8d2b3dd1bff87e71fd451ac7", "txid": "8f8deda12dad6248e655054632a27f6891ebb37e8d2b3dd1bff87e71fd451ac7",
"vout": 1, "vout": 1,
"ts": 1406312717, "ts": 1406312717,
"scriptPubKey": "a914ec7bce12d0e82a7d2b5431f6d89ca70af317f5a187", "scriptPubKey": "a914ec7bce12d0e82a7d2b5431f6d89ca70af317f5a187",
"amount": 0.009798, "amount": 0.009798,
"confirmations": 0, "confirmations": 0,
"confirmationsFromCache": false "confirmationsFromCache": false
}], }],
"opts": { "opts": {
"spendUnconfirmed": true, "spendUnconfirmed": true,
"remainderOut": { "remainderOut": {
"address": "2N74XAozMH3JB3XgeBkRvRw1J8TtfLTtvny" "address": "2N74XAozMH3JB3XgeBkRvRw1J8TtfLTtvny"
}
},
"scriptSig": ["00483045022100f167ad33b8bef4c65af8d19c1a849d1770cc8d1e35bffebe6b5459dcbe655c7802207b37370b308ba668fe19f8e8bc462c9fbdc6c67f79900670758d228d83ea96da014730440220038ad3f4cc7b0738b593454ec189913ae4b442bc83da153d68d9a0077bd1b09102202b5728a08f302e97de61ea37280b48ccdd575f0d235c22f5e0ecac6a4ab0f46401475221024739614847d5233a46913482c17c6860194ad78abb3bf47de46223047d8a0b5821024c6dc65a52c5eaaa080b96888091544f8ab8712caa7e0b69ea4b45f6f059557452ae"],
"hashToScriptMap": {
"2NEodmgBa4SH3VwE2asgW34vMYe8VThBZNo": "5221024739614847d5233a46913482c17c6860194ad78abb3bf47de46223047d8a0b5821024c6dc65a52c5eaaa080b96888091544f8ab8712caa7e0b69ea4b45f6f059557452ae"
} }
},
"scriptSig": ["00483045022100f167ad33b8bef4c65af8d19c1a849d1770cc8d1e35bffebe6b5459dcbe655c7802207b37370b308ba668fe19f8e8bc462c9fbdc6c67f79900670758d228d83ea96da014730440220038ad3f4cc7b0738b593454ec189913ae4b442bc83da153d68d9a0077bd1b09102202b5728a08f302e97de61ea37280b48ccdd575f0d235c22f5e0ecac6a4ab0f46401475221024739614847d5233a46913482c17c6860194ad78abb3bf47de46223047d8a0b5821024c6dc65a52c5eaaa080b96888091544f8ab8712caa7e0b69ea4b45f6f059557452ae"],
"hashToScriptMap": {
"2NEodmgBa4SH3VwE2asgW34vMYe8VThBZNo": "5221024739614847d5233a46913482c17c6860194ad78abb3bf47de46223047d8a0b5821024c6dc65a52c5eaaa080b96888091544f8ab8712caa7e0b69ea4b45f6f059557452ae"
} }
}; }
};

View File

@ -39,7 +39,7 @@ describe('Wallet model', function() {
(function() { (function() {
new Wallet(config) new Wallet(config)
}).should. }).should.
throw(); throw();
}); });
it('should getNetworkName', function() { it('should getNetworkName', function() {
var w = cachedCreateW(); var w = cachedCreateW();
@ -266,7 +266,7 @@ describe('Wallet model', function() {
var w = cachedCreateW2(); var w = cachedCreateW2();
var l = w.getAddressesStr(); var l = w.getAddressesStr();
for (var i = 0; i < l.length; i++) for (var i = 0; i < l.length; i++)
w.addressIsOwn(l[i]).should.equal(true); w.addressIsOwn(l[i]).should.equal(true);
w.addressIsOwn(l[0], { w.addressIsOwn(l[0], {
excludeMain: true excludeMain: true
@ -315,14 +315,14 @@ describe('Wallet model', function() {
o.opts.reconnectDelay = 100; o.opts.reconnectDelay = 100;
var w2 = Wallet.fromObj(o, var w2 = Wallet.fromObj(o,
new Storage(config.storage), new Storage(config.storage),
new Network(config.network), new Network(config.network),
new Blockchain(config.blockchain)); new Blockchain(config.blockchain));
should.exist(w2); should.exist(w2);
w2.publicKeyRing.requiredCopayers.should.equal(w.publicKeyRing.requiredCopayers); w2.publicKeyRing.requiredCopayers.should.equal(w.publicKeyRing.requiredCopayers);
should.exist(w2.publicKeyRing.getCopayerId); should.exist(w2.publicKeyRing.getCopayerId);
should.exist(w2.txProposals.toObj); should.exist(w2.txProposals.toObj);
should.exist(w2.privateKey.toObj); should.exist(w2.privateKey.toObj);
}); });
it('#getSecret decodeSecret', function() { it('#getSecret decodeSecret', function() {
@ -339,15 +339,15 @@ describe('Wallet model', function() {
(function() { (function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM'); Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
}).should.not. }).should.not.
throw(); throw();
(function() { (function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK'); Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
}).should. }).should.
throw(); throw();
(function() { (function() {
Wallet.decodeSecret('12345'); Wallet.decodeSecret('12345');
}).should. }).should.
throw(); throw();
}); });
//this test fails randomly //this test fails randomly
@ -381,14 +381,14 @@ describe('Wallet model', function() {
var w = createW(); var w = createW();
var aiObj = { var aiObj = {
indexes: [{ indexes: [{
cosigner: 0, copayerIndex: 0,
changeIndex: 3, changeIndex: 3,
receiveIndex: 2 receiveIndex: 2
}] }]
}; };
w._handleIndexes('senderID', aiObj, true); w._handleIndexes('senderID', aiObj, true);
w.publicKeyRing.getIndex(0).getReceiveIndex(2); w.publicKeyRing.getHDParams(0).getReceiveIndex(2);
w.publicKeyRing.getIndex(0).getChangeIndex(3); w.publicKeyRing.getHDParams(0).getChangeIndex(3);
}); });
it('handle network pubKeyRings correctly', function() { it('handle network pubKeyRings correctly', function() {
@ -405,7 +405,7 @@ describe('Wallet model', function() {
requiredCopayers: w.requiredCopayers, requiredCopayers: w.requiredCopayers,
totalCopayers: w.totalCopayers, totalCopayers: w.totalCopayers,
indexes: [{ indexes: [{
cosigner: 0, copayerIndex: 0,
changeIndex: 2, changeIndex: 2,
receiveIndex: 3 receiveIndex: 3
}], }],
@ -415,8 +415,8 @@ describe('Wallet model', function() {
w._handlePublicKeyRing('senderID', { w._handlePublicKeyRing('senderID', {
publicKeyRing: pkrObj publicKeyRing: pkrObj
}, true); }, true);
w.publicKeyRing.getIndex(0).getReceiveIndex(2); w.publicKeyRing.getHDParams(0).getReceiveIndex(2);
w.publicKeyRing.getIndex(0).getChangeIndex(3); w.publicKeyRing.getHDParams(0).getChangeIndex(3);
for (var i = 0; i < w.requiredCopayers; i++) { for (var i = 0; i < w.requiredCopayers; i++) {
w.publicKeyRing.toObj().copayersExtPubKeys[i].should.equal(cepk[i]); w.publicKeyRing.toObj().copayersExtPubKeys[i].should.equal(cepk[i]);
} }
@ -557,21 +557,21 @@ describe('Wallet model', function() {
}); });
var roundErrorChecks = [{ var roundErrorChecks = [{
unspent: [1.0001], unspent: [1.0001],
balance: 100010000 balance: 100010000
}, { }, {
unspent: [1.0002, 1.0003, 1.0004], unspent: [1.0002, 1.0003, 1.0004],
balance: 300090000 balance: 300090000
}, { }, {
unspent: [0.000002, 1.000003, 2.000004], unspent: [0.000002, 1.000003, 2.000004],
balance: 300000900 balance: 300000900
}, { }, {
unspent: [0.0001, 0.0003], unspent: [0.0001, 0.0003],
balance: 40000 balance: 40000
}, { }, {
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002], unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
balance: 110000 balance: 110000
}, },
]; ];
var roundWallet = cachedCreateW2(); var roundWallet = cachedCreateW2();
@ -788,8 +788,8 @@ describe('Wallet model', function() {
// check updated all indexes // check updated all indexes
var cosignersChecked = [] var cosignersChecked = []
updateIndex.args.forEach(function(i) { updateIndex.args.forEach(function(i) {
cosignersChecked.indexOf(i[0].cosigner).should.equal(-1); cosignersChecked.indexOf(i[0].copayerIndex).should.equal(-1);
cosignersChecked.push(i[0].cosigner); cosignersChecked.push(i[0].copayerIndex);
}); });
sinon.assert.callCount(updateIndex, 4); sinon.assert.callCount(updateIndex, 4);
@ -810,7 +810,7 @@ describe('Wallet model', function() {
var index = { var index = {
changeIndex: 1, changeIndex: 1,
receiveIndex: 2, receiveIndex: 2,
cosigner: 2, copayerIndex: 2,
} }
w.updateIndex(index, function(err) { w.updateIndex(index, function(err) {
index.receiveIndex.should.equal(9); index.receiveIndex.should.equal(9);
@ -873,7 +873,7 @@ describe('Wallet model', function() {
(function() { (function() {
w.setAddressBook(contacts[0].address, contacts[0].label); w.setAddressBook(contacts[0].address, contacts[0].label);
}).should. }).should.
throw(); throw();
}); });
it('should show/hide everywhere', function() { it('should show/hide everywhere', function() {
@ -1049,11 +1049,11 @@ describe('Wallet model', function() {
var opts = {}; var opts = {};
opts.signhash = signhash; opts.signhash = signhash;
var txb = new TransactionBuilder(opts) var txb = new TransactionBuilder(opts)
.setUnspent(utxos) .setUnspent(utxos)
.setOutputs(outs) .setOutputs(outs)
.sign(['cVBtNonMyTydnS3NnZyipbduXo9KZfF1aUZ3uQHcvJB6UARZbiWG', .sign(['cVBtNonMyTydnS3NnZyipbduXo9KZfF1aUZ3uQHcvJB6UARZbiWG',
'cRVF68hhZp1PUQCdjr2k6aVYb2cn6uabbySDPBizAJ3PXF7vDXTL' 'cRVF68hhZp1PUQCdjr2k6aVYb2cn6uabbySDPBizAJ3PXF7vDXTL'
]); ]);
var txp = { var txp = {
'txProposal': { 'txProposal': {
'builderObj': txb.toObj() 'builderObj': txb.toObj()