2014-04-10 13:57:41 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-14 08:51:56 -07:00
|
|
|
var Wallet = copay.Wallet;
|
2014-08-02 16:51:31 -07:00
|
|
|
var PrivateKey = copay.PrivateKey;
|
2014-09-17 05:42:23 -07:00
|
|
|
var Storage = copay.Storage;
|
2014-09-24 21:58:27 -07:00
|
|
|
var Network = requireMock('FakeNetwork');
|
|
|
|
var Blockchain = requireMock('FakeBlockchain');
|
|
|
|
var Builder = requireMock('FakeBuilder');
|
2014-06-09 13:28:56 -07:00
|
|
|
var TransactionBuilder = bitcore.TransactionBuilder;
|
2014-07-24 06:42:47 -07:00
|
|
|
var Transaction = bitcore.Transaction;
|
|
|
|
var Address = bitcore.Address;
|
2014-04-15 11:50:22 -07:00
|
|
|
|
2014-09-29 06:18:47 -07:00
|
|
|
|
|
|
|
function assertObjectEqual(a, b) {
|
|
|
|
Wallet.PERSISTED_PROPERTIES.forEach(function(k) {
|
|
|
|
if (a[k] && b[k]) {
|
|
|
|
_.omit(a[k], 'name').should.be.deep.equal(b[k], k + ' differs');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-21 16:04:08 -07:00
|
|
|
var walletConfig = {
|
2014-08-02 16:51:31 -07:00
|
|
|
requiredCopayers: 3,
|
|
|
|
totalCopayers: 5,
|
|
|
|
spendUnconfirmed: true,
|
|
|
|
reconnectDelay: 100,
|
|
|
|
networkName: 'testnet',
|
2014-09-24 21:58:27 -07:00
|
|
|
storage: requireMock('FakeLocalStorage').storageParams,
|
2014-10-07 14:33:55 -07:00
|
|
|
// network layer config
|
|
|
|
networkOpts: {
|
|
|
|
testnet: {
|
|
|
|
url: 'https://test-insight.bitpay.com:443',
|
|
|
|
transports: ['polling'],
|
|
|
|
},
|
|
|
|
livenet: {
|
|
|
|
url: 'https://insight.bitpay.com:443',
|
|
|
|
transports: ['polling'],
|
|
|
|
},
|
|
|
|
},
|
2014-08-02 16:51:31 -07:00
|
|
|
};
|
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
|
|
|
|
walletConfig.blockchainOpts = walletConfig.networkOpts;
|
|
|
|
|
|
|
|
|
2014-08-02 16:51:31 -07:00
|
|
|
var getNewEpk = function() {
|
|
|
|
return new PrivateKey({
|
2014-08-21 16:04:08 -07:00
|
|
|
networkName: walletConfig.networkName,
|
2014-08-22 11:44:40 -07:00
|
|
|
})
|
|
|
|
.deriveBIP45Branch()
|
|
|
|
.extendedPublicKeyString();
|
2014-08-02 16:51:31 -07:00
|
|
|
}
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
var addCopayers = function(w) {
|
|
|
|
for (var i = 0; i < 4; i++) {
|
2014-08-02 16:51:31 -07:00
|
|
|
w.publicKeyRing.addCopayer(getNewEpk());
|
2014-04-15 11:50:22 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-10 13:57:41 -07:00
|
|
|
describe('Wallet model', function() {
|
2014-04-16 17:10:04 -07:00
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('should fail to create an instance', function() {
|
|
|
|
(function() {
|
2014-08-21 16:04:08 -07:00
|
|
|
new Wallet(walletConfig)
|
2014-06-03 09:07:31 -07:00
|
|
|
}).should.
|
2014-08-22 11:44:40 -07:00
|
|
|
throw();
|
2014-04-10 13:57:41 -07:00
|
|
|
});
|
2014-06-18 06:09:40 -07:00
|
|
|
it('should getNetworkName', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW();
|
2014-06-18 06:09:40 -07:00
|
|
|
w.getNetworkName().should.equal('testnet');
|
|
|
|
});
|
2014-04-14 14:30:08 -07:00
|
|
|
|
2014-06-24 09:17:22 -07:00
|
|
|
|
2014-08-02 16:51:31 -07:00
|
|
|
var createW = function(N, conf) {
|
2014-06-09 13:52:08 -07:00
|
|
|
|
2014-08-21 16:04:08 -07:00
|
|
|
var c = JSON.parse(JSON.stringify(conf || walletConfig));
|
2014-06-09 13:52:08 -07:00
|
|
|
if (!N) N = c.totalCopayers;
|
2014-06-03 09:07:31 -07:00
|
|
|
|
2014-06-24 09:17:22 -07:00
|
|
|
var mainPrivateKey = new copay.PrivateKey({
|
2014-08-21 16:04:08 -07:00
|
|
|
networkName: walletConfig.networkName
|
2014-06-03 09:07:31 -07:00
|
|
|
});
|
2014-06-24 09:17:22 -07:00
|
|
|
var mainCopayerEPK = mainPrivateKey.deriveBIP45Branch().extendedPublicKeyString();
|
|
|
|
c.privateKey = mainPrivateKey;
|
2014-04-15 11:50:22 -07:00
|
|
|
|
2014-04-16 17:10:04 -07:00
|
|
|
c.publicKeyRing = new copay.PublicKeyRing({
|
|
|
|
networkName: c.networkName,
|
2014-06-09 13:52:08 -07:00
|
|
|
requiredCopayers: Math.min(N, c.requiredCopayers),
|
|
|
|
totalCopayers: N,
|
2014-04-16 17:10:04 -07:00
|
|
|
});
|
2014-06-24 09:17:22 -07:00
|
|
|
c.publicKeyRing.addCopayer(mainCopayerEPK);
|
2014-04-15 11:50:22 -07:00
|
|
|
|
2014-04-16 17:10:04 -07:00
|
|
|
c.txProposals = new copay.TxProposals({
|
|
|
|
networkName: c.networkName,
|
|
|
|
});
|
2014-06-24 09:17:22 -07:00
|
|
|
|
2014-08-21 16:04:08 -07:00
|
|
|
var storage = new Storage(walletConfig.storage);
|
2014-09-30 17:16:46 -07:00
|
|
|
storage._setPassphrase('xxx');
|
2014-10-07 14:33:55 -07:00
|
|
|
|
|
|
|
c.blockchain = new Blockchain(walletConfig.blockchain);
|
2014-06-24 09:17:22 -07:00
|
|
|
c.storage = storage;
|
2014-10-07 14:33:55 -07:00
|
|
|
|
|
|
|
c.network = sinon.stub();
|
|
|
|
c.network.setHexNonce = sinon.stub();
|
|
|
|
c.network.setHexNonces = sinon.stub();
|
|
|
|
c.network.getHexNonce = sinon.stub();
|
|
|
|
c.network.getHexNonces = sinon.stub();
|
|
|
|
c.network.peerFromCopayer = sinon.stub().returns('xxxx');
|
|
|
|
c.network.send = sinon.stub();
|
|
|
|
|
|
|
|
|
2014-04-16 17:10:04 -07:00
|
|
|
|
2014-06-23 06:59:33 -07:00
|
|
|
c.addressBook = {
|
|
|
|
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': {
|
2014-06-18 16:18:13 -07:00
|
|
|
label: 'John',
|
|
|
|
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
|
|
|
createdTs: 1403102115,
|
2014-07-06 21:33:39 -07:00
|
|
|
hidden: false
|
2014-06-23 06:59:33 -07:00
|
|
|
},
|
|
|
|
'2MtP8WyiwG7ZdVWM96CVsk2M1N8zyfiVQsY': {
|
2014-06-18 16:18:13 -07:00
|
|
|
label: 'Jennifer',
|
|
|
|
copayerId: '032991f836543a492bd6d0bb112552bfc7c5f3b7d5388fcbcbf2fbb893b44770d7',
|
|
|
|
createdTs: 1403103115,
|
2014-07-06 21:33:39 -07:00
|
|
|
hidden: false
|
2014-06-18 16:18:13 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-21 16:04:08 -07:00
|
|
|
c.networkName = walletConfig.networkName;
|
2014-06-03 09:07:31 -07:00
|
|
|
c.version = '0.0.1';
|
2014-04-16 17:10:04 -07:00
|
|
|
|
|
|
|
return new Wallet(c);
|
|
|
|
}
|
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var cachedW = null;
|
|
|
|
var cachedWobj = null;
|
|
|
|
var cachedCreateW = function() {
|
|
|
|
if (!cachedW) {
|
|
|
|
cachedW = createW();
|
|
|
|
cachedWobj = cachedW.toObj();
|
|
|
|
cachedWobj.opts.reconnectDelay = 100;
|
|
|
|
}
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet._newAsync = sinon.stub().returns(new Network(walletConfig.network));
|
|
|
|
Wallet._newInsight = sinon.stub().returns(new Blockchain(walletConfig.blockchain));
|
|
|
|
|
|
|
|
var w = Wallet.fromObj(cachedWobj, {
|
|
|
|
storage: cachedW.storage,
|
|
|
|
blockchainOpts: {},
|
|
|
|
networkOpts: {},
|
|
|
|
});
|
2014-06-24 17:48:05 -07:00
|
|
|
return w;
|
|
|
|
};
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('should create an instance', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW();
|
2014-04-16 17:10:04 -07:00
|
|
|
should.exist(w);
|
|
|
|
w.publicKeyRing.walletId.should.equal(w.id);
|
|
|
|
w.txProposals.walletId.should.equal(w.id);
|
|
|
|
w.requiredCopayers.should.equal(3);
|
2014-04-15 11:50:22 -07:00
|
|
|
should.exist(w.id);
|
|
|
|
should.exist(w.publicKeyRing);
|
|
|
|
should.exist(w.privateKey);
|
|
|
|
should.exist(w.txProposals);
|
2014-06-17 21:00:32 -07:00
|
|
|
should.exist(w.addressBook);
|
2014-04-15 11:50:22 -07:00
|
|
|
});
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
it('should provide some basic features', function(done) {
|
2014-04-15 11:50:22 -07:00
|
|
|
var opts = {};
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW();
|
2014-04-15 11:50:22 -07:00
|
|
|
addCopayers(w);
|
2014-07-03 07:18:01 -07:00
|
|
|
w.publicKeyRing.generateAddress(false, w.publicKey);
|
2014-04-15 11:50:22 -07:00
|
|
|
w.publicKeyRing.isComplete().should.equal(true);
|
2014-06-09 07:19:38 -07:00
|
|
|
w.generateAddress(true).isValid().should.equal(true);
|
|
|
|
w.generateAddress(true, function(addr) {
|
|
|
|
addr.isValid().should.equal(true);
|
|
|
|
done();
|
|
|
|
});
|
2014-04-14 14:30:08 -07:00
|
|
|
});
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
var unspentTest = [{
|
2014-04-15 14:23:35 -07:00
|
|
|
"address": "dummy",
|
|
|
|
"scriptPubKey": "dummy",
|
|
|
|
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
|
|
|
"vout": 1,
|
|
|
|
"amount": 10,
|
2014-06-03 09:07:31 -07:00
|
|
|
"confirmations": 7
|
|
|
|
}];
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-19 06:30:53 -07:00
|
|
|
var createW2 = function(privateKeys, N, conf) {
|
2014-06-09 13:52:08 -07:00
|
|
|
if (!N) N = 3;
|
2014-08-02 16:51:31 -07:00
|
|
|
var w = createW(N, conf);
|
2014-04-15 14:23:35 -07:00
|
|
|
should.exist(w);
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
var pkr = w.publicKeyRing;
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-13 07:30:48 -07:00
|
|
|
for (var i = 0; i < N - 1; i++) {
|
2014-04-17 13:01:31 -07:00
|
|
|
if (privateKeys) {
|
2014-06-03 09:07:31 -07:00
|
|
|
var k = privateKeys[i];
|
2014-08-02 16:51:31 -07:00
|
|
|
pkr.addCopayer(k ? k.deriveBIP45Branch().extendedPublicKeyString() : getNewEpk());
|
2014-05-29 13:18:55 -07:00
|
|
|
} else {
|
2014-08-02 16:51:31 -07:00
|
|
|
pkr.addCopayer(getNewEpk());
|
2014-05-29 13:18:55 -07:00
|
|
|
}
|
2014-04-15 14:23:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
};
|
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var cachedW2 = null;
|
|
|
|
var cachedW2obj = null;
|
|
|
|
var cachedCreateW2 = function() {
|
|
|
|
if (!cachedW2) {
|
|
|
|
cachedW2 = createW2();
|
|
|
|
cachedW2obj = cachedW2.toObj();
|
|
|
|
cachedW2obj.opts.reconnectDelay = 100;
|
|
|
|
}
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet._newAsync = sinon.stub().returns(new Network(walletConfig.network));
|
|
|
|
Wallet._newInsight = sinon.stub().returns(new Blockchain(walletConfig.blockchain));
|
|
|
|
|
|
|
|
var w = Wallet.fromObj(cachedW2obj, {
|
|
|
|
storage: cachedW2.storage,
|
|
|
|
blockchainOpts: {},
|
|
|
|
networkOpts: {},
|
|
|
|
});
|
2014-06-24 17:48:05 -07:00
|
|
|
return w;
|
|
|
|
};
|
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
|
2014-07-04 08:51:27 -07:00
|
|
|
it('#create, fail for network', function() {
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
|
|
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-07-04 08:51:27 -07:00
|
|
|
var f = function() {
|
|
|
|
var ntxid = w.createTxSync(
|
|
|
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
|
|
|
'123456789',
|
|
|
|
null,
|
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
};
|
|
|
|
f.should.throw(Error);
|
|
|
|
});
|
|
|
|
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-09-09 04:42:32 -07:00
|
|
|
it('#create, check builder opts', 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(
|
|
|
|
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
|
|
|
'123456789',
|
|
|
|
null,
|
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
var t = w.txProposals;
|
|
|
|
var opts = JSON.parse(t.txps[ntxid].builder.vanilla.opts);
|
|
|
|
opts.signhash.should.equal(1);
|
2014-09-10 11:09:11 -07:00
|
|
|
(opts.lockTime === null).should.be.true;
|
2014-09-09 04:42:32 -07:00
|
|
|
should.not.exist(opts.fee);
|
|
|
|
should.not.exist(opts.feeSat);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#create, 1 sign', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-07-03 07:18:01 -07:00
|
|
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
|
|
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-05-29 13:18:55 -07:00
|
|
|
var ntxid = w.createTxSync(
|
2014-07-04 08:51:27 -07:00
|
|
|
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
2014-06-03 09:07:31 -07:00
|
|
|
'123456789',
|
2014-06-13 06:33:30 -07:00
|
|
|
null,
|
2014-04-15 14:23:35 -07:00
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
|
|
|
|
var t = w.txProposals;
|
2014-05-29 13:18:55 -07:00
|
|
|
var txp = t.txps[ntxid];
|
2014-08-21 16:30:31 -07:00
|
|
|
Object.keys(txp._inputSigners).length.should.equal(1);
|
2014-05-29 13:18:55 -07:00
|
|
|
var tx = txp.builder.build();
|
2014-04-15 14:23:35 -07:00
|
|
|
should.exist(tx);
|
2014-06-13 06:33:30 -07:00
|
|
|
chai.expect(txp.comment).to.be.null;
|
2014-04-15 14:23:35 -07:00
|
|
|
tx.isComplete().should.equal(false);
|
2014-05-29 13:18:55 -07:00
|
|
|
Object.keys(txp.seenBy).length.should.equal(1);
|
2014-04-15 14:23:35 -07:00
|
|
|
});
|
|
|
|
|
2014-06-13 06:33:30 -07:00
|
|
|
it('#create with comment', function() {
|
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-13 06:33:30 -07:00
|
|
|
var comment = 'This is a comment';
|
|
|
|
|
2014-07-03 07:18:01 -07:00
|
|
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
|
|
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
2014-06-13 06:33:30 -07:00
|
|
|
|
|
|
|
var ntxid = w.createTxSync(
|
2014-07-04 08:51:27 -07:00
|
|
|
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
2014-06-13 06:33:30 -07:00
|
|
|
'123456789',
|
|
|
|
comment,
|
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
|
|
|
|
var t = w.txProposals;
|
|
|
|
var txp = t.txps[ntxid];
|
|
|
|
var tx = txp.builder.build();
|
|
|
|
should.exist(tx);
|
|
|
|
txp.comment.should.equal(comment);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#create throw exception on long comment', function() {
|
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-13 06:33:30 -07:00
|
|
|
var comment = 'Lorem ipsum dolor sit amet, suas euismod vis te, velit deleniti vix an. Pri ex suscipit similique, inermis per';
|
|
|
|
|
2014-07-03 07:18:01 -07:00
|
|
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
|
|
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
2014-06-13 06:33:30 -07:00
|
|
|
|
|
|
|
var badCreate = function() {
|
|
|
|
w.createTxSync(
|
2014-07-04 08:51:27 -07:00
|
|
|
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
2014-06-13 06:33:30 -07:00
|
|
|
'123456789',
|
|
|
|
comment,
|
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
chai.expect(badCreate).to.throw(Error);
|
|
|
|
});
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('#addressIsOwn', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-18 07:19:39 -07:00
|
|
|
var l = w.getAddressesStr();
|
2014-06-03 09:07:31 -07:00
|
|
|
for (var i = 0; i < l.length; i++)
|
2014-08-22 11:44:40 -07:00
|
|
|
w.addressIsOwn(l[i]).should.equal(true);
|
2014-05-01 07:04:21 -07:00
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
w.addressIsOwn(l[0], {
|
|
|
|
excludeMain: true
|
|
|
|
}).should.equal(false);
|
2014-05-01 07:04:21 -07:00
|
|
|
|
2014-04-18 07:19:39 -07:00
|
|
|
w.addressIsOwn('mmHqhvTVbxgJTnePa7cfweSRjBCy9bQQXJ').should.equal(false);
|
|
|
|
w.addressIsOwn('mgtUfP9sTJ6vPLoBxZLPEccGpcjNVryaCX').should.equal(false);
|
|
|
|
});
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('#create. Signing with derivate keys', function() {
|
2014-04-15 14:23:35 -07:00
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-15 14:23:35 -07:00
|
|
|
|
|
|
|
var ts = Date.now();
|
2014-06-24 09:17:22 -07:00
|
|
|
for (var isChange = false; !isChange; isChange = true) {
|
2014-06-03 09:07:31 -07:00
|
|
|
for (var index = 0; index < 3; index++) {
|
2014-07-03 07:18:01 -07:00
|
|
|
unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange, w.publicKey).toString();
|
|
|
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange, w.publicKey);
|
2014-04-16 17:10:04 -07:00
|
|
|
w.createTxSync(
|
2014-07-04 08:51:27 -07:00
|
|
|
'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79',
|
2014-06-03 09:07:31 -07:00
|
|
|
'123456789',
|
2014-06-13 06:33:30 -07:00
|
|
|
null,
|
2014-04-15 14:23:35 -07:00
|
|
|
unspentTest
|
|
|
|
);
|
|
|
|
var t = w.txProposals;
|
2014-04-18 15:28:28 -07:00
|
|
|
var k = Object.keys(t.txps)[0];
|
|
|
|
var tx = t.txps[k].builder.build();
|
2014-04-15 14:23:35 -07:00
|
|
|
should.exist(tx);
|
|
|
|
tx.isComplete().should.equal(false);
|
|
|
|
tx.countInputMissingSignatures(0).should.equal(2);
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
(t.txps[k].signedBy[w.privateKey.getId()] - ts > 0).should.equal(true);
|
|
|
|
(t.txps[k].seenBy[w.privateKey.getId()] - ts > 0).should.equal(true);
|
2014-04-15 14:23:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('#fromObj #toObj round trip', function() {
|
2014-04-28 08:02:43 -07:00
|
|
|
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-28 08:02:43 -07:00
|
|
|
|
|
|
|
var o = w.toObj();
|
|
|
|
o = JSON.parse(JSON.stringify(o));
|
|
|
|
|
2014-06-09 16:08:12 -07:00
|
|
|
// non stored options
|
2014-06-13 07:30:48 -07:00
|
|
|
o.opts.reconnectDelay = 100;
|
2014-06-09 16:08:12 -07:00
|
|
|
|
2014-09-17 08:10:26 -07:00
|
|
|
var s = new Storage(walletConfig.storage);
|
2014-09-30 17:16:46 -07:00
|
|
|
s._setPassphrase('xxx');
|
2014-10-07 14:33:55 -07:00
|
|
|
var w2 = Wallet.fromObj(o, {
|
|
|
|
storage: s,
|
|
|
|
blockchainOpts: {},
|
|
|
|
networkOpts: {},
|
|
|
|
});
|
2014-08-22 11:44:40 -07:00
|
|
|
should.exist(w2);
|
|
|
|
w2.publicKeyRing.requiredCopayers.should.equal(w.publicKeyRing.requiredCopayers);
|
|
|
|
should.exist(w2.publicKeyRing.getCopayerId);
|
|
|
|
should.exist(w2.txProposals.toObj);
|
|
|
|
should.exist(w2.privateKey.toObj);
|
2014-04-28 08:02:43 -07:00
|
|
|
});
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('#getSecret decodeSecret', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-04-30 08:58:40 -07:00
|
|
|
var id = w.getMyCopayerId();
|
2014-09-03 12:51:02 -07:00
|
|
|
var secretNumber = w.getSecretNumber();
|
2014-04-30 08:58:40 -07:00
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
var sb = w.getSecret();
|
2014-04-30 08:58:40 -07:00
|
|
|
should.exist(sb);
|
2014-09-03 12:51:02 -07:00
|
|
|
|
2014-04-30 08:58:40 -07:00
|
|
|
var s = Wallet.decodeSecret(sb);
|
|
|
|
s.pubKey.should.equal(id);
|
2014-09-03 12:51:02 -07:00
|
|
|
s.secretNumber.should.equal(secretNumber);
|
2014-09-09 17:08:59 -07:00
|
|
|
s.networkName.should.equal(w.getNetworkName());
|
|
|
|
});
|
2014-04-30 08:58:40 -07:00
|
|
|
|
2014-09-09 17:08:59 -07:00
|
|
|
it('#getSecret decodeSecret livenet', function() {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var stub = sinon.stub(w, 'getNetworkName');
|
|
|
|
stub.returns('livenet');
|
|
|
|
var sb = w.getSecret();
|
|
|
|
should.exist(sb);
|
|
|
|
var s = Wallet.decodeSecret(sb);
|
|
|
|
s.networkName.should.equal('livenet');
|
|
|
|
stub.restore();
|
2014-04-30 08:58:40 -07:00
|
|
|
});
|
2014-09-03 12:51:02 -07:00
|
|
|
|
|
|
|
|
2014-06-03 09:07:31 -07:00
|
|
|
it('decodeSecret check', function() {
|
2014-10-10 08:02:46 -07:00
|
|
|
var s = Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
|
|
|
|
should.exist(s);
|
2014-09-03 12:51:02 -07:00
|
|
|
|
2014-10-22 12:57:29 -07:00
|
|
|
s = Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
|
2014-10-10 08:02:46 -07:00
|
|
|
s.should.equal(false);
|
2014-09-10 11:09:11 -07:00
|
|
|
|
2014-10-10 08:02:46 -07:00
|
|
|
|
2014-10-22 12:57:29 -07:00
|
|
|
s = Wallet.decodeSecret('123456');
|
2014-10-10 08:02:46 -07:00
|
|
|
s.should.equal(false);
|
2014-06-03 09:07:31 -07:00
|
|
|
});
|
2014-06-09 06:30:37 -07:00
|
|
|
|
2014-08-21 10:12:55 -07:00
|
|
|
|
2014-08-21 10:54:38 -07:00
|
|
|
it('#maxRejectCount', function() {
|
2014-08-21 10:12:55 -07:00
|
|
|
var w = cachedCreateW();
|
|
|
|
w.maxRejectCount().should.equal(2);
|
|
|
|
});
|
|
|
|
|
2014-09-30 09:04:48 -07:00
|
|
|
describe('#getMaxRequiredCopayers', function() {
|
|
|
|
it('should return ', function() {
|
|
|
|
var validPairs = {
|
|
|
|
1: 1,
|
|
|
|
2: 2,
|
|
|
|
3: 3,
|
|
|
|
4: 4,
|
|
|
|
5: 4,
|
|
|
|
6: 3,
|
|
|
|
7: 3,
|
|
|
|
8: 2,
|
|
|
|
9: 2,
|
|
|
|
10: 2,
|
|
|
|
11: 1,
|
|
|
|
12: 1,
|
|
|
|
};
|
|
|
|
_.each(validPairs, function(maxReq, total) {
|
|
|
|
Wallet.getMaxRequiredCopayers(total).should.equal(maxReq);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2014-08-21 10:12:55 -07:00
|
|
|
|
2014-09-16 11:58:23 -07:00
|
|
|
describe('#_onData', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
var sender = '025c046aaf505a6d23203edd343132e9d4d21818b962d1e9a9c98573cc2031bfc9';
|
|
|
|
var ts = 1410810974778246;
|
|
|
|
it('should fail on message unknown', function() {
|
|
|
|
var data = {
|
|
|
|
type: "xxx",
|
|
|
|
walletId: w.id
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
w._onData(sender, data, ts);
|
|
|
|
}).should.
|
|
|
|
throw('unknown message type received: xxx from: 025c046aaf505a6d23203edd343132e9d4d21818b962d1e9a9c98573cc2031bfc9');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call sendWalletReady', function() {
|
|
|
|
var data = {
|
|
|
|
type: "walletId",
|
|
|
|
walletId: w.id
|
|
|
|
};
|
|
|
|
|
|
|
|
var spy = sinon.spy(w, 'sendWalletReady');
|
|
|
|
w._onData(sender, data, ts);
|
|
|
|
sinon.assert.callCount(spy, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-21 10:12:55 -07:00
|
|
|
describe('#purgeTxProposals', function() {
|
|
|
|
it('should delete all', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
var spy1 = sinon.spy(w.txProposals, 'deleteAll');
|
|
|
|
var spy2 = sinon.spy(w.txProposals, 'deletePending');
|
|
|
|
w.purgeTxProposals(1);
|
|
|
|
spy1.callCount.should.equal(1);
|
|
|
|
spy2.callCount.should.equal(0);
|
2014-08-21 10:54:38 -07:00
|
|
|
spy1.restore();
|
|
|
|
spy2.restore();
|
2014-08-21 10:12:55 -07:00
|
|
|
});
|
|
|
|
it('should delete pending', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
var spy1 = sinon.spy(w.txProposals, 'deleteAll');
|
|
|
|
var spy2 = sinon.spy(w.txProposals, 'deletePending');
|
|
|
|
w.purgeTxProposals();
|
|
|
|
spy1.callCount.should.equal(0);
|
|
|
|
spy2.callCount.should.equal(1);
|
2014-08-21 10:54:38 -07:00
|
|
|
spy1.restore();
|
|
|
|
spy2.restore();
|
2014-08-21 10:12:55 -07:00
|
|
|
});
|
|
|
|
it('should count deletions', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
var s = sinon.stub(w.txProposals, 'length').returns(10);
|
|
|
|
var n = w.purgeTxProposals();
|
|
|
|
n.should.equal(0);
|
2014-08-21 10:54:38 -07:00
|
|
|
s.restore();
|
2014-08-21 10:12:55 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-08 15:52:47 -07:00
|
|
|
//this test fails randomly
|
|
|
|
it.skip('call reconnect after interval', function(done) {
|
2014-06-15 21:19:21 -07:00
|
|
|
this.timeout(10000);
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-03 09:07:31 -07:00
|
|
|
var spy = sinon.spy(w, 'scheduleConnect');
|
2014-06-18 07:08:50 -07:00
|
|
|
var callCount = 3;
|
2014-06-03 09:07:31 -07:00
|
|
|
w.netStart();
|
|
|
|
setTimeout(function() {
|
2014-06-09 16:08:12 -07:00
|
|
|
sinon.assert.callCount(spy, callCount);
|
2014-06-03 09:07:31 -07:00
|
|
|
done();
|
2014-06-23 06:59:33 -07:00
|
|
|
}, w.reconnectDelay * callCount * (callCount + 1) / 2);
|
2014-04-30 08:58:40 -07:00
|
|
|
});
|
2014-06-09 06:30:37 -07:00
|
|
|
|
2014-08-04 12:27:58 -07:00
|
|
|
it('#isSingleUser', function() {
|
|
|
|
var w = createW();
|
|
|
|
w.isShared().should.equal(true);
|
|
|
|
|
|
|
|
w.totalCopayers = 1;
|
|
|
|
w.isShared().should.equal(false);
|
|
|
|
});
|
|
|
|
|
2014-08-21 10:12:55 -07:00
|
|
|
|
|
|
|
|
2014-07-08 07:52:24 -07:00
|
|
|
it('#isReady', function() {
|
|
|
|
var w = createW();
|
|
|
|
w.publicKeyRing.isComplete().should.equal(false);
|
|
|
|
w.isReady().should.equal(false);
|
|
|
|
|
|
|
|
var w2 = createW2();
|
|
|
|
w2.publicKeyRing.isComplete().should.equal(true);
|
|
|
|
w2.isReady().should.equal(false);
|
|
|
|
|
|
|
|
w2.publicKeyRing.copayersBackup = ["a", "b", "c"];
|
|
|
|
w2.publicKeyRing.isFullyBackup().should.equal(true);
|
|
|
|
w2.isReady().should.equal(true);
|
|
|
|
});
|
|
|
|
|
2014-06-09 06:30:37 -07:00
|
|
|
it('handle network indexes correctly', function() {
|
|
|
|
var w = createW();
|
|
|
|
var aiObj = {
|
2014-07-01 05:41:28 -07:00
|
|
|
indexes: [{
|
2014-07-29 09:09:47 -07:00
|
|
|
copayerIndex: 0,
|
2014-07-01 05:41:28 -07:00
|
|
|
changeIndex: 3,
|
|
|
|
receiveIndex: 2
|
|
|
|
}]
|
2014-06-09 06:30:37 -07:00
|
|
|
};
|
2014-08-19 09:50:49 -07:00
|
|
|
w._onIndexes('senderID', aiObj, true);
|
2014-07-29 09:09:47 -07:00
|
|
|
w.publicKeyRing.getHDParams(0).getReceiveIndex(2);
|
|
|
|
w.publicKeyRing.getHDParams(0).getChangeIndex(3);
|
2014-06-09 06:30:37 -07:00
|
|
|
});
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
it('handle network pubKeyRings correctly', function() {
|
2014-06-09 06:30:37 -07:00
|
|
|
var w = createW();
|
2014-06-09 16:08:12 -07:00
|
|
|
w.getNetworkName().should.equal('testnet');
|
2014-06-09 06:30:37 -07:00
|
|
|
var cepk = [
|
|
|
|
w.publicKeyRing.toObj().copayersExtPubKeys[0],
|
2014-06-09 13:28:56 -07:00
|
|
|
'tpubDEqHs8LoCB1MDfXs1y2WaLJqPkKsgt8mDoQUFsQ4aKHvho5oFJkF7UrZnfFXKMhA1MuVPwq8a5VhFHvCquYcCVHeCrW4ZCWoDDE9K95e8rP',
|
|
|
|
'tpubDEqHs8LoCB1MGGKRyouphPdFNNuay5PBzCuJkgDSiWeAST8m7y4nwPZ7M27mUNWLLPDp6n8kp4P57sd8xHXNnZvap8PxWrUMvXzkxFNgCh7',
|
2014-06-09 06:30:37 -07:00
|
|
|
];
|
|
|
|
var pkrObj = {
|
|
|
|
walletId: w.id,
|
|
|
|
networkName: w.networkName,
|
|
|
|
requiredCopayers: w.requiredCopayers,
|
|
|
|
totalCopayers: w.totalCopayers,
|
2014-07-01 05:41:28 -07:00
|
|
|
indexes: [{
|
2014-07-29 09:09:47 -07:00
|
|
|
copayerIndex: 0,
|
2014-06-09 06:30:37 -07:00
|
|
|
changeIndex: 2,
|
|
|
|
receiveIndex: 3
|
2014-07-01 05:41:28 -07:00
|
|
|
}],
|
2014-06-09 06:30:37 -07:00
|
|
|
copayersExtPubKeys: cepk,
|
|
|
|
nicknameFor: {},
|
|
|
|
};
|
2014-08-19 09:51:08 -07:00
|
|
|
w._onPublicKeyRing('senderID', {
|
2014-06-09 06:30:37 -07:00
|
|
|
publicKeyRing: pkrObj
|
|
|
|
}, true);
|
2014-07-29 09:09:47 -07:00
|
|
|
w.publicKeyRing.getHDParams(0).getReceiveIndex(2);
|
|
|
|
w.publicKeyRing.getHDParams(0).getChangeIndex(3);
|
2014-06-09 06:30:37 -07:00
|
|
|
for (var i = 0; i < w.requiredCopayers; i++) {
|
|
|
|
w.publicKeyRing.toObj().copayersExtPubKeys[i].should.equal(cepk[i]);
|
|
|
|
}
|
|
|
|
});
|
2014-06-09 07:19:38 -07:00
|
|
|
|
2014-06-09 13:28:56 -07:00
|
|
|
it('handle network txProposals correctly', function() {
|
|
|
|
var w = createW();
|
2014-06-18 06:21:26 -07:00
|
|
|
var txp = {
|
2014-06-18 06:09:40 -07:00
|
|
|
'txProposal': {
|
2014-08-04 13:12:53 -07:00
|
|
|
inputChainPaths: ['m/1'],
|
2014-07-24 17:18:38 -07:00
|
|
|
builderObj: {
|
|
|
|
version: 1,
|
|
|
|
outs: [{
|
|
|
|
address: '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
|
|
|
amountSatStr: '123456789'
|
|
|
|
}],
|
|
|
|
utxos: [{
|
|
|
|
address: '2N6fdPg2QL7V36XKe7a8wkkA5HCy7fNYmZF',
|
|
|
|
scriptPubKey: 'a91493372782bab70f4eefdefefea8ece0df44f9596887',
|
|
|
|
txid: '2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1',
|
|
|
|
vout: 1,
|
|
|
|
amount: 10,
|
|
|
|
confirmations: 7
|
2014-06-18 06:09:40 -07:00
|
|
|
}],
|
2014-07-24 17:18:38 -07:00
|
|
|
opts: {
|
|
|
|
remainderOut: {
|
|
|
|
address: '2N7BLvdrxJ4YzDtb3hfgt6CMY5rrw5kNT1H'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scriptSig: ['00493046022100b8249a4fc326c4c33882e9d5468a1c6faa01e8c6cef0a24970122e804abdd860022100dbf6ee3b07d3aad8f73997e62ad20654a08aa63a7609792d02f3d5d088e69ad9014cad5321027445ab3a935dce7aee1dadb0d103ed6147a0f83deb80474a04538b2c5bc4d5092102ab32ba51402a139873aeb919c738f5a945f3956f8f8c6ba296677bd29e85d7e821036f119b72e09f76c11ebe2cf754d64eac2cb42c9e623455d54aaa89d70c11f9c82103bcbd3f8ab2c849ea9eae434733cee8b75120d26233def56011b3682ca12081d72103f37f81dc534163b9f73ecf36b91e6c3fb8ae370c24618f91bb1d972e86ceeee255ae'],
|
|
|
|
hashToScriptMap: {
|
|
|
|
'2N6fdPg2QL7V36XKe7a8wkkA5HCy7fNYmZF': '5321027445ab3a935dce7aee1dadb0d103ed6147a0f83deb80474a04538b2c5bc4d5092102ab32ba51402a139873aeb919c738f5a945f3956f8f8c6ba296677bd29e85d7e821036f119b72e09f76c11ebe2cf754d64eac2cb42c9e623455d54aaa89d70c11f9c82103bcbd3f8ab2c849ea9eae434733cee8b75120d26233def56011b3682ca12081d72103f37f81dc534163b9f73ecf36b91e6c3fb8ae370c24618f91bb1d972e86ceeee255ae'
|
|
|
|
}
|
2014-06-18 06:09:40 -07:00
|
|
|
}
|
2014-06-09 13:28:56 -07:00
|
|
|
}
|
|
|
|
};
|
2014-07-24 17:18:38 -07:00
|
|
|
|
2014-08-22 11:44:40 -07:00
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys').returns({
|
|
|
|
'027445ab3a935dce7aee1dadb0d103ed6147a0f83deb80474a04538b2c5bc4d509': 'pepe'
|
|
|
|
});
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onTxProposal('senderID', txp, true);
|
2014-06-09 13:28:56 -07:00
|
|
|
Object.keys(w.txProposals.txps).length.should.equal(1);
|
|
|
|
w.getTxProposals().length.should.equal(1);
|
2014-08-04 13:12:53 -07:00
|
|
|
//stub.restore();
|
2014-06-09 13:28:56 -07:00
|
|
|
});
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
var newId = '00bacacafe';
|
|
|
|
it('handle new connections', function(done) {
|
|
|
|
var w = createW();
|
2014-10-07 14:33:55 -07:00
|
|
|
w.sendWalletId = sinon.stub();
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
w.on('connect', function(id) {
|
2014-10-07 14:33:55 -07:00
|
|
|
id.should.equal('xxxx');
|
2014-06-09 07:19:38 -07:00
|
|
|
done();
|
|
|
|
});
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onConnect(newId);
|
2014-06-09 07:19:38 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should register new copayers correctly', function() {
|
|
|
|
var w = createW();
|
|
|
|
var r = w.getRegisteredCopayerIds();
|
|
|
|
r.length.should.equal(1);
|
2014-08-02 16:51:31 -07:00
|
|
|
w.publicKeyRing.addCopayer(getNewEpk());
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
r = w.getRegisteredCopayerIds();
|
|
|
|
r.length.should.equal(2);
|
|
|
|
r[0].should.not.equal(r[1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should register new peers correctly', function() {
|
|
|
|
var w = createW();
|
|
|
|
var r = w.getRegisteredPeerIds();
|
|
|
|
r.length.should.equal(1);
|
2014-08-02 16:51:31 -07:00
|
|
|
w.publicKeyRing.addCopayer(getNewEpk());
|
2014-06-09 07:19:38 -07:00
|
|
|
r = w.getRegisteredPeerIds();
|
|
|
|
r.length.should.equal(2);
|
|
|
|
r[0].should.not.equal(r[1]);
|
|
|
|
});
|
2014-06-12 13:42:26 -07:00
|
|
|
|
|
|
|
it('#getBalance should call #getUnspent', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-12 13:42:26 -07:00
|
|
|
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
|
|
|
w.generateAddress();
|
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
|
|
sinon.assert.callCount(spy, 1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-06-16 08:44:18 -07:00
|
|
|
it('#getBalance should return values in satoshis', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-12 13:42:26 -07:00
|
|
|
w.generateAddress();
|
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
2014-06-16 08:44:18 -07:00
|
|
|
balance.should.equal(2500010000);
|
|
|
|
safeBalance.should.equal(2500010000);
|
|
|
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
2014-06-12 13:42:26 -07:00
|
|
|
Object.keys(balanceByAddr).length.should.equal(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-19 06:30:53 -07:00
|
|
|
it('#getUnspent should honor spendUnconfirmed = false', function(done) {
|
2014-08-21 16:04:08 -07:00
|
|
|
var conf = JSON.parse(JSON.stringify(walletConfig));
|
2014-06-19 06:30:53 -07:00
|
|
|
conf.spendUnconfirmed = false;
|
|
|
|
var w = createW2(null, null, conf);
|
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
|
|
balance.should.equal(2500010000);
|
|
|
|
safeBalance.should.equal(0);
|
|
|
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#getUnspent and spendUnconfirmed should count transactions with 1 confirmations', function(done) {
|
2014-08-21 16:04:08 -07:00
|
|
|
var conf = JSON.parse(JSON.stringify(walletConfig));
|
2014-06-19 06:30:53 -07:00
|
|
|
conf.spendUnconfirmed = false;
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2(null, null, conf);
|
2014-06-19 06:30:53 -07:00
|
|
|
w.blockchain.getUnspent = w.blockchain.getUnspent2;
|
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
|
|
balance.should.equal(2500010000);
|
|
|
|
safeBalance.should.equal(2500010000);
|
|
|
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-13 07:30:48 -07:00
|
|
|
var roundErrorChecks = [{
|
2014-08-22 11:44:40 -07:00
|
|
|
unspent: [1.0001],
|
|
|
|
balance: 100010000
|
|
|
|
}, {
|
|
|
|
unspent: [1.0002, 1.0003, 1.0004],
|
|
|
|
balance: 300090000
|
|
|
|
}, {
|
|
|
|
unspent: [0.000002, 1.000003, 2.000004],
|
|
|
|
balance: 300000900
|
|
|
|
}, {
|
|
|
|
unspent: [0.0001, 0.0003],
|
|
|
|
balance: 40000
|
|
|
|
}, {
|
|
|
|
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
|
|
|
|
balance: 110000
|
|
|
|
},
|
2014-06-13 07:30:48 -07:00
|
|
|
|
2014-06-12 13:42:26 -07:00
|
|
|
];
|
2014-06-26 06:47:39 -07:00
|
|
|
var roundWallet = cachedCreateW2();
|
2014-06-12 13:42:26 -07:00
|
|
|
|
2014-06-13 07:30:48 -07:00
|
|
|
roundErrorChecks.forEach(function(c) {
|
2014-06-26 06:47:39 -07:00
|
|
|
it('#getBalance should handle rounding errors: ' + c.unspent[0], function(done) {
|
|
|
|
var w = roundWallet;
|
|
|
|
//w.generateAddress();
|
2014-06-13 07:30:48 -07:00
|
|
|
w.blockchain.fixUnspent(c.unspent.map(function(u) {
|
|
|
|
return {
|
|
|
|
amount: u
|
|
|
|
}
|
|
|
|
}));
|
2014-06-12 13:42:26 -07:00
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
|
|
|
balance.should.equal(c.balance);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-09 07:19:38 -07:00
|
|
|
it('should get balance', function(done) {
|
2014-07-31 12:13:27 -07:00
|
|
|
var w = createW2();
|
2014-06-12 13:42:26 -07:00
|
|
|
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
2014-06-24 09:17:22 -07:00
|
|
|
w.blockchain.fixUnspent([]);
|
2014-06-09 07:19:38 -07:00
|
|
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
2014-06-12 13:42:26 -07:00
|
|
|
sinon.assert.callCount(spy, 1);
|
2014-06-09 07:19:38 -07:00
|
|
|
balance.should.equal(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-06-09 13:28:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
// tx handling
|
|
|
|
|
|
|
|
var createUTXO = function(w) {
|
|
|
|
var utxo = [{
|
2014-06-09 07:19:38 -07:00
|
|
|
'txid': '0be0fb4579911be829e3077202e1ab47fcc12cf3ab8f8487ccceae768e1f95fa',
|
|
|
|
'vout': 0,
|
|
|
|
'ts': 1402323949,
|
|
|
|
'amount': 25.0001,
|
|
|
|
'confirmations': 10,
|
|
|
|
'confirmationsFromCache': false
|
2014-06-09 13:28:56 -07:00
|
|
|
}];
|
|
|
|
var addr = w.generateAddress().toString();
|
|
|
|
utxo[0].address = addr;
|
2014-07-07 10:35:06 -07:00
|
|
|
utxo[0].scriptPubKey = (new bitcore.Address(addr)).getScriptPubKey().serialize().toString('hex');
|
2014-06-09 13:28:56 -07:00
|
|
|
return utxo;
|
|
|
|
};
|
|
|
|
var toAddress = 'mjfAe7YrzFujFf8ub5aUrCaN5GfSABdqjh';
|
2014-08-21 12:02:02 -07:00
|
|
|
var amountSatStr = '10000';
|
2014-06-09 13:28:56 -07:00
|
|
|
|
|
|
|
it('should create transaction', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-09 13:28:56 -07:00
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-06-09 07:19:38 -07:00
|
|
|
ntxid.length.should.equal(64);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-09 13:28:56 -07:00
|
|
|
});
|
2014-08-21 12:02:02 -07:00
|
|
|
|
2014-06-09 13:28:56 -07:00
|
|
|
it('should create & sign transaction from received funds', function(done) {
|
2014-08-02 16:51:31 -07:00
|
|
|
var k2 = new PrivateKey({
|
2014-08-21 16:04:08 -07:00
|
|
|
networkName: walletConfig.networkName
|
2014-08-02 16:51:31 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
var w = createW2([k2]);
|
2014-06-09 13:28:56 -07:00
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-06-09 13:28:56 -07:00
|
|
|
w.on('txProposalsUpdated', function() {
|
|
|
|
w.getTxProposals()[0].signedByUs.should.equal(true);
|
|
|
|
w.getTxProposals()[0].rejectedByUs.should.equal(false);
|
|
|
|
done();
|
|
|
|
});
|
2014-08-02 16:51:31 -07:00
|
|
|
w.privateKey = k2;
|
2014-06-09 13:28:56 -07:00
|
|
|
w.sign(ntxid, function(success) {
|
|
|
|
success.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-08-03 19:57:23 -07:00
|
|
|
it('should fail to reject a signed transaction', function() {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-08-04 08:43:21 -07:00
|
|
|
(function() {
|
|
|
|
w.reject(ntxid);
|
|
|
|
}).should.throw('reject a signed');
|
2014-08-03 19:57:23 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-09 13:28:56 -07:00
|
|
|
it('should create & reject transaction', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-08-03 19:57:23 -07:00
|
|
|
var oldK = w.privateKey;
|
2014-06-09 13:28:56 -07:00
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-08-03 19:57:23 -07:00
|
|
|
var s = sinon.stub(w, 'getMyCopayerId').returns('213');
|
2014-08-05 12:25:02 -07:00
|
|
|
Object.keys(w.txProposals.get(ntxid).rejectedBy).length.should.equal(0);
|
2014-06-09 13:28:56 -07:00
|
|
|
w.reject(ntxid);
|
2014-08-05 12:25:02 -07:00
|
|
|
Object.keys(w.txProposals.get(ntxid).rejectedBy).length.should.equal(1);
|
|
|
|
w.txProposals.get(ntxid).rejectedBy['213'].should.gt(1);
|
2014-08-03 19:57:23 -07:00
|
|
|
s.restore();
|
|
|
|
done();
|
2014-06-09 13:28:56 -07:00
|
|
|
});
|
2014-06-09 07:19:38 -07:00
|
|
|
});
|
2014-06-09 13:52:08 -07:00
|
|
|
it('should create & sign & send a transaction', function(done) {
|
|
|
|
var w = createW2(null, 1);
|
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-06-09 13:52:08 -07:00
|
|
|
w.sendTx(ntxid, function(txid) {
|
|
|
|
txid.length.should.equal(64);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-08-27 05:47:45 -07:00
|
|
|
it('should fail to send incomplete transaction', function(done) {
|
|
|
|
var w = createW2(null, 1);
|
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-08-27 05:47:45 -07:00
|
|
|
var txp = w.txProposals.get(ntxid);
|
|
|
|
// Assign fake builder
|
|
|
|
txp.builder = new Builder();
|
2014-09-10 11:09:11 -07:00
|
|
|
sinon.stub(txp.builder, 'build').returns({
|
|
|
|
isComplete: function() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
(function() {
|
2014-08-27 05:47:45 -07:00
|
|
|
w.sendTx(ntxid);
|
|
|
|
}).should.throw('Tx is not complete. Can not broadcast');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-08-27 06:36:01 -07:00
|
|
|
it('should check if transaction already sent when failing to send', function(done) {
|
|
|
|
var w = createW2(null, 1);
|
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-09-10 11:09:11 -07:00
|
|
|
sinon.stub(w.blockchain, 'broadcast').yields({
|
|
|
|
statusCode: 303
|
|
|
|
});
|
2014-08-27 06:36:01 -07:00
|
|
|
var spyCheckSentTx = sinon.spy(w, '_checkSentTx');
|
2014-09-10 11:09:11 -07:00
|
|
|
w.sendTx(ntxid, function() {});
|
2014-08-27 06:36:01 -07:00
|
|
|
chai.expect(spyCheckSentTx.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-06-18 06:09:40 -07:00
|
|
|
it('should send TxProposal', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-18 06:09:40 -07:00
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-06-18 06:21:26 -07:00
|
|
|
w.sendTxProposal.bind(w).should.throw('Illegal Argument.');
|
2014-06-18 06:09:40 -07:00
|
|
|
(function() {
|
2014-06-18 06:21:26 -07:00
|
|
|
w.sendTxProposal(ntxid);
|
|
|
|
}).should.not.throw();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-07-08 23:03:30 -07:00
|
|
|
|
2014-06-18 06:21:26 -07:00
|
|
|
it('should send all TxProposal', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-18 06:21:26 -07:00
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
2014-09-08 11:50:20 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-06-18 06:21:26 -07:00
|
|
|
w.sendAllTxProposals.bind(w).should.not.throw();
|
|
|
|
(function() {
|
|
|
|
w.sendAllTxProposals();
|
2014-06-18 06:09:40 -07:00
|
|
|
}).should.not.throw();
|
|
|
|
done();
|
|
|
|
});
|
2014-06-09 14:01:15 -07:00
|
|
|
});
|
2014-06-13 07:30:48 -07:00
|
|
|
|
2014-09-10 11:09:11 -07:00
|
|
|
describe('#createTx', function() {
|
|
|
|
it('should fail if insight server is down', function(done) {
|
2014-09-08 12:37:33 -07:00
|
|
|
var w = cachedCreateW2();
|
|
|
|
var utxo = createUTXO(w);
|
|
|
|
w.blockchain.fixUnspent(utxo);
|
|
|
|
sinon.stub(w, 'getUnspent').yields('error', null);
|
2014-09-10 11:09:11 -07:00
|
|
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
2014-09-08 12:37:33 -07:00
|
|
|
chai.expect(err.message).to.equal('Could not get list of UTXOs');
|
2014-09-10 11:09:11 -07:00
|
|
|
done();
|
2014-09-08 12:37:33 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-10 11:09:11 -07:00
|
|
|
describe('removeTxWithSpentInputs', function() {
|
2014-09-29 13:36:34 -07:00
|
|
|
var w;
|
|
|
|
var utxos;
|
|
|
|
beforeEach(function() {
|
|
|
|
w = cachedCreateW2();
|
|
|
|
w.txProposals.deleteOne = sinon.spy();
|
|
|
|
utxos = [{
|
|
|
|
txid: 'txid0',
|
|
|
|
vout: 'vout1',
|
|
|
|
}, {
|
|
|
|
txid: 'txid0',
|
|
|
|
vout: 'vout2',
|
|
|
|
}];
|
|
|
|
});
|
2014-09-04 13:37:38 -07:00
|
|
|
it('should remove pending TxProposal with spent inputs', function(done) {
|
2014-09-29 13:36:34 -07:00
|
|
|
var txp = {
|
|
|
|
ntxid: 'txid1',
|
|
|
|
isPending: true,
|
|
|
|
builder: {
|
|
|
|
utxos: [utxos[0]],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
w.getTxProposals = sinon.stub().returns([txp]);
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, utxos);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.called.should.be.false;
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, []);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.calledWith('txid1').should.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-08-27 12:42:52 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-04 13:37:38 -07:00
|
|
|
it('should remove pending TxProposal with at least 1 spent input', function(done) {
|
2014-09-29 13:36:34 -07:00
|
|
|
var txp = {
|
|
|
|
ntxid: 'txid1',
|
|
|
|
isPending: true,
|
|
|
|
builder: {
|
|
|
|
utxos: utxos,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
w.getTxProposals = sinon.stub().returns([txp]);
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, utxos);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.called.should.be.false;
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, [utxos[0]]);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.calledWith('txid1').should.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-08-27 12:42:52 -07:00
|
|
|
});
|
|
|
|
});
|
2014-09-04 13:37:38 -07:00
|
|
|
|
|
|
|
it('should not remove complete TxProposal', function(done) {
|
2014-09-29 13:36:34 -07:00
|
|
|
var txp = {
|
|
|
|
ntxid: 'txid1',
|
|
|
|
isPending: false,
|
|
|
|
builder: {
|
|
|
|
utxos: [utxos[0]],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
w.getTxProposals = sinon.stub().returns([txp]);
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, utxos);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.called.should.be.false;
|
|
|
|
w.blockchain.getUnspent = sinon.stub().yields(null, []);
|
|
|
|
w.removeTxWithSpentInputs(function() {
|
|
|
|
w.txProposals.deleteOne.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
2014-09-04 13:37:38 -07:00
|
|
|
});
|
|
|
|
});
|
2014-08-27 12:42:52 -07:00
|
|
|
});
|
|
|
|
|
2014-09-10 14:03:31 -07:00
|
|
|
describe('#subscribeToAddresses', function() {
|
|
|
|
it('should subscribe successfully', function() {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var addr1 = w.getAddresses()[0].toString();
|
|
|
|
var addr2 = w.generateAddress().toString();
|
|
|
|
var addr3 = w.generateAddress(true).toString();
|
|
|
|
chai.expect(w.getAddresses().length).to.equal(3);
|
|
|
|
|
|
|
|
w.blockchain.subscribe = sinon.spy();
|
|
|
|
w.subscribeToAddresses();
|
|
|
|
w.blockchain.subscribe.calledOnce.should.equal(true);
|
|
|
|
var arg = w.blockchain.subscribe.getCall(0).args[0];
|
|
|
|
chai.expect(_.difference(arg, [addr1, addr2, addr3]).length).to.equal(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-08 23:03:30 -07:00
|
|
|
describe('#send', function() {
|
2014-07-24 17:18:38 -07:00
|
|
|
it('should call this.network.send', function() {
|
2014-07-08 23:03:30 -07:00
|
|
|
var w = cachedCreateW2();
|
|
|
|
var save = w.network.send;
|
|
|
|
w.network.send = sinon.spy();
|
|
|
|
w.send();
|
|
|
|
w.network.send.calledOnce.should.equal(true);
|
|
|
|
w.network.send = save;
|
|
|
|
});
|
|
|
|
});
|
2014-06-25 09:06:25 -07:00
|
|
|
|
|
|
|
describe('#indexDiscovery', function() {
|
|
|
|
var ADDRESSES_CHANGE, ADDRESSES_RECEIVE, w;
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
w = cachedCreateW2();
|
2014-07-03 12:42:03 -07:00
|
|
|
ADDRESSES_CHANGE = w.deriveAddresses(0, 20, true, 0);
|
|
|
|
ADDRESSES_RECEIVE = w.deriveAddresses(0, 20, false, 0);
|
2014-06-25 09:06:25 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
var mockFakeActivity = function(f) {
|
2014-08-28 10:23:49 -07:00
|
|
|
w.blockchain.getActivity = function(addresses, cb) {
|
2014-06-25 09:06:25 -07:00
|
|
|
var activity = new Array(addresses.length);
|
|
|
|
for (var i = 0; i < addresses.length; i++) {
|
|
|
|
var a1 = ADDRESSES_CHANGE.indexOf(addresses[i]);
|
|
|
|
var a2 = ADDRESSES_RECEIVE.indexOf(addresses[i]);
|
|
|
|
activity[i] = f(Math.max(a1, a2));
|
|
|
|
}
|
|
|
|
cb(null, activity);
|
2014-06-18 10:24:48 -07:00
|
|
|
}
|
2014-06-18 06:58:34 -07:00
|
|
|
}
|
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
it('#indexDiscovery should work without found activities', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return false;
|
|
|
|
});
|
2014-07-03 12:42:03 -07:00
|
|
|
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
2014-06-25 09:06:25 -07:00
|
|
|
lastActive.should.equal(-1);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-18 06:58:34 -07:00
|
|
|
});
|
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
it('#indexDiscovery should continue scanning', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 7;
|
|
|
|
});
|
2014-07-03 12:42:03 -07:00
|
|
|
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
2014-06-25 09:06:25 -07:00
|
|
|
lastActive.should.equal(7);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-18 06:58:34 -07:00
|
|
|
});
|
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
it('#indexDiscovery should not found beyond the scannWindow', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 10 || index == 17;
|
|
|
|
});
|
2014-07-03 12:42:03 -07:00
|
|
|
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
2014-06-25 09:06:25 -07:00
|
|
|
lastActive.should.equal(10);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-18 06:58:34 -07:00
|
|
|
});
|
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
it('#indexDiscovery should look for activity along the scannWindow', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 14 && index % 2 == 0;
|
|
|
|
});
|
2014-07-03 12:42:03 -07:00
|
|
|
w.indexDiscovery(0, false, 0, 5, function(e, lastActive) {
|
2014-06-25 09:06:25 -07:00
|
|
|
lastActive.should.equal(14);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-18 06:58:34 -07:00
|
|
|
});
|
2014-06-18 10:24:48 -07:00
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
it('#updateIndexes should update correctly', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 14 && index % 2 == 0;
|
|
|
|
});
|
2014-06-18 10:24:48 -07:00
|
|
|
|
2014-07-24 17:18:38 -07:00
|
|
|
var updateIndex = sinon.stub(w, 'updateIndex', function(i, cb) {
|
|
|
|
cb();
|
|
|
|
});
|
2014-07-10 12:19:09 -07:00
|
|
|
|
2014-06-25 09:06:25 -07:00
|
|
|
w.updateIndexes(function(err) {
|
2014-07-10 12:19:09 -07:00
|
|
|
// check updated all indexes
|
|
|
|
var cosignersChecked = []
|
2014-07-24 17:18:38 -07:00
|
|
|
updateIndex.args.forEach(function(i) {
|
2014-07-29 09:09:47 -07:00
|
|
|
cosignersChecked.indexOf(i[0].copayerIndex).should.equal(-1);
|
|
|
|
cosignersChecked.push(i[0].copayerIndex);
|
2014-07-10 12:19:09 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
sinon.assert.callCount(updateIndex, 4);
|
2014-08-22 11:44:40 -07:00
|
|
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[0]);
|
|
|
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[1]);
|
|
|
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[2]);
|
2014-07-10 12:19:09 -07:00
|
|
|
w.updateIndex.restore();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-07-03 12:42:03 -07:00
|
|
|
|
2014-07-10 12:19:09 -07:00
|
|
|
it('#updateIndex should update correctly', function(done) {
|
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 14 && index % 2 == 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-24 17:18:38 -07:00
|
|
|
var indexDiscovery = sinon.stub(w, 'indexDiscovery', function(a, b, c, d, cb) {
|
|
|
|
cb(null, 8);
|
|
|
|
});
|
2014-07-10 12:19:09 -07:00
|
|
|
var index = {
|
|
|
|
changeIndex: 1,
|
|
|
|
receiveIndex: 2,
|
2014-07-29 09:09:47 -07:00
|
|
|
copayerIndex: 2,
|
2014-07-10 12:19:09 -07:00
|
|
|
}
|
|
|
|
w.updateIndex(index, function(err) {
|
|
|
|
index.receiveIndex.should.equal(9);
|
|
|
|
index.changeIndex.should.equal(9);
|
|
|
|
indexDiscovery.callCount.should.equal(2);
|
2014-08-22 11:44:40 -07:00
|
|
|
sinon.assert.calledWith(indexDiscovery, 1, true, 2, 20);
|
|
|
|
sinon.assert.calledWith(indexDiscovery, 2, false, 2, 20);
|
2014-07-10 12:19:09 -07:00
|
|
|
w.indexDiscovery.restore();
|
2014-06-25 09:06:25 -07:00
|
|
|
done();
|
|
|
|
});
|
2014-06-23 06:59:33 -07:00
|
|
|
});
|
2014-06-25 09:06:25 -07:00
|
|
|
|
2014-07-10 12:19:09 -07:00
|
|
|
|
2014-07-02 06:44:20 -07:00
|
|
|
it('#updateIndexes should store wallet', function(done) {
|
2014-06-25 09:06:25 -07:00
|
|
|
mockFakeActivity(function(index) {
|
|
|
|
return index <= 14 && index % 2 == 0;
|
|
|
|
});
|
2014-07-24 17:18:38 -07:00
|
|
|
var indexDiscovery = sinon.stub(w, 'indexDiscovery', function(a, b, c, d, cb) {
|
|
|
|
cb(null, 8);
|
|
|
|
});
|
2014-06-25 09:06:25 -07:00
|
|
|
var spyStore = sinon.spy(w, 'store');
|
|
|
|
w.updateIndexes(function(err) {
|
|
|
|
sinon.assert.callCount(spyStore, 1);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-18 10:24:48 -07:00
|
|
|
});
|
2014-06-25 09:06:25 -07:00
|
|
|
|
2014-06-18 10:24:48 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('#deriveAddresses', function(done) {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-07-03 12:42:03 -07:00
|
|
|
var addresses1 = w.deriveAddresses(0, 5, false, 0);
|
|
|
|
var addresses2 = w.deriveAddresses(4, 5, false, 0);
|
2014-06-18 10:24:48 -07:00
|
|
|
|
|
|
|
addresses1.length.should.equal(5);
|
|
|
|
addresses2.length.should.equal(5);
|
|
|
|
|
|
|
|
addresses1[4].should.equal(addresses2[0]);
|
|
|
|
done();
|
2014-06-09 14:01:15 -07:00
|
|
|
});
|
2014-06-13 07:30:48 -07:00
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
describe('#AddressBook', function() {
|
|
|
|
var contacts = [{
|
|
|
|
label: 'Charles',
|
|
|
|
address: '2N8pJWpXCAxmNLHKVEhz3TtTcYCtHd43xWU ',
|
|
|
|
}, {
|
|
|
|
label: 'Linda',
|
|
|
|
address: '2N4Zq92goYGrf5J4F4SZZq7jnPYbCiyRYT2 ',
|
|
|
|
}];
|
2014-06-17 21:00:32 -07:00
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
it('should create new entry for address book', function() {
|
|
|
|
var w = createW();
|
|
|
|
contacts.forEach(function(c) {
|
|
|
|
w.setAddressBook(c.address, c.label);
|
|
|
|
});
|
|
|
|
Object.keys(w.addressBook).length.should.equal(4);
|
2014-06-17 21:00:32 -07:00
|
|
|
});
|
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
it('should fail if create a duplicate address', function() {
|
|
|
|
var w = createW();
|
2014-06-18 16:18:13 -07:00
|
|
|
w.setAddressBook(contacts[0].address, contacts[0].label);
|
2014-07-06 21:33:39 -07:00
|
|
|
(function() {
|
|
|
|
w.setAddressBook(contacts[0].address, contacts[0].label);
|
|
|
|
}).should.
|
2014-08-22 11:44:40 -07:00
|
|
|
throw();
|
2014-07-06 21:33:39 -07:00
|
|
|
});
|
2014-06-23 06:59:33 -07:00
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
it('should show/hide everywhere', function() {
|
|
|
|
var w = createW();
|
|
|
|
var key = '2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ';
|
|
|
|
w.toggleAddressBookEntry(key);
|
|
|
|
w.addressBook[key].hidden.should.equal(true);
|
|
|
|
w.toggleAddressBookEntry(key);
|
|
|
|
w.addressBook[key].hidden.should.equal(false);
|
2014-07-24 17:18:38 -07:00
|
|
|
(function() {
|
2014-07-07 06:58:43 -07:00
|
|
|
w.toggleAddressBookEntry();
|
|
|
|
}).should.throw();
|
2014-07-06 21:33:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handle network addressBook correctly', function() {
|
|
|
|
var w = createW();
|
2014-07-07 15:12:34 -07:00
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
var data = {
|
2014-07-24 17:18:38 -07:00
|
|
|
type: "addressbook",
|
2014-07-06 21:33:39 -07:00
|
|
|
addressBook: {
|
2014-07-24 17:18:38 -07:00
|
|
|
"3Ae1ieAYNXznm7NkowoFTu5MkzgrTfDz8Z": {
|
2014-07-07 15:12:34 -07:00
|
|
|
copayerId: "03baa45498fee1045fa8f91a2913f638dc3979b455498924d3cf1a11303c679cdb",
|
|
|
|
createdTs: 1404769393509,
|
|
|
|
hidden: false,
|
|
|
|
label: "adsf",
|
|
|
|
signature: "3046022100d4cdefef66ab8cea26031d5df03a38fc9ec9b09b0fb31d3a26b6e204918e9e78022100ecdbbd889ec99ea1bfd471253487af07a7fa7c0ac6012ca56e10e66f335e4586"
|
2014-07-06 21:33:39 -07:00
|
|
|
}
|
2014-07-24 17:18:38 -07:00
|
|
|
},
|
|
|
|
walletId: "11d23e638ed84c06",
|
2014-07-07 15:12:34 -07:00
|
|
|
isBroadcast: 1
|
2014-07-07 13:38:17 -07:00
|
|
|
};
|
2014-07-07 15:12:34 -07:00
|
|
|
|
|
|
|
var senderId = "03baa45498fee1045fa8f91a2913f638dc3979b455498924d3cf1a11303c679cdb";
|
2014-07-24 17:18:38 -07:00
|
|
|
|
2014-07-06 21:33:39 -07:00
|
|
|
Object.keys(w.addressBook).length.should.equal(2);
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onAddressBook(senderId, data, true);
|
2014-07-06 21:33:39 -07:00
|
|
|
Object.keys(w.addressBook).length.should.equal(3);
|
2014-07-24 17:18:38 -07:00
|
|
|
});
|
2014-07-06 21:33:39 -07:00
|
|
|
|
|
|
|
it('should return signed object', function() {
|
|
|
|
var w = createW();
|
|
|
|
var payload = {
|
|
|
|
address: 'msj42CCGruhRsFrGATiUuh25dtxYtnpbTx',
|
|
|
|
label: 'Faucet',
|
|
|
|
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
|
|
|
createdTs: 1403102115
|
|
|
|
};
|
2014-07-07 06:58:43 -07:00
|
|
|
should.exist(w.signJson(payload));
|
2014-07-06 21:33:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should verify signed object', function() {
|
|
|
|
var w = createW();
|
|
|
|
|
2014-07-07 15:12:34 -07:00
|
|
|
var payload = {
|
|
|
|
address: "3Ae1ieAYNXznm7NkowoFTu5MkzgrTfDz8Z",
|
|
|
|
label: "adsf",
|
|
|
|
copayerId: "03baa45498fee1045fa8f91a2913f638dc3979b455498924d3cf1a11303c679cdb",
|
|
|
|
createdTs: 1404769393509
|
|
|
|
}
|
|
|
|
|
|
|
|
var signature = "3046022100d4cdefef66ab8cea26031d5df03a38fc9ec9b09b0fb31d3a26b6e204918e9e78022100ecdbbd889ec99ea1bfd471253487af07a7fa7c0ac6012ca56e10e66f335e4586";
|
|
|
|
|
|
|
|
var pubKey = "03baa45498fee1045fa8f91a2913f638dc3979b455498924d3cf1a11303c679cdb";
|
|
|
|
|
|
|
|
w.verifySignedJson(pubKey, payload, signature).should.equal(true);
|
|
|
|
payload.label = 'Another';
|
|
|
|
w.verifySignedJson(pubKey, payload, signature).should.equal(false);
|
2014-07-06 21:33:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should verify signed addressbook entry', function() {
|
|
|
|
var w = createW();
|
2014-07-07 15:12:34 -07:00
|
|
|
var key = "3Ae1ieAYNXznm7NkowoFTu5MkzgrTfDz8Z";
|
|
|
|
var pubKey = "03baa45498fee1045fa8f91a2913f638dc3979b455498924d3cf1a11303c679cdb";
|
|
|
|
w.addressBook[key] = {
|
|
|
|
copayerId: pubKey,
|
|
|
|
createdTs: 1404769393509,
|
2014-07-06 21:33:39 -07:00
|
|
|
hidden: false,
|
2014-07-07 15:12:34 -07:00
|
|
|
label: "adsf",
|
|
|
|
signature: "3046022100d4cdefef66ab8cea26031d5df03a38fc9ec9b09b0fb31d3a26b6e204918e9e78022100ecdbbd889ec99ea1bfd471253487af07a7fa7c0ac6012ca56e10e66f335e4586"
|
2014-07-06 21:33:39 -07:00
|
|
|
};
|
|
|
|
|
2014-07-07 16:01:50 -07:00
|
|
|
w.verifyAddressbookEntry(w.addressBook[key], pubKey, key).should.equal(true);
|
2014-07-06 21:33:39 -07:00
|
|
|
w.addressBook[key].label = 'Another';
|
2014-07-07 16:01:50 -07:00
|
|
|
w.verifyAddressbookEntry(w.addressBook[key], pubKey, key).should.equal(false);
|
2014-07-24 17:18:38 -07:00
|
|
|
(function() {
|
2014-07-07 16:01:50 -07:00
|
|
|
w.verifyAddressbookEntry();
|
2014-07-07 06:58:43 -07:00
|
|
|
}).should.throw();
|
2014-06-17 21:00:32 -07:00
|
|
|
});
|
|
|
|
|
2014-06-19 10:21:38 -07:00
|
|
|
});
|
|
|
|
|
2014-06-19 11:03:31 -07:00
|
|
|
it('#getNetworkName', function() {
|
|
|
|
var w = createW();
|
|
|
|
w.getNetworkName().should.equal('testnet');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getMyCopayerId', function() {
|
|
|
|
it('should call getCopayerId', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-19 11:03:31 -07:00
|
|
|
w.getCopayerId = sinon.spy();
|
|
|
|
w.getMyCopayerId();
|
|
|
|
w.getCopayerId.calledOnce.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getMyCopayerIdPriv', function() {
|
|
|
|
it('should call privateKey.getIdPriv', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-19 11:03:31 -07:00
|
|
|
w.privateKey.getIdPriv = sinon.spy();
|
|
|
|
w.getMyCopayerIdPriv();
|
|
|
|
w.privateKey.getIdPriv.calledOnce.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-12 06:40:47 -07:00
|
|
|
describe('#getMyCopayerNickname', function() {
|
|
|
|
it('should call publicKeyRing.nicknameForCopayer', function() {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
w.publicKeyRing.nicknameForCopayer = sinon.spy();
|
|
|
|
w.getMyCopayerNickname();
|
|
|
|
w.publicKeyRing.nicknameForCopayer.calledOnce.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-19 11:03:31 -07:00
|
|
|
describe('#netStart', function() {
|
|
|
|
it('should call Network.start', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-19 11:03:31 -07:00
|
|
|
w.network.start = sinon.spy();
|
|
|
|
w.netStart();
|
|
|
|
w.network.start.calledOnce.should.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call Network.start with a private key', function() {
|
2014-06-24 17:48:05 -07:00
|
|
|
var w = cachedCreateW2();
|
2014-06-19 11:03:31 -07:00
|
|
|
w.network.start = sinon.spy();
|
|
|
|
w.netStart();
|
|
|
|
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
|
|
|
});
|
2014-08-07 16:07:41 -07:00
|
|
|
|
2014-06-25 13:36:34 -07:00
|
|
|
});
|
2014-06-19 11:03:31 -07:00
|
|
|
|
2014-08-04 08:43:21 -07:00
|
|
|
describe('_getKeymap', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
|
|
|
|
it('should set keymap', function() {
|
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
|
|
|
return {
|
|
|
|
'123': 'juan'
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var txp = {
|
2014-08-21 16:30:31 -07:00
|
|
|
_inputSigners: [
|
2014-08-04 08:43:21 -07:00
|
|
|
['123']
|
|
|
|
],
|
2014-08-04 13:12:53 -07:00
|
|
|
inputChainPaths: ['/m/1'],
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
|
|
|
var map = w._getKeyMap(txp);
|
|
|
|
Object.keys(map).length.should.equal(1);
|
|
|
|
map['123'].should.equal('juan');
|
|
|
|
stub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw if unmatched sigs', function() {
|
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
2014-08-22 11:44:40 -07:00
|
|
|
return {};
|
2014-08-04 08:43:21 -07:00
|
|
|
});
|
|
|
|
var txp = {
|
2014-08-21 16:30:31 -07:00
|
|
|
_inputSigners: [
|
2014-08-04 08:43:21 -07:00
|
|
|
['234']
|
|
|
|
],
|
2014-08-04 13:12:53 -07:00
|
|
|
inputChainPaths: ['/m/1'],
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
|
|
|
(function() {
|
|
|
|
w._getKeyMap(txp);
|
2014-08-21 18:02:55 -07:00
|
|
|
}).should.throw('does not match known copayers');
|
|
|
|
stub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw if unmatched sigs (case 2)', function() {
|
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
2014-08-22 11:44:40 -07:00
|
|
|
return {};
|
2014-08-21 18:02:55 -07:00
|
|
|
});
|
|
|
|
var txp = {
|
|
|
|
_inputSigners: [
|
2014-08-22 11:44:40 -07:00
|
|
|
['234', '321'],
|
|
|
|
['234', '322']
|
2014-08-21 18:02:55 -07:00
|
|
|
],
|
|
|
|
inputChainPaths: ['/m/1'],
|
|
|
|
};
|
|
|
|
(function() {
|
|
|
|
w._getKeyMap(txp);
|
|
|
|
}).should.throw('does not match known copayers');
|
2014-08-04 08:43:21 -07:00
|
|
|
stub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set keymap with multiple signatures', function() {
|
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
|
|
|
return {
|
|
|
|
'123': 'juan',
|
|
|
|
'234': 'pepe',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var txp = {
|
2014-08-21 16:30:31 -07:00
|
|
|
_inputSigners: [
|
2014-08-04 08:43:21 -07:00
|
|
|
['234', '123']
|
|
|
|
],
|
2014-08-04 13:12:53 -07:00
|
|
|
inputChainPaths: ['/m/1'],
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
|
|
|
var map = w._getKeyMap(txp);
|
|
|
|
Object.keys(map).length.should.equal(2);
|
|
|
|
map['123'].should.equal('juan');
|
|
|
|
map['234'].should.equal('pepe');
|
|
|
|
stub.restore();
|
|
|
|
});
|
|
|
|
|
2014-08-21 18:02:55 -07:00
|
|
|
it('should throw if one inputs has missing sigs', function() {
|
2014-08-22 11:44:40 -07:00
|
|
|
var call = 0;
|
2014-08-04 08:43:21 -07:00
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
2014-08-21 18:02:55 -07:00
|
|
|
return call++ ? {
|
|
|
|
'555': 'pepe',
|
2014-08-22 11:44:40 -07:00
|
|
|
} : {
|
2014-08-04 08:43:21 -07:00
|
|
|
'123': 'juan',
|
|
|
|
'234': 'pepe',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var txp = {
|
2014-08-21 16:30:31 -07:00
|
|
|
_inputSigners: [
|
2014-08-04 08:43:21 -07:00
|
|
|
['234', '123'],
|
2014-08-21 18:02:55 -07:00
|
|
|
['555']
|
2014-08-04 08:43:21 -07:00
|
|
|
],
|
2014-08-04 13:12:53 -07:00
|
|
|
inputChainPaths: ['/m/1'],
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
|
|
|
(function() {
|
|
|
|
w._getKeyMap(txp);
|
|
|
|
}).should.throw('different sig');
|
|
|
|
stub.restore();
|
|
|
|
});
|
2014-08-21 18:02:55 -07:00
|
|
|
|
|
|
|
|
|
|
|
it('should throw if one inputs has different sigs', function() {
|
2014-08-22 11:44:40 -07:00
|
|
|
var call = 0;
|
2014-08-21 18:02:55 -07:00
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
|
|
|
return call++ ? {
|
|
|
|
'555': 'pepe',
|
|
|
|
'666': 'pedro',
|
2014-08-22 11:44:40 -07:00
|
|
|
} : {
|
2014-08-21 18:02:55 -07:00
|
|
|
'123': 'juan',
|
|
|
|
'234': 'pepe',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var txp = {
|
|
|
|
_inputSigners: [
|
|
|
|
['234', '123'],
|
|
|
|
['555', '666']
|
|
|
|
],
|
|
|
|
inputChainPaths: ['/m/1'],
|
|
|
|
};
|
|
|
|
(function() {
|
|
|
|
w._getKeyMap(txp);
|
|
|
|
}).should.throw('different sig');
|
|
|
|
stub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should not throw if 2 inputs has different pubs, same copayers', function() {
|
2014-08-22 11:44:40 -07:00
|
|
|
var call = 0;
|
2014-08-21 18:02:55 -07:00
|
|
|
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
|
|
|
return call++ ? {
|
|
|
|
'555': 'pepe',
|
|
|
|
'666': 'pedro',
|
2014-08-22 11:44:40 -07:00
|
|
|
} : {
|
2014-08-21 18:02:55 -07:00
|
|
|
'123': 'pedro',
|
|
|
|
'234': 'pepe',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var txp = {
|
|
|
|
_inputSigners: [
|
|
|
|
['234', '123'],
|
|
|
|
['555', '666']
|
|
|
|
],
|
|
|
|
inputChainPaths: ['/m/1'],
|
|
|
|
};
|
2014-08-22 11:44:40 -07:00
|
|
|
var gk = w._getKeyMap(txp);
|
|
|
|
gk.should.deep.equal({
|
|
|
|
'123': 'pedro',
|
|
|
|
'234': 'pepe',
|
|
|
|
'555': 'pepe',
|
|
|
|
'666': 'pedro'
|
|
|
|
});
|
2014-08-21 18:02:55 -07:00
|
|
|
stub.restore();
|
|
|
|
});
|
2014-08-04 08:43:21 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-24 06:42:47 -07:00
|
|
|
|
2014-08-19 09:51:55 -07:00
|
|
|
describe('_onTxProposal', function() {
|
2014-09-29 13:36:34 -07:00
|
|
|
var w;
|
|
|
|
beforeEach(function() {
|
|
|
|
w = cachedCreateW();
|
|
|
|
w._getKeyMap = sinon.stub();
|
|
|
|
w.sendSeen = sinon.spy();
|
|
|
|
w.sendTxProposal = sinon.spy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle corrupt tx', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
w.txProposals.merge = sinon.stub().throws(new Error('test error'));
|
2014-08-03 19:57:23 -07:00
|
|
|
|
2014-07-24 06:42:47 -07:00
|
|
|
var spy = sinon.spy();
|
|
|
|
w.on('txProposalEvent', spy);
|
|
|
|
w.on('txProposalEvent', function(e) {
|
2014-09-29 13:36:34 -07:00
|
|
|
e.type.should.equal('corrupt');
|
2014-07-24 06:42:47 -07:00
|
|
|
done();
|
|
|
|
});
|
2014-09-29 13:36:34 -07:00
|
|
|
|
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
spy.called.should.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle new', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
|
|
|
var txp = {
|
2014-09-29 13:36:34 -07:00
|
|
|
getSeen: sinon.stub().returns(false),
|
|
|
|
setSeen: sinon.spy(),
|
|
|
|
setCopayers: sinon.spy(),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(false),
|
|
|
|
}),
|
|
|
|
},
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
2014-09-09 18:06:19 -07:00
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: true,
|
|
|
|
hasChanged: true,
|
2014-09-09 18:06:19 -07:00
|
|
|
});
|
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
var spy1 = sinon.spy();
|
|
|
|
var spy2 = sinon.spy();
|
|
|
|
w.on('txProposalEvent', spy1);
|
|
|
|
w.on('txProposalsUpdated', spy2);
|
|
|
|
w.on('txProposalEvent', function(e) {
|
|
|
|
e.type.should.equal('new');
|
|
|
|
done();
|
|
|
|
});
|
2014-09-09 18:06:19 -07:00
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
spy1.called.should.be.true;
|
|
|
|
spy2.called.should.be.true;
|
|
|
|
txp.setSeen.calledOnce.should.be.true;
|
|
|
|
w.sendSeen.calledOnce.should.be.true;
|
|
|
|
w.sendTxProposal.calledOnce.should.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle signed', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var txp = {
|
|
|
|
getSeen: sinon.stub().returns(true),
|
|
|
|
setSeen: sinon.spy(),
|
|
|
|
setCopayers: sinon.stub().returns(['new copayer']),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(false),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: false,
|
|
|
|
hasChanged: true,
|
2014-08-01 06:51:46 -07:00
|
|
|
});
|
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
var spy1 = sinon.spy();
|
|
|
|
var spy2 = sinon.spy();
|
|
|
|
w.on('txProposalEvent', spy1);
|
|
|
|
w.on('txProposalsUpdated', spy2);
|
|
|
|
w.on('txProposalEvent', function(e) {
|
|
|
|
e.type.should.equal('signed');
|
|
|
|
done();
|
|
|
|
});
|
2014-07-24 06:42:47 -07:00
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
spy1.called.should.be.true;
|
|
|
|
spy2.called.should.be.true;
|
|
|
|
txp.setSeen.calledOnce.should.be.false;
|
|
|
|
w.sendSeen.calledOnce.should.be.false;
|
|
|
|
w.sendTxProposal.calledOnce.should.be.true;
|
2014-07-25 09:37:12 -07:00
|
|
|
});
|
2014-09-29 13:36:34 -07:00
|
|
|
|
|
|
|
it('should mark as broadcast when complete', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var txp = {
|
|
|
|
getSeen: sinon.stub().returns(true),
|
|
|
|
setCopayers: sinon.stub().returns(['new copayer']),
|
2014-10-06 14:51:45 -07:00
|
|
|
getSent: sinon.stub().returns(false),
|
2014-09-29 13:36:34 -07:00
|
|
|
setSent: sinon.spy(),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(true),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: false,
|
|
|
|
hasChanged: true,
|
|
|
|
});
|
|
|
|
w._checkSentTx = sinon.stub().yields(true);
|
|
|
|
|
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
txp.setSent.calledOnce.should.be.true;
|
|
|
|
w.sendTxProposal.called.should.be.false;
|
|
|
|
done();
|
2014-07-24 06:42:47 -07:00
|
|
|
});
|
2014-09-29 13:36:34 -07:00
|
|
|
|
|
|
|
it('should only mark as broadcast if found in the blockchain', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var txp = {
|
|
|
|
getSeen: sinon.stub().returns(true),
|
|
|
|
setCopayers: sinon.stub().returns(['new copayer']),
|
2014-10-06 14:51:45 -07:00
|
|
|
getSent: sinon.stub().returns(false),
|
2014-09-29 13:36:34 -07:00
|
|
|
setSent: sinon.spy(),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(true),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: false,
|
|
|
|
hasChanged: true,
|
|
|
|
});
|
|
|
|
w._checkSentTx = sinon.stub().yields(false);
|
|
|
|
|
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
txp.setSent.called.should.be.false;
|
2014-09-29 14:04:58 -07:00
|
|
|
txp.setSent.calledWith(1).should.be.false;
|
2014-09-29 13:36:34 -07:00
|
|
|
w.sendTxProposal.called.should.be.false;
|
|
|
|
done();
|
2014-08-03 19:57:23 -07:00
|
|
|
});
|
|
|
|
|
2014-10-06 14:51:45 -07:00
|
|
|
it('should not overwrite sent info', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var txp = {
|
|
|
|
getSeen: sinon.stub().returns(true),
|
|
|
|
setCopayers: sinon.stub().returns(['new copayer']),
|
|
|
|
getSent: sinon.stub().returns(true),
|
|
|
|
setSent: sinon.spy(),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(true),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: false,
|
|
|
|
hasChanged: false,
|
|
|
|
});
|
|
|
|
w._checkSentTx = sinon.stub().yields(true);
|
|
|
|
|
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
txp.setSent.called.should.be.false;
|
|
|
|
w.sendTxProposal.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2014-09-29 13:36:34 -07:00
|
|
|
it('should resend when not complete only if changed', function(done) {
|
|
|
|
var data = {
|
|
|
|
txProposal: {
|
|
|
|
dummy: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var txp = {
|
|
|
|
getSeen: sinon.stub().returns(true),
|
|
|
|
setCopayers: sinon.stub().returns(['new copayer']),
|
|
|
|
builder: {
|
|
|
|
build: sinon.stub().returns({
|
|
|
|
isComplete: sinon.stub().returns(false),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
w.txProposals.merge = sinon.stub().returns({
|
|
|
|
ntxid: 1,
|
|
|
|
txp: txp,
|
|
|
|
new: false,
|
|
|
|
hasChanged: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
w._onTxProposal('senderID', data);
|
|
|
|
w.sendTxProposal.called.should.be.false;
|
|
|
|
done();
|
|
|
|
});
|
2014-07-24 06:42:47 -07:00
|
|
|
});
|
2014-08-04 08:43:21 -07:00
|
|
|
|
|
|
|
|
2014-08-19 09:51:55 -07:00
|
|
|
describe('_onReject', function() {
|
2014-08-04 08:43:21 -07:00
|
|
|
it('should fails if unknown tx', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
(function() {
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onReject(1, {
|
2014-08-04 08:43:21 -07:00
|
|
|
ntxid: 1
|
|
|
|
}, 1);
|
2014-08-05 12:25:02 -07:00
|
|
|
}).should.throw('Unknown TXP');
|
2014-08-04 08:43:21 -07:00
|
|
|
});
|
|
|
|
it('should fail to reject a signed tx', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
w.txProposals.txps['qwerty'] = {
|
|
|
|
signedBy: {
|
|
|
|
john: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
(function() {
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onReject('john', {
|
2014-08-04 08:43:21 -07:00
|
|
|
ntxid: 'qwerty'
|
|
|
|
}, 1);
|
|
|
|
}).should.throw('already signed');
|
|
|
|
});
|
|
|
|
it('should reject a tx', function() {
|
|
|
|
var w = cachedCreateW();
|
2014-08-04 13:12:53 -07:00
|
|
|
|
2014-08-04 08:43:21 -07:00
|
|
|
function txp() {
|
2014-08-04 13:12:53 -07:00
|
|
|
this.ok = 0;
|
2014-08-04 08:43:21 -07:00
|
|
|
this.signedBy = {};
|
|
|
|
};
|
2014-08-04 13:12:53 -07:00
|
|
|
txp.prototype.setRejected = function() {
|
|
|
|
this.ok = 1;
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
2014-08-04 13:12:53 -07:00
|
|
|
txp.prototype.toObj = function() {};
|
2014-08-04 08:43:21 -07:00
|
|
|
|
2014-08-04 13:12:53 -07:00
|
|
|
var spy1 = sinon.spy(w, 'store');
|
|
|
|
var spy2 = sinon.spy(w, 'emit');
|
2014-08-04 08:43:21 -07:00
|
|
|
w.txProposals.txps['qwerty'] = new txp();
|
2014-08-04 13:12:53 -07:00
|
|
|
w.txProposals.txps['qwerty'].ok.should.equal(0);
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onReject('john', {
|
2014-08-04 08:43:21 -07:00
|
|
|
ntxid: 'qwerty'
|
|
|
|
}, 1);
|
2014-08-04 13:12:53 -07:00
|
|
|
w.txProposals.txps['qwerty'].ok.should.equal(1);
|
2014-08-04 08:43:21 -07:00
|
|
|
spy1.calledOnce.should.equal(true);
|
|
|
|
spy2.callCount.should.equal(2);
|
|
|
|
spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']);
|
2014-08-04 13:12:53 -07:00
|
|
|
spy2.secondCall.args.should.deep.equal(['txProposalEvent', {
|
|
|
|
type: 'rejected',
|
2014-08-04 08:43:21 -07:00
|
|
|
cId: 'john',
|
|
|
|
txId: 'qwerty',
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-19 09:51:55 -07:00
|
|
|
describe('_onSeen', function() {
|
2014-08-04 08:43:21 -07:00
|
|
|
it('should fails if unknown tx', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
(function() {
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onReject(1, {
|
2014-08-04 08:43:21 -07:00
|
|
|
ntxid: 1
|
|
|
|
}, 1);
|
2014-08-05 12:25:02 -07:00
|
|
|
}).should.throw('Unknown TXP');
|
2014-08-04 08:43:21 -07:00
|
|
|
});
|
|
|
|
it('should set seen a tx', function() {
|
|
|
|
var w = cachedCreateW();
|
2014-08-04 13:12:53 -07:00
|
|
|
|
2014-08-04 08:43:21 -07:00
|
|
|
function txp() {
|
2014-08-04 13:12:53 -07:00
|
|
|
this.ok = 0;
|
2014-08-04 08:43:21 -07:00
|
|
|
this.signedBy = {};
|
|
|
|
};
|
2014-08-04 13:12:53 -07:00
|
|
|
txp.prototype.setSeen = function() {
|
|
|
|
this.ok = 1;
|
2014-08-04 08:43:21 -07:00
|
|
|
};
|
2014-08-04 13:12:53 -07:00
|
|
|
txp.prototype.toObj = function() {};
|
2014-08-04 08:43:21 -07:00
|
|
|
|
2014-08-04 13:12:53 -07:00
|
|
|
var spy1 = sinon.spy(w, 'store');
|
|
|
|
var spy2 = sinon.spy(w, 'emit');
|
2014-08-04 08:43:21 -07:00
|
|
|
w.txProposals.txps['qwerty'] = new txp();
|
2014-08-04 13:12:53 -07:00
|
|
|
w.txProposals.txps['qwerty'].ok.should.equal(0);
|
2014-08-19 09:51:55 -07:00
|
|
|
w._onSeen('john', {
|
2014-08-04 08:43:21 -07:00
|
|
|
ntxid: 'qwerty'
|
|
|
|
}, 1);
|
2014-08-04 13:12:53 -07:00
|
|
|
w.txProposals.txps['qwerty'].ok.should.equal(1);
|
2014-08-04 08:43:21 -07:00
|
|
|
spy1.calledOnce.should.equal(true);
|
|
|
|
spy2.callCount.should.equal(2);
|
|
|
|
spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']);
|
2014-08-04 13:12:53 -07:00
|
|
|
spy2.secondCall.args.should.deep.equal(['txProposalEvent', {
|
|
|
|
type: 'seen',
|
2014-08-04 08:43:21 -07:00
|
|
|
cId: 'john',
|
|
|
|
txId: 'qwerty',
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getNetwork', function() {
|
|
|
|
var w = cachedCreateW();
|
|
|
|
var n = w.getNetwork();
|
|
|
|
n.maxPeers.should.equal(5);
|
|
|
|
should.exist(n.networkNonce);
|
|
|
|
});
|
|
|
|
|
2014-09-29 07:35:04 -07:00
|
|
|
|
|
|
|
describe('#obtainNetworkName', function() {
|
|
|
|
it('should return the networkname', function() {
|
|
|
|
Wallet.obtainNetworkName({
|
|
|
|
networkName: 'testnet',
|
|
|
|
}).should.equal('testnet');
|
|
|
|
Wallet.obtainNetworkName({
|
|
|
|
opts: {
|
|
|
|
networkName: 'testnet'
|
|
|
|
}
|
|
|
|
}).should.equal('testnet');
|
|
|
|
Wallet.obtainNetworkName({
|
|
|
|
publicKeyRing: {
|
|
|
|
networkName: 'testnet'
|
|
|
|
}
|
|
|
|
}).should.equal('testnet');
|
2014-09-29 15:58:00 -07:00
|
|
|
|
2014-09-29 07:35:04 -07:00
|
|
|
Wallet.obtainNetworkName({
|
|
|
|
privateKey: {
|
|
|
|
networkName: 'testnet'
|
|
|
|
}
|
|
|
|
}).should.equal('testnet');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:34:00 -07:00
|
|
|
it('should emit notification when tx received', function(done) {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
w.blockchain.removeAllListeners = sinon.stub();
|
|
|
|
var spy = sinon.spy(w, 'emit');
|
|
|
|
|
|
|
|
w.generateAddress(false, function(addr1) {
|
|
|
|
w.generateAddress(true, function(addr2) {
|
|
|
|
w.blockchain.on = sinon.stub().withArgs('tx').yields({
|
|
|
|
address: addr1.toString(),
|
|
|
|
});
|
|
|
|
w._setBlockchainListeners();
|
|
|
|
spy.calledWith('tx', addr1.toString(), false).should.be.true;
|
|
|
|
|
|
|
|
w.blockchain.on = sinon.stub().withArgs('tx').yields({
|
|
|
|
address: addr2.toString(),
|
|
|
|
});
|
|
|
|
w._setBlockchainListeners();
|
|
|
|
spy.calledWith('tx', addr2.toString(), true).should.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-29 06:18:47 -07:00
|
|
|
describe('#fromObj / #toObj', function() {
|
|
|
|
var storage = new Storage(walletConfig.storage);
|
|
|
|
var network = new Network(walletConfig.network);
|
|
|
|
var blockchain = new Blockchain(walletConfig.blockchain);
|
|
|
|
|
|
|
|
it('Import backup using old copayerIndex', function() {
|
2014-10-07 14:33:55 -07:00
|
|
|
|
|
|
|
var w = Wallet.fromObj(JSON.parse(o), {
|
|
|
|
storage: storage,
|
|
|
|
blockchainOpts: {},
|
|
|
|
networkOpts: {},
|
|
|
|
});
|
2014-09-29 06:18:47 -07:00
|
|
|
|
|
|
|
should.exist(w);
|
|
|
|
w.id.should.equal("dbfe10c3fae71cea");
|
|
|
|
should.exist(w.publicKeyRing.getCopayerId);
|
|
|
|
should.exist(w.txProposals.toObj());
|
|
|
|
should.exist(w.privateKey.toObj());
|
|
|
|
assertObjectEqual(w.toObj(), JSON.parse(o));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#fromObj, skipping fields', function() {
|
2014-10-07 14:33:55 -07:00
|
|
|
var w = Wallet.fromObj(JSON.parse(o), {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
skipFields: ['publicKeyRing'],
|
|
|
|
});
|
2014-09-29 06:18:47 -07:00
|
|
|
|
|
|
|
should.exist(w);
|
|
|
|
w.id.should.equal("dbfe10c3fae71cea");
|
|
|
|
should.exist(w.publicKeyRing.getCopayerId);
|
|
|
|
should.exist(w.txProposals.toObj());
|
|
|
|
should.exist(w.privateKey.toObj());
|
|
|
|
(function() {
|
|
|
|
assertObjectEqual(w.toObj(), JSON.parse(o))
|
|
|
|
}).should.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('support old index schema: #fromObj #toObj round trip', function() {
|
|
|
|
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5"},"networkNonce":"0000000000000001","networkNonces":[],"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersBackup":[],"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet"},"addressBook":{}}';
|
|
|
|
var o2 = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5","networkName":"testnet"},"networkNonce":"0000000000000001","networkNonces":[],"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":[{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":0},{"copayerIndex":0,"changeIndex":0,"receiveIndex":0},{"copayerIndex":1,"changeIndex":0,"receiveIndex":0},{"copayerIndex":2,"changeIndex":0,"receiveIndex":0},{"copayerIndex":3,"changeIndex":0,"receiveIndex":0},{"copayerIndex":4,"changeIndex":0,"receiveIndex":0}],"copayersBackup":[],"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet"},"addressBook":{}}';
|
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
var w = Wallet.fromObj(JSON.parse(o), {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
});
|
2014-09-29 06:18:47 -07:00
|
|
|
|
|
|
|
should.exist(w);
|
|
|
|
w.id.should.equal("dbfe10c3fae71cea");
|
|
|
|
should.exist(w.publicKeyRing.getCopayerId);
|
|
|
|
should.exist(w.txProposals.toObj);
|
|
|
|
should.exist(w.privateKey.toObj);
|
|
|
|
|
|
|
|
assertObjectEqual(w.toObj(), JSON.parse(o2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-22 12:57:29 -07:00
|
|
|
describe('#getTransactionHistory', function() {
|
|
|
|
it('should return list of txs', function(done) {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var txs = [{
|
|
|
|
vin: [{
|
|
|
|
addr: 'addr_in_1',
|
|
|
|
valueSat: 1000
|
|
|
|
}],
|
|
|
|
vout: [{
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['addr_out_1'],
|
|
|
|
},
|
|
|
|
value: '0.00000900',
|
|
|
|
}],
|
|
|
|
fees: 0.00000100
|
|
|
|
}, {
|
|
|
|
vin: [{
|
|
|
|
addr: 'addr_in_2',
|
|
|
|
valueSat: 2000
|
|
|
|
}],
|
|
|
|
vout: [{
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['addr_out_2'],
|
|
|
|
},
|
|
|
|
value: '0.00001900',
|
|
|
|
}],
|
|
|
|
fees: 0.00000100
|
|
|
|
}, {
|
|
|
|
vin: [{
|
|
|
|
addr: 'addr_in_1',
|
|
|
|
valueSat: 3000
|
|
|
|
|
|
|
|
}],
|
|
|
|
vout: [{
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['addr_out_2'],
|
|
|
|
},
|
|
|
|
value: '0.00002900',
|
|
|
|
|
|
|
|
}],
|
|
|
|
fees: 0.00000100
|
|
|
|
}];
|
|
|
|
|
|
|
|
w.blockchain.getTransactions = sinon.stub().yields(null, txs);
|
|
|
|
w.getAddressesInfo = sinon.stub().returns([{
|
|
|
|
addressStr: 'addr_in_1'
|
|
|
|
}, {
|
|
|
|
addressStr: 'addr_out_2'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
w.getTransactionHistory(function(err, res) {
|
|
|
|
res.should.exist;
|
|
|
|
res.length.should.equal(3);
|
|
|
|
console.log('res', res);
|
|
|
|
res[0].action.should.equal('sent');
|
|
|
|
res[0].amountSat.should.equal(900);
|
|
|
|
res[1].action.should.equal('received');
|
|
|
|
res[1].amountSat.should.equal(1900);
|
|
|
|
res[2].action.should.equal('moved');
|
|
|
|
res[2].amountSat.should.equal(2900);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should compute sent amount correctly', function(done) {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var txs = [{
|
|
|
|
vin: [{
|
|
|
|
addr: 'addr_in_1',
|
|
|
|
valueSat: 3000
|
|
|
|
}, {
|
|
|
|
addr: 'addr_in_2',
|
|
|
|
valueSat: 2000
|
|
|
|
}],
|
|
|
|
vout: [{
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['addr_out_1'],
|
|
|
|
},
|
|
|
|
value: '0.00003900',
|
|
|
|
}, {
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['change'],
|
|
|
|
},
|
|
|
|
value: '0.00001000',
|
|
|
|
}],
|
|
|
|
fees: 0.00000100
|
|
|
|
}];
|
|
|
|
|
|
|
|
w.blockchain.getTransactions = sinon.stub().yields(null, txs);
|
|
|
|
w.getAddressesInfo = sinon.stub().returns([{
|
|
|
|
addressStr: 'addr_in_1'
|
|
|
|
}, {
|
|
|
|
addressStr: 'addr_in_2'
|
|
|
|
}, {
|
|
|
|
addressStr: 'change'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
w.getTransactionHistory(function(err, res) {
|
|
|
|
res.should.exist;
|
|
|
|
res[0].action.should.equal('sent');
|
|
|
|
res[0].amountSat.should.equal(3900);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should compute moved amount correctly', function(done) {
|
|
|
|
var w = cachedCreateW2();
|
|
|
|
var txs = [{
|
|
|
|
vin: [{
|
|
|
|
addr: 'addr_1',
|
|
|
|
valueSat: 3000
|
|
|
|
}, {
|
|
|
|
addr: 'addr_2',
|
|
|
|
valueSat: 2000
|
|
|
|
}],
|
|
|
|
vout: [{
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['addr_1'],
|
|
|
|
},
|
|
|
|
value: '0.00003900',
|
|
|
|
}, {
|
|
|
|
scriptPubKey: {
|
|
|
|
addresses: ['change'],
|
|
|
|
},
|
|
|
|
value: '0.00001000',
|
|
|
|
}],
|
|
|
|
fees: 0.00000100
|
|
|
|
}];
|
|
|
|
|
|
|
|
w.blockchain.getTransactions = sinon.stub().yields(null, txs);
|
|
|
|
w.getAddressesInfo = sinon.stub().returns([{
|
|
|
|
addressStr: 'addr_1'
|
|
|
|
}, {
|
|
|
|
addressStr: 'addr_2'
|
|
|
|
}, {
|
|
|
|
addressStr: 'change'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
w.getTransactionHistory(function(err, res) {
|
|
|
|
res.should.exist;
|
|
|
|
res[0].action.should.equal('moved');
|
|
|
|
res[0].amountSat.should.equal(3900);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-09-29 12:55:45 -07:00
|
|
|
describe('#read', function() {
|
2014-10-07 14:33:55 -07:00
|
|
|
var storage, network, blockchain;
|
2014-09-29 12:55:45 -07:00
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
beforeEach(function() {
|
|
|
|
var s = function() {};
|
|
|
|
storage = new s();
|
|
|
|
network = new Network(walletConfig.network);
|
|
|
|
blockchain = new Blockchain(walletConfig.blockchain);
|
|
|
|
storage.setPassword = sinon.stub();
|
|
|
|
});
|
2014-09-29 12:55:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
it('should fail to read an unexisting wallet', function(done) {
|
2014-10-01 04:35:17 -07:00
|
|
|
storage.getFirst = sinon.stub().yields(null);
|
2014-09-29 12:55:45 -07:00
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet.read('123', {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
}, function(err, w) {
|
2014-09-29 12:55:45 -07:00
|
|
|
err.toString().should.contain('WNOTFOUND');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not read a corrupted wallet', function(done) {
|
|
|
|
|
2014-10-01 04:35:17 -07:00
|
|
|
storage.getFirst = sinon.stub().yields(null, '{hola:1}');
|
2014-09-29 12:55:45 -07:00
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet.read('123', {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
}, function(err, w) {
|
2014-09-29 12:55:45 -07:00
|
|
|
err.toString().should.contain('WERROR');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should read a wallet', function(done) {
|
2014-10-01 04:35:17 -07:00
|
|
|
storage.getFirst = sinon.stub().yields(null, JSON.parse(o));
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet.read('123', {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
}, function(err, w) {
|
2014-09-29 12:55:45 -07:00
|
|
|
should.not.exist(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-30 04:09:39 -07:00
|
|
|
|
|
|
|
it('should be able to import unencrypted legacy wallet TxProposal: v0', function(done) {
|
2014-10-01 04:35:17 -07:00
|
|
|
storage.getFirst = sinon.stub().yields(null, JSON.parse(legacyO));
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet.read('123', {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
}, function(err, w) {
|
2014-09-30 04:09:39 -07:00
|
|
|
should.exist(w);
|
|
|
|
w.id.should.equal('55d4bd062d32f90a');
|
|
|
|
should.exist(w.publicKeyRing.getCopayerId);
|
|
|
|
should.exist(w.txProposals.toObj());
|
|
|
|
should.exist(w.privateKey.toObj());
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function(done) {
|
2014-10-01 04:35:17 -07:00
|
|
|
storage.getFirst = sinon.stub().yields(null, JSON.parse(legacy1));
|
2014-09-30 04:09:39 -07:00
|
|
|
|
2014-10-07 14:33:55 -07:00
|
|
|
Wallet.read('123', {
|
|
|
|
storage: storage,
|
|
|
|
networkOpts: {},
|
|
|
|
blockchainOpts: {},
|
|
|
|
}, function(err, w) {
|
2014-09-30 04:09:39 -07:00
|
|
|
should.exist(w);
|
|
|
|
w.isReady().should.equal(true);
|
|
|
|
var wo = w.toObj();
|
|
|
|
wo.opts.id.should.equal('48ba2f1ffdfe9708');
|
|
|
|
wo.opts.spendUnconfirmed.should.equal(true);
|
|
|
|
wo.opts.requiredCopayers.should.equal(1);
|
|
|
|
wo.opts.totalCopayers.should.equal(1);
|
|
|
|
wo.opts.name.should.equal('pepe wallet');
|
|
|
|
wo.opts.version.should.equal('0.4.7');
|
|
|
|
wo.publicKeyRing.walletId.should.equal('48ba2f1ffdfe9708');
|
|
|
|
wo.publicKeyRing.networkName.should.equal('testnet');
|
|
|
|
wo.publicKeyRing.requiredCopayers.should.equal(1);
|
|
|
|
wo.publicKeyRing.totalCopayers.should.equal(1);
|
|
|
|
wo.publicKeyRing.indexes.length.should.equal(2);
|
|
|
|
JSON.stringify(wo.publicKeyRing.indexes[0]).should.equal('{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":1}');
|
|
|
|
JSON.stringify(wo.publicKeyRing.indexes[1]).should.equal('{"copayerIndex":0,"changeIndex":0,"receiveIndex":1}');
|
|
|
|
wo.publicKeyRing.copayersBackup.length.should.equal(1);
|
|
|
|
wo.publicKeyRing.copayersBackup[0].should.equal('0298f65b2694c55f9048bc05f10368242727c7f9d2065cbd788c3ecde1ec57f33f');
|
|
|
|
wo.publicKeyRing.copayersExtPubKeys.length.should.equal(1);
|
|
|
|
wo.publicKeyRing.copayersExtPubKeys[0].should.equal('tpubD9SGoP7CXsqSKTiQxCZSCpicDcophqnE4yuqjfw5M9tAR3fSjT9GDGwPEUFCN7SSmRKGDLZgKQePYFaLWyK32akeSan45TNTd8sgef9Ymh6');
|
|
|
|
wo.privateKey.extendedPrivateKeyString.should.equal('tprv8ZgxMBicQKsPfQCscb7CtJKzixxcVSyrCVcfr3WCFbtT8kYTzNubhjQ5R7AuYJgPCcSH4R8T34YVxeohKGhAB9wbB4eFBbQFjUpjGCqptHm');
|
|
|
|
wo.privateKey.networkName.should.equal('testnet');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-29 12:55:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-09-30 04:09:39 -07:00
|
|
|
|
|
|
|
var legacyO = '{"opts":{"id":"55d4bd062d32f90a","spendUnconfirmed":true,"requiredCopayers":2,"totalCopayers":2,"name":"xcvzxcv","version":"0.3.2"},"networkNonce":"53d25e8600000009","networkNonces":[],"publicKeyRing":{"walletId":"55d4bd062d32f90a","networkName":"testnet","requiredCopayers":2,"totalCopayers":2,"indexes":[{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":0},{"copayerIndex":0,"changeIndex":4,"receiveIndex":2},{"copayerIndex":1,"changeIndex":5,"receiveIndex":2}],"copayersBackup":["02c7b87033e4357d8afc6ab7fe31fff054772ea6251f0d9c8a835b1c1ac74f6fba","02b0c868a3889cd0cfc0e7fef9eaa6d85d7cf6f7573ae5c9d1d13645d22e2eb7e5"],"copayersExtPubKeys":["tpubD94LTzAUiW99mpA59nyf6fAHh4xKGmnwbgCV4gU2bRpeN9CRiMSurqme22px5NmJAo6FdcdH883Zu98VbqyhesCJ86kUEjH3Zpufy5FfcaC","tpubDA2U9H6LkRHDRbRxHBp4VTbxPc7JqsvtcLxrE5QJF8z1iT6hMJ1pXSVf57GWRcxXutYvpoXRurDVGsscJauMtnJBkYAWBVExYmm91XQE2zz"],"nicknameFor":{"02c7b87033e4357d8afc6ab7fe31fff054772ea6251f0d9c8a835b1c1ac74f6fba":"asdf","02b0c868a3889cd0cfc0e7fef9eaa6d85d7cf6f7573ae5c9d1d13645d22e2eb7e5":"qwerqw"},"publicKeysCache":{"m/0/0/0":["028a4b63f26253f3a8731577b8e1ee480950ad5833ebbf106fe3463bfc07cc3b90","0332efa054c08cb77506a35ee0762cb7156f244566703ec08e433568ec0397bec8"],"m/1/0/0":["0220ad514cf593d0c3905d3bb49bc5767a9410823bf9b77ea5ef2cf1d1016d77a8","02fd42cf66f1dbdc7bbb9ae09aecea72df479ffe5a0c4641301067e331d12e416d"],"m/1/0/1":["0315f7868eaf1f9b7127e3f7e0222c5e473eea003e34700f4758b6873c525d6723","02a2e8ed5e90dd39e3842fc790e06178997dbca319987f365317589e2a71a93658"],"m/0/1/0":["0244a25a0b97b26707fd855c15b046b901be85a3b70a781d0678608e633440eeca","0358cdcbc528ddfb7173b0dab283f702be82546ff031e4a832a7270080cb875959"],"m/0/1/1":["025c9b49bdf17d97bd82ea1b87793082f857247f0f9b999937a166ec994bb1b41f","020389327ee8ae7d0ee3f8187842d23a4070bdd8a27c0bcddd05d80ef39009253d"],"m/1/1/0":["02fd0e7c62b7b58d1ea7bb4cb84d53b019df99d3703a42aed73a2cfa15f3af5d08","0355a15912e76072ef50e6643376b8a9da8422ed4f8ea07b1d84d4989be5a39b2e"],"m/1/1/1":["03bc3e1f4db32efd8eb1fd44a1665938d59628429c67e1e8b7054ab5717f4e6750","03c4c817b633ac31f44f16f390af831d35f7d98744a52a0f23e9598967342255f8"],"m/1/1/2":["02826fe7e9da408480ddeb1d4414c5100b350f862ca718e27122681e1a0ca35077","02bd25af907bb3edbf6b2cd1ea90eaa92cc93ec47bea7d339af44c1d2c05708e99"],"m/0/1/2":["0337a1a70364b94745d6e26d2d28919cf528304f52765f12ef43e3d6da0a6c8dc0","039d83db9aa43e6e00e0304e6971b6079d79dc12d8d55ce2e6fc24a52ba8d41329"],"m/0/0/1":["0359c6d0d0d31f83301169901a6ffad9535f14014b5ab3b43561dbb2436a7b8138","037d06f713f13a11967fd5edca265ff4c77528693a712c482256505693e4890d93"],"m/1/1/3":["02600e5c41670773a213a4cb58c8f2fa3e83840784bc7f0b56925e1075e06632c2","036d01867af5f61371151ef7d9026fa0400a623f6924e404ee0b856625268972f9"],"m/0/1/3":["03e5a9b039b187ca8e065627df402e4a5b196b94198542da7036879de08be63d2d","0304f3e0b70f696d80e5785dc7747d6dcb55ba24c31f2d80bf184b4e582e6b47fc"],"m/1/1/4":["03741afa5bd50d6ba5801064c810fae84f6a4557d6a88ddc8591d0d4eb68a8fc41","0214dd6ce6073b05999fb887098ca6f7e1d0b4fdc0760557786907df353df90d1c"],"m/2147483647/1/0":["033e072a53ea835763a03c66e35c35384736210a1bb7d7ee6d9a3e109e82426b30","02e37b5570c053da8a8ee587be86fc629775c4db890aba2745ccc4e4dcc8c31041"],"m/2147483647/1/1":["0228a6de42ef421c263d1efd9f28d9a7d15a261995028a24eff6b9f1c3fc46e6bf","0226cff885cb0d607cc9cf69a7608316eb3fb2ec344c0c9956246ba776116fc396"],"m/2147483647/1/2":["034fe2a8f0b98445eb5810fe36572ad2f64ed9bf64dc9de624f99c0142cb07c682","02f2c5c758e32293f5c193fd69afadbba83abafb397db01e6f2b447690e900475a"],"m/2147483647/1/3":["02b25ef9434446c51f10678f787e4913de582e34d164bd3b06af7732c5476df1a8","025d51a1efd59bcff22ee2e0af61b21a7ba5f639e20dfdf25690e926005177dd0c"],"m/2147483647/1/4":["03e5734e1d29b2f684d0446b7a2ffbd0ba8952570a502d0d14b1efd8f24b61be53","0258fc28a324848d8d0154e8614815e35c668d274a8f01957bb99aab8dc8f386c0"],"m/2147483647/1/5":["021f9e775246765e1cfba0ae453b4eae6cd4ae5a57a09c319edbe89d4dbbf23be3","02857f66571a1c3eb9e72d22ae88e734c03d448bced4dcfd345c2059468124c741"],"m/2147483647/1/6":["02c072f329391a25255dc6452e5f5220966869dbf736ba8a8c3ae9d273a84bc3fd","030920a8b8e88c4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var legacy1 = '{"opts":{"id":"48ba2f1ffdfe9708","spendUnconfirmed":true,"requiredCopayers":1,"totalCopayers":1,"name":"pepe wallet","version":"0.4.7"},"networkNonce":"5405f06b00000001","networkNonces":[],"publicKeyRing":{"walletId":"48ba2f1ffdfe9708","networkName":"testnet","requiredCopayers":1,"totalCopayers":1,"indexes":[{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":1},{"copayerIndex":0,"changeIndex":0,"receiveIndex":1}],"copayersBackup":["0298f65b2694c55f9048bc05f10368242727c7f9d2065cbd788c3ecde1ec57f33f"],"copayersExtPubKeys":["tpubD9SGoP7CXsqSKTiQxCZSCpicDcophqnE4yuqjfw5M9tAR3fSjT9GDGwPEUFCN7SSmRKGDLZgKQePYFaLWyK32akeSan45TNTd8sgef9Ymh6"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"48ba2f1ffdfe9708","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPfQCscb7CtJKzixxcVSyrCVcfr3WCFbtT8kYTzNubhjQ5R7AuYJgPCcSH4R8T34YVxeohKGhAB9wbB4eFBbQFjUpjGCqptHm","networkName":"testnet"},"addressBook":{}}';
|
|
|
|
|
|
|
|
|
2014-09-29 06:18:47 -07:00
|
|
|
// DATA
|
|
|
|
var o = '{"opts":{"id":"dbfe10c3fae71cea", "spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5","networkName":"testnet"},"networkNonce":"0000000000000001","networkNonces":[],"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":[{"copayerIndex":2,"changeIndex":0,"receiveIndex":0}],"copayersBackup":[],"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet"},"addressBook":{},"settings":{"unitName":"BTC","unitToSatoshi":100000000,"unitDecimals":8,"alternativeName":"Argentine Peso","alternativeIsoCode":"ARS"}}';
|
|
|
|
|
2014-09-03 09:17:59 -07:00
|
|
|
});
|