updated
This commit is contained in:
commit
a1e5246727
44 changed files with 3762 additions and 365 deletions
|
|
@ -9,6 +9,7 @@ try {
|
|||
var copay = require('../copay'); //node
|
||||
}
|
||||
var Wallet = require('../js/models/core/Wallet');
|
||||
var Structure = copay.Structure;
|
||||
var Storage = require('./mocks/FakeStorage');
|
||||
var Network = require('./mocks/FakeNetwork');
|
||||
var Blockchain = require('./mocks/FakeBlockchain');
|
||||
|
|
@ -124,7 +125,7 @@ describe('Wallet model', function() {
|
|||
var opts = {};
|
||||
var w = cachedCreateW();
|
||||
addCopayers(w);
|
||||
w.publicKeyRing.generateAddress(false);
|
||||
w.publicKeyRing.generateAddress(false, w.publicKey);
|
||||
w.publicKeyRing.isComplete().should.equal(true);
|
||||
w.generateAddress(true).isValid().should.equal(true);
|
||||
w.generateAddress(true, function(addr) {
|
||||
|
|
@ -174,15 +175,33 @@ describe('Wallet model', function() {
|
|||
return w;
|
||||
};
|
||||
|
||||
it('#create, 1 sign', function() {
|
||||
it('#create, fail for network', function() {
|
||||
|
||||
var w = cachedCreateW2();
|
||||
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
||||
|
||||
var f = function() {
|
||||
var ntxid = w.createTxSync(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'123456789',
|
||||
null,
|
||||
unspentTest
|
||||
);
|
||||
};
|
||||
f.should.throw(Error);
|
||||
});
|
||||
|
||||
it('#create, 1 sign', function() {
|
||||
|
||||
var w = cachedCreateW2();
|
||||
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
||||
|
||||
var ntxid = w.createTxSync(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
||||
'123456789',
|
||||
null,
|
||||
unspentTest
|
||||
|
|
@ -203,11 +222,11 @@ describe('Wallet model', function() {
|
|||
var w = cachedCreateW2();
|
||||
var comment = 'This is a comment';
|
||||
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
||||
|
||||
var ntxid = w.createTxSync(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
||||
'123456789',
|
||||
comment,
|
||||
unspentTest
|
||||
|
|
@ -225,12 +244,12 @@ describe('Wallet model', function() {
|
|||
var w = cachedCreateW2();
|
||||
var comment = 'Lorem ipsum dolor sit amet, suas euismod vis te, velit deleniti vix an. Pri ex suscipit similique, inermis per';
|
||||
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
||||
|
||||
var badCreate = function() {
|
||||
w.createTxSync(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
||||
'123456789',
|
||||
comment,
|
||||
unspentTest
|
||||
|
|
@ -261,10 +280,10 @@ describe('Wallet model', function() {
|
|||
var ts = Date.now();
|
||||
for (var isChange = false; !isChange; isChange = true) {
|
||||
for (var index = 0; index < 3; index++) {
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange);
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange, w.publicKey).toString();
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange, w.publicKey);
|
||||
w.createTxSync(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
||||
'123456789',
|
||||
null,
|
||||
unspentTest
|
||||
|
|
@ -343,13 +362,15 @@ describe('Wallet model', function() {
|
|||
it('handle network indexes correctly', function() {
|
||||
var w = createW();
|
||||
var aiObj = {
|
||||
walletId: w.id,
|
||||
changeIndex: 3,
|
||||
receiveIndex: 2
|
||||
indexes: [{
|
||||
cosigner: 0,
|
||||
changeIndex: 3,
|
||||
receiveIndex: 2
|
||||
}]
|
||||
};
|
||||
w._handleIndexes('senderID', aiObj, true);
|
||||
w.publicKeyRing.indexes.getReceiveIndex(2);
|
||||
w.publicKeyRing.indexes.getChangeIndex(3);
|
||||
w.publicKeyRing.getIndex(0).getReceiveIndex(2);
|
||||
w.publicKeyRing.getIndex(0).getChangeIndex(3);
|
||||
});
|
||||
|
||||
it('handle network pubKeyRings correctly', function() {
|
||||
|
|
@ -365,19 +386,19 @@ describe('Wallet model', function() {
|
|||
networkName: w.networkName,
|
||||
requiredCopayers: w.requiredCopayers,
|
||||
totalCopayers: w.totalCopayers,
|
||||
indexes: {
|
||||
walletId: undefined,
|
||||
indexes: [{
|
||||
cosigner: 0,
|
||||
changeIndex: 2,
|
||||
receiveIndex: 3
|
||||
},
|
||||
}],
|
||||
copayersExtPubKeys: cepk,
|
||||
nicknameFor: {},
|
||||
};
|
||||
w._handlePublicKeyRing('senderID', {
|
||||
publicKeyRing: pkrObj
|
||||
}, true);
|
||||
w.publicKeyRing.indexes.getReceiveIndex(2);
|
||||
w.publicKeyRing.indexes.getChangeIndex(3);
|
||||
w.publicKeyRing.getIndex(0).getReceiveIndex(2);
|
||||
w.publicKeyRing.getIndex(0).getChangeIndex(3);
|
||||
for (var i = 0; i < w.requiredCopayers; i++) {
|
||||
w.publicKeyRing.toObj().copayersExtPubKeys[i].should.equal(cepk[i]);
|
||||
}
|
||||
|
|
@ -579,7 +600,7 @@ describe('Wallet model', function() {
|
|||
}];
|
||||
var addr = w.generateAddress().toString();
|
||||
utxo[0].address = addr;
|
||||
utxo[0].scriptPubKey = TransactionBuilder.scriptForAddress(addr).serialize().toString('hex');
|
||||
utxo[0].scriptPubKey = (new bitcore.Address(addr)).getScriptPubKey().serialize().toString('hex');
|
||||
return utxo;
|
||||
};
|
||||
var toAddress = 'mjfAe7YrzFujFf8ub5aUrCaN5GfSABdqjh';
|
||||
|
|
@ -669,8 +690,8 @@ describe('Wallet model', function() {
|
|||
|
||||
before(function() {
|
||||
w = cachedCreateW2();
|
||||
ADDRESSES_CHANGE = w.deriveAddresses(0, 20, true);
|
||||
ADDRESSES_RECEIVE = w.deriveAddresses(0, 20, false);
|
||||
ADDRESSES_CHANGE = w.deriveAddresses(0, 20, true, 0);
|
||||
ADDRESSES_RECEIVE = w.deriveAddresses(0, 20, false, 0);
|
||||
});
|
||||
|
||||
var mockFakeActivity = function(f) {
|
||||
|
|
@ -689,7 +710,7 @@ describe('Wallet model', function() {
|
|||
mockFakeActivity(function(index) {
|
||||
return false;
|
||||
});
|
||||
w.indexDiscovery(0, false, 5, function(e, lastActive) {
|
||||
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
||||
lastActive.should.equal(-1);
|
||||
done();
|
||||
});
|
||||
|
|
@ -699,7 +720,7 @@ describe('Wallet model', function() {
|
|||
mockFakeActivity(function(index) {
|
||||
return index <= 7;
|
||||
});
|
||||
w.indexDiscovery(0, false, 5, function(e, lastActive) {
|
||||
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
||||
lastActive.should.equal(7);
|
||||
done();
|
||||
});
|
||||
|
|
@ -709,7 +730,7 @@ describe('Wallet model', function() {
|
|||
mockFakeActivity(function(index) {
|
||||
return index <= 10 || index == 17;
|
||||
});
|
||||
w.indexDiscovery(0, false, 5, function(e, lastActive) {
|
||||
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
||||
lastActive.should.equal(10);
|
||||
done();
|
||||
});
|
||||
|
|
@ -719,7 +740,7 @@ describe('Wallet model', function() {
|
|||
mockFakeActivity(function(index) {
|
||||
return index <= 14 && index % 2 == 0;
|
||||
});
|
||||
w.indexDiscovery(0, false, 5, function(e, lastActive) {
|
||||
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
||||
lastActive.should.equal(14);
|
||||
done();
|
||||
});
|
||||
|
|
@ -731,8 +752,11 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
w.updateIndexes(function(err) {
|
||||
w.publicKeyRing.indexes.receiveIndex.should.equal(15);
|
||||
w.publicKeyRing.indexes.changeIndex.should.equal(15);
|
||||
w.publicKeyRing.getIndex(0).receiveIndex.should.equal(15);
|
||||
w.publicKeyRing.getIndex(0).changeIndex.should.equal(15);
|
||||
|
||||
w.publicKeyRing.getIndex(1).receiveIndex.should.equal(0);
|
||||
w.publicKeyRing.getIndex(1).changeIndex.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
@ -752,8 +776,8 @@ describe('Wallet model', function() {
|
|||
|
||||
it('#deriveAddresses', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var addresses1 = w.deriveAddresses(0, 5, false);
|
||||
var addresses2 = w.deriveAddresses(4, 5, false);
|
||||
var addresses1 = w.deriveAddresses(0, 5, false, 0);
|
||||
var addresses2 = w.deriveAddresses(4, 5, false, 0);
|
||||
|
||||
addresses1.length.should.equal(5);
|
||||
addresses2.length.should.equal(5);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue