test acceptance flow

This commit is contained in:
Ivan Socolsky 2015-02-15 16:15:45 -03:00
parent bcdd807395
commit 9020c70dd2
2 changed files with 97 additions and 6 deletions

View File

@ -198,7 +198,7 @@ TxProposal.prototype.reject = function(copayerId, reason) {
};
TxProposal.prototype.isPending = function() {
return !_.contains(['boradcasted', 'rejected'], this.status);
return !_.contains(['broadcasted', 'rejected'], this.status);
};
TxProposal.prototype.isAccepted = function() {
@ -211,6 +211,10 @@ TxProposal.prototype.isRejected = function() {
return votes['reject'] >= this.requiredRejections;
};
TxProposal.prototype.isBroadcasted = function() {
return this.status == 'broadcasted';
};
TxProposal.prototype.setBroadcasted = function(txid) {
this.txid = txid;
this.status = 'broadcasted';

View File

@ -1122,14 +1122,15 @@ describe('Copay server', function() {
});
describe('Tx proposal workflow', function() {
var server, wallet;
var server, wallet, utxos;
beforeEach(function(done) {
helpers.createAndJoinWallet(2, 3, function(s, w) {
server = s;
wallet = w;
server.createAddress({}, function(err, address) {
helpers.createUtxos(server, wallet, _.range(1, 9), function(utxos) {
helpers.stubBlockExplorer(server, utxos);
helpers.createUtxos(server, wallet, _.range(1, 9), function(inUtxos) {
utxos = inUtxos;
helpers.stubBlockExplorer(server, utxos, '999');
done();
});
});
@ -1153,11 +1154,96 @@ describe('Copay server', function() {
});
});
it.skip('tx proposals should not be broadcast until quorum is reached', function(done) {});
it('tx proposals should not be broadcast until quorum is reached', function(done) {
var txpId;
async.waterfall([
function(next) {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey);
server.createTx(txOpts, function(err, txp) {
txpId = txp.id;
should.not.exist(err);
should.exist.txp;
next();
});
},
function(next) {
server.getPendingTxs({}, function(err, txps) {
should.not.exist(err);
txps.length.should.equal(1);
var txp = txps[0];
_.keys(txp.actions).should.be.empty;
next(null, txp);
});
},
function(txp, next) {
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey);
server.signTx({
txProposalId: txpId,
signatures: signatures,
}, function(err) {
should.not.exist(err);
next();
});
},
function(next) {
server.getPendingTxs({}, function(err, txps) {
should.not.exist(err);
txps.length.should.equal(1);
var txp = txps[0];
txp.isPending().should.be.true;
txp.isRejected().should.be.false;
txp.isAccepted().should.be.false;
_.keys(txp.actions).length.should.equal(1);
var action = txp.actions[wallet.copayers[0].id];
action.type.should.equal('accept');
next(null, txp);
});
},
function(txp, next) {
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) {
helpers.stubBlockExplorer(server, utxos, '999');
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
server.signTx({
txProposalId: txpId,
signatures: signatures,
}, function(err) {
should.not.exist(err);
next();
});
});
},
function(next) {
server.getPendingTxs({}, function(err, txps) {
should.not.exist(err);
txps.length.should.equal(0);
next();
});
},
function(next) {
server.getTx({
id: txpId
}, function(err, txp) {
should.not.exist(err);
txp.isPending().should.be.false;
txp.isRejected().should.be.false;
txp.isAccepted().should.be.true;
txp.isBroadcasted().should.be.true;
txp.txid.should.equal('999');
_.keys(txp.actions).length.should.equal(2);
next();
});
},
],
function() {
done();
});
});
it('tx proposals should accept as many rejections as possible without finally rejecting', function(done) {
var txpId;
async.series([
async.waterfall([
function(next) {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey);
@ -1203,6 +1289,7 @@ describe('Copay server', function() {
},
function(next) {
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) {
helpers.stubBlockExplorer(server, utxos, '999');
server.rejectTx({
txProposalId: txpId,
reason: 'some other reason'