commit
26470e5804
|
@ -23,7 +23,6 @@ var errors = {
|
||||||
NOT_AUTHORIZED: 'Not authorized',
|
NOT_AUTHORIZED: 'Not authorized',
|
||||||
TOO_MANY_KEYS: 'Too many keys registered',
|
TOO_MANY_KEYS: 'Too many keys registered',
|
||||||
TX_ALREADY_BROADCASTED: 'The transaction proposal is already broadcasted',
|
TX_ALREADY_BROADCASTED: 'The transaction proposal is already broadcasted',
|
||||||
TX_ALREADY_EXISTS: 'A transaction proposal with the same id already exists',
|
|
||||||
TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time',
|
TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time',
|
||||||
TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime',
|
TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime',
|
||||||
TX_MAX_SIZE_EXCEEDED: 'TX exceeds maximum allowed size',
|
TX_MAX_SIZE_EXCEEDED: 'TX exceeds maximum allowed size',
|
||||||
|
|
|
@ -1776,15 +1776,7 @@ WalletService.prototype.createTx = function(opts, cb) {
|
||||||
|
|
||||||
function checkTxpAlreadyExists(txProposalId, cb) {
|
function checkTxpAlreadyExists(txProposalId, cb) {
|
||||||
if (!txProposalId) return cb();
|
if (!txProposalId) return cb();
|
||||||
|
self.storage.fetchTx(self.walletId, txProposalId, cb);
|
||||||
self.storage.fetchTx(self.walletId, txProposalId, function(err, txp) {
|
|
||||||
if (err || !txp) return cb(err);
|
|
||||||
if (txp.status == 'temporary') {
|
|
||||||
return cb(null, txp);
|
|
||||||
} else {
|
|
||||||
return cb(Errors.TX_ALREADY_EXISTS);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self._runLocked(cb, function(cb) {
|
self._runLocked(cb, function(cb) {
|
||||||
|
|
|
@ -2308,6 +2308,84 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should create a tx with foreign ID', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, 2, function() {
|
||||||
|
var txOpts = {
|
||||||
|
txProposalId: '123',
|
||||||
|
outputs: [{
|
||||||
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||||
|
amount: 1e8,
|
||||||
|
}],
|
||||||
|
feePerKb: 100e2,
|
||||||
|
};
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(tx);
|
||||||
|
tx.id.should.equal('123');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should return already created tx if same foreign ID is specified and tx still unpublished', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, 2, function() {
|
||||||
|
var txOpts = {
|
||||||
|
txProposalId: '123',
|
||||||
|
outputs: [{
|
||||||
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||||
|
amount: 1e8,
|
||||||
|
}],
|
||||||
|
feePerKb: 100e2,
|
||||||
|
};
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(tx);
|
||||||
|
tx.id.should.equal('123');
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(tx);
|
||||||
|
tx.id.should.equal('123');
|
||||||
|
server.storage.fetchTxs(wallet.id, {}, function(err, txs) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(txs);
|
||||||
|
txs.length.should.equal(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should return already published tx if same foreign ID is specified and tx already published', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, [2, 2, 2], function() {
|
||||||
|
var txOpts = {
|
||||||
|
txProposalId: '123',
|
||||||
|
outputs: [{
|
||||||
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||||
|
amount: 1e8,
|
||||||
|
}],
|
||||||
|
feePerKb: 100e2,
|
||||||
|
};
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(tx);
|
||||||
|
tx.id.should.equal('123');
|
||||||
|
var publishOpts = helpers.getProposalSignatureOpts(tx, TestData.copayers[0].privKey_1H_0);
|
||||||
|
server.publishTx(publishOpts, function(err) {
|
||||||
|
should.not.exist(err);
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(tx);
|
||||||
|
tx.id.should.equal('123');
|
||||||
|
tx.status.should.equal('pending');
|
||||||
|
server.storage.fetchTxs(wallet.id, {}, function(err, txs) {
|
||||||
|
should.not.exist(err);
|
||||||
|
txs.length.should.equal(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should be able to publish a temporary tx proposal', function(done) {
|
it('should be able to publish a temporary tx proposal', function(done) {
|
||||||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||||
var txOpts = {
|
var txOpts = {
|
||||||
|
|
Loading…
Reference in New Issue