fix tests and amount
This commit is contained in:
parent
93b3e1db86
commit
2d70a54c6f
|
@ -152,7 +152,7 @@ API.prototype._initData = function(network, walletPrivKey, m, n) {
|
||||||
var xPrivKey = new Bitcore.HDPrivateKey(network);
|
var xPrivKey = new Bitcore.HDPrivateKey(network);
|
||||||
var signingPrivKey = (new Bitcore.HDPrivateKey(xPrivKey)).derive('m/1/0').privateKey.toWIF();
|
var signingPrivKey = (new Bitcore.HDPrivateKey(xPrivKey)).derive('m/1/0').privateKey.toWIF();
|
||||||
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
|
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
|
||||||
var copayerId = WalletUtils.xpubToCopayerId(xPubKey);
|
var copayerId = WalletUtils.xPubToCopayerId(xPubKey);
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
copayerId: copayerId,
|
copayerId: copayerId,
|
||||||
|
@ -279,6 +279,10 @@ API.prototype.getStatus = function(cb) {
|
||||||
|
|
||||||
var url = '/v1/wallets/';
|
var url = '/v1/wallets/';
|
||||||
self._doGetRequest(url, data, function(err, body) {
|
self._doGetRequest(url, data, function(err, body) {
|
||||||
|
_.each(body.pendingTxps, function(txp) {
|
||||||
|
txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey);
|
||||||
|
});
|
||||||
|
|
||||||
return cb(err, body, data.copayerId);
|
return cb(err, body, data.copayerId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -413,7 +417,7 @@ API.prototype.getTxProposals = function(opts, cb) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
_.each(txps, function(txp) {
|
_.each(txps, function(txp) {
|
||||||
txp.message = self._decryptProposalMessage(txp.message, data.signingPrivKey);
|
txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey);
|
||||||
});
|
});
|
||||||
return cb(null, txps);
|
return cb(null, txps);
|
||||||
});
|
});
|
||||||
|
|
|
@ -90,6 +90,7 @@ TxProposal.prototype._getBitcoreTx = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var t = new Bitcore.Transaction();
|
var t = new Bitcore.Transaction();
|
||||||
|
|
||||||
_.each(this.inputs, function(i) {
|
_.each(this.inputs, function(i) {
|
||||||
t.from(i, i.publicKeys, self.requiredSignatures)
|
t.from(i, i.publicKeys, self.requiredSignatures)
|
||||||
});
|
});
|
||||||
|
@ -99,7 +100,6 @@ TxProposal.prototype._getBitcoreTx = function() {
|
||||||
|
|
||||||
t._updateChangeOutput();
|
t._updateChangeOutput();
|
||||||
|
|
||||||
|
|
||||||
var sigs = this._getCurrentSignatures();
|
var sigs = this._getCurrentSignatures();
|
||||||
_.each(sigs, function(x) {
|
_.each(sigs, function(x) {
|
||||||
self._addSignaturesToBitcoreTx(t, x.signatures, x.xpub);
|
self._addSignaturesToBitcoreTx(t, x.signatures, x.xpub);
|
||||||
|
|
|
@ -378,6 +378,8 @@ CopayServer.prototype._getUtxos = function(cb) {
|
||||||
|
|
||||||
// Needed for the clients to sign UTXOs
|
// Needed for the clients to sign UTXOs
|
||||||
_.each(utxos, function(utxo) {
|
_.each(utxos, function(utxo) {
|
||||||
|
utxo.satoshis = utxo.satoshis ? +utxo.satoshis : Utils.strip(utxo.amount * 1e8);
|
||||||
|
delete utxo.amount;
|
||||||
utxo.path = addressToPath[utxo.address].path;
|
utxo.path = addressToPath[utxo.address].path;
|
||||||
utxo.publicKeys = addressToPath[utxo.address].publicKeys;
|
utxo.publicKeys = addressToPath[utxo.address].publicKeys;
|
||||||
});
|
});
|
||||||
|
@ -402,13 +404,13 @@ CopayServer.prototype.getBalance = function(opts, cb) {
|
||||||
|
|
||||||
var balance = {};
|
var balance = {};
|
||||||
balance.totalAmount = Utils.strip(_.reduce(utxos, function(sum, utxo) {
|
balance.totalAmount = Utils.strip(_.reduce(utxos, function(sum, utxo) {
|
||||||
return sum + self._inputSatoshis(utxo);
|
return sum + utxo.satoshis;
|
||||||
}, 0));
|
}, 0));
|
||||||
|
|
||||||
balance.lockedAmount = Utils.strip(_.reduce(_.filter(utxos, {
|
balance.lockedAmount = Utils.strip(_.reduce(_.filter(utxos, {
|
||||||
locked: true
|
locked: true
|
||||||
}), function(sum, utxo) {
|
}), function(sum, utxo) {
|
||||||
return sum + self._inputSatoshis(utxo);
|
return sum + utxo.satoshis;
|
||||||
}, 0));
|
}, 0));
|
||||||
|
|
||||||
return cb(null, balance);
|
return cb(null, balance);
|
||||||
|
@ -416,11 +418,6 @@ CopayServer.prototype.getBalance = function(opts, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// TODO: should be in Utils
|
|
||||||
CopayServer.prototype._inputSatoshis = function(i) {
|
|
||||||
return i.amount ? Utils.strip(i.amount * 1e8) : i.satoshis;
|
|
||||||
};
|
|
||||||
|
|
||||||
CopayServer.prototype._selectUtxos = function(txp, utxos) {
|
CopayServer.prototype._selectUtxos = function(txp, utxos) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var total = 0;
|
var total = 0;
|
||||||
|
@ -429,7 +426,7 @@ CopayServer.prototype._selectUtxos = function(txp, utxos) {
|
||||||
|
|
||||||
while (i < inputs.length) {
|
while (i < inputs.length) {
|
||||||
selected.push(inputs[i]);
|
selected.push(inputs[i]);
|
||||||
total += this._inputSatoshis(inputs[i]);
|
total += inputs[i].satoshis;
|
||||||
|
|
||||||
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) {
|
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -172,7 +172,7 @@ describe('client API ', function() {
|
||||||
|
|
||||||
describe('#getTxProposals', function() {
|
describe('#getTxProposals', function() {
|
||||||
it('should return tx proposals and decrypt message', function(done) {
|
it('should return tx proposals and decrypt message', function(done) {
|
||||||
client.storage.fs.readFile = sinon.stub().yields(null, JSON.stringify(TestData.storage.complete22));
|
client.storage.fs.readFile = sinon.stub().yields(null, JSON.stringify(TestData.storage.complete11));
|
||||||
var request = sinon.mock().yields(null, {
|
var request = sinon.mock().yields(null, {
|
||||||
statusCode: 200
|
statusCode: 200
|
||||||
}, TestData.serverResponse.pendingTxs);
|
}, TestData.serverResponse.pendingTxs);
|
||||||
|
@ -182,7 +182,7 @@ describe('client API ', function() {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
x.length.should.equal(1);
|
x.length.should.equal(1);
|
||||||
x[0].id.should.equal(TestData.serverResponse.pendingTxs[0].id);
|
x[0].id.should.equal(TestData.serverResponse.pendingTxs[0].id);
|
||||||
x[0].message.should.equal('test');
|
x[0].message.should.equal('hola');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,6 +30,16 @@ var storage = {
|
||||||
"signingPrivKey": "KyhU3befBaePqHuPQNNyY1XFUgnArR3GUKZpZwV5vS7u1pcR3uzB",
|
"signingPrivKey": "KyhU3befBaePqHuPQNNyY1XFUgnArR3GUKZpZwV5vS7u1pcR3uzB",
|
||||||
"network": "livenet"
|
"network": "livenet"
|
||||||
},
|
},
|
||||||
|
complete11: {
|
||||||
|
"copayerId": "02da4d1bd797b41a5565fe54f22583051bd3c29dbbc86eedadb6af6e9200af1048",
|
||||||
|
"xPrivKey": "tprv8ZgxMBicQKsPeCyWCzmvnAkJUBEKpqggFmEmaR6CeyHeJj8oB8uFRWZonK7qLD1ih35tiRr1xnXg9a2rGLiYGQWVgvjhubzuUvVyanPXNuU",
|
||||||
|
"publicKeyRing": ["tpubD6NzVbkrYhZ4Xg1J6eSXBaQR3CkFzAsaq4qYrw8W5F639DPZoXiqc1BfxSR2J1muzEE2qq7rZEDUgwyuwv1nYQgA9uorLghrT76FE5CjAuz"],
|
||||||
|
"network": "testnet",
|
||||||
|
"m": 1,
|
||||||
|
"n": 1,
|
||||||
|
"signingPrivKey": "Kzs8tquNTCsxwbEB9RiSNmcti4QXaW1i9UyLBV329VM5zU7o5nGB",
|
||||||
|
"walletPrivKey": "L259i9W123MrrEjBUTzPVvo3ZMoJV26WB7Abr9LcVsiuWpj6sEL1"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var serverResponse = {
|
var serverResponse = {
|
||||||
|
@ -126,32 +136,30 @@ var serverResponse = {
|
||||||
},
|
},
|
||||||
pendingTxs: [{
|
pendingTxs: [{
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
createdOn: 1424280917,
|
createdOn: 1424287779,
|
||||||
id: '0142428091712494d9e6a3-dbdc-4a59-a1fb-225f39f5a024',
|
id: '01424287779165d80a7123-f5c4-4144-ac1b-663220c01c55',
|
||||||
creatorId: '0399e8f038c092f3c13345f2975dc048ffdff7786daa11edc569ecdf253941d6ef',
|
creatorId: '02da4d1bd797b41a5565fe54f22583051bd3c29dbbc86eedadb6af6e9200af1048',
|
||||||
toAddress: 'n2TBMPzPECGUfcT2EByiTJ12TPZkhN2mN5',
|
toAddress: 'n2TBMPzPECGUfcT2EByiTJ12TPZkhN2mN5',
|
||||||
amount: '10000',
|
amount: 10000,
|
||||||
message: '{"iv":"DSQtJyxpHpEenAXR0R+0zg==","v":1,"iter":1,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","ct":"XUOT38qT8JV08Ll7"}',
|
message: '{"iv":"Ij6LjNp6Cjlrpx1MklQk9A==","v":1,"iter":1,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","ct":"uyxcL8bBgRS0W2KA"}',
|
||||||
changeAddress: '2NFX68fh3qkWP11geyVArsjkc7sWwtEdKeX',
|
changeAddress: '2Mu4nmHhBWFk766M4yXJi2oyi59HZLKHWqn',
|
||||||
inputs: [{
|
inputs: [{
|
||||||
address: '2MwKHNRTm1EdUUbwZ8dsqaqp58ACge6Uekn',
|
address: '2MvBhgsQX6EusXvNGdcjM5dschDkaos1uuk',
|
||||||
txid: '6b25d0a580d86befb4d094ffecd891abb1fc58508456d8a40b75183c98f481ed',
|
txid: '006a2915d8f1811620f8b83357869a94c53714f90ce4be4a5ca0d5305a21400d',
|
||||||
vout: 0,
|
vout: 0,
|
||||||
scriptPubKey: 'a9142ca4fd690042933f3336dd6c8f9f5daa8ab7b50a87',
|
scriptPubKey: 'a914203dd60a7659995a6e3bba7caac3c2d684c836ce87',
|
||||||
amount: 0.1,
|
amount: 0.1,
|
||||||
path: 'm/2147483647/0/0',
|
path: 'm/2147483647/0/0',
|
||||||
publicKeys: ['028c00c47a3df50868875cc7b8eb7ababf6c19e4a037c9f893fea5c2f975274606',
|
publicKeys: ['0371629fe3547002723ef57ad4dae0d97653cf89b0a570637cffca2f23982f0f92']
|
||||||
'02f2ab07b43a4b7df05475c0a910a3fb10c8f9ae84dac67a85cbf71bc3ca177968',
|
|
||||||
'0223874637af10e54b7004899b0aa66a60376fa520de7b9f5ee19a9fb0957ebc13'
|
|
||||||
]
|
|
||||||
}],
|
}],
|
||||||
requiredSignatures: 2,
|
requiredSignatures: 1,
|
||||||
requiredRejections: 2,
|
requiredRejections: 1,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
inputPaths: ['m/2147483647/0/0'],
|
inputPaths: ['m/2147483647/0/0'],
|
||||||
actions: {},
|
actions: {},
|
||||||
creatorName: 'ematiu'
|
creatorName: 'ematiu'
|
||||||
}],
|
}],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.serverResponse = serverResponse;
|
module.exports.serverResponse = serverResponse;
|
||||||
|
|
|
@ -664,7 +664,6 @@ describe('Copay server', function() {
|
||||||
|
|
||||||
it('should create a tx', function(done) {
|
it('should create a tx', function(done) {
|
||||||
helpers.createUtxos(server, wallet, [100, 200], function(utxos) {
|
helpers.createUtxos(server, wallet, [100, 200], function(utxos) {
|
||||||
|
|
||||||
helpers.stubBlockExplorer(server, utxos);
|
helpers.stubBlockExplorer(server, utxos);
|
||||||
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey);
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey);
|
||||||
server.createTx(txOpts, function(err, tx) {
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
|
Loading…
Reference in New Issue