add test to reject
This commit is contained in:
parent
7975bb2499
commit
324c058303
|
@ -93,10 +93,32 @@ TxProposal.prototype.getRawTx = function() {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* getActors
|
||||
*
|
||||
* @return {String[]} copayerIds that performed actions in this proposal (accept / reject)
|
||||
*/
|
||||
TxProposal.prototype.getActors = function() {
|
||||
return _.keys(this.actions);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* getActionBy
|
||||
*
|
||||
* @param {String} copayerId
|
||||
* @return {Object} type / createdOn
|
||||
*/
|
||||
TxProposal.prototype.getActionBy = function(copayerId) {
|
||||
var a = this.actions[copayerId];
|
||||
if (!a) return null;
|
||||
|
||||
return {
|
||||
type: a.type,
|
||||
createdOn: a.createdOn,
|
||||
};
|
||||
};
|
||||
|
||||
TxProposal.prototype.addAction = function(copayerId, type, signatures) {
|
||||
var action = new TxProposalAction({
|
||||
copayerId: copayerId,
|
||||
|
|
|
@ -66,7 +66,7 @@ helpers.createAndJoinWallet = function(m, n, cb) {
|
|||
|
||||
helpers.getAuthServer(copayerIds[0], function(s) {
|
||||
s.getWallet({}, function(err, w) {
|
||||
cb(s, w, _.take(TestData.copayers, w.n));
|
||||
cb(s, w, _.take(TestData.copayers, w.n), copayerIds);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -765,14 +765,66 @@ describe('Copay server', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#signTx', function() {
|
||||
var server, wallet, copayerPriv, txid;
|
||||
|
||||
describe('#rejectTx', function() {
|
||||
var server, wallet, copayerPriv, txid, copayerIds;
|
||||
|
||||
beforeEach(function(done) {
|
||||
helpers.createAndJoinWallet(2, 2, function(s, w, c) {
|
||||
helpers.createAndJoinWallet(2, 2, function(s, w, c, ids) {
|
||||
server = s;
|
||||
wallet = w;
|
||||
copayerPriv = c;
|
||||
copayerIds = ids;
|
||||
server.createAddress({}, function(err, address) {
|
||||
helpers.createUtxos(server, wallet, helpers.toSatoshi([1, 2, 3, 4, 5, 6, 7, 8]), function(utxos) {
|
||||
helpers.stubBlockExplorer(server, utxos);
|
||||
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, copayerPriv[0].privKey);
|
||||
server.createTx(txOpts, function(err, tx) {
|
||||
should.not.exist(err);
|
||||
tx.should.exist;
|
||||
txid = tx.id;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject a TX', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
|
||||
server.rejectTx({
|
||||
txProposalId: txid,
|
||||
}, function(err) {
|
||||
should.not.exist(err);
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
should.not.exist(err);
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
|
||||
var actors = tx.getActors();
|
||||
actors.length.should.equal(1);
|
||||
actors[0].should.equal(copayerIds[0]);
|
||||
tx.getActionBy(copayerIds[0]).type.should.equal('reject');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#signTx', function() {
|
||||
var server, wallet, copayerPriv, txid, copayerIds;
|
||||
|
||||
beforeEach(function(done) {
|
||||
helpers.createAndJoinWallet(2, 2, function(s, w, c, ids) {
|
||||
server = s;
|
||||
wallet = w;
|
||||
copayerPriv = c;
|
||||
copayerIds = ids;
|
||||
server.createAddress({}, function(err, address) {
|
||||
helpers.createUtxos(server, wallet, helpers.toSatoshi([1, 2, 3, 4, 5, 6, 7, 8]), function(utxos) {
|
||||
helpers.stubBlockExplorer(server, utxos);
|
||||
|
@ -799,10 +851,21 @@ describe('Copay server', function() {
|
|||
signatures: signatures,
|
||||
}, function(err) {
|
||||
should.not.exist(err);
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
should.not.exist(err);
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
|
||||
var actors = tx.getActors();
|
||||
actors.length.should.equal(1);
|
||||
actors[0].should.equal(copayerIds[0]);
|
||||
tx.getActionBy(copayerIds[0]).type.should.equal('accept');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if one signature is broken', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
|
@ -836,6 +899,47 @@ describe('Copay server', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when signing a TX previously rejected', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
|
||||
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey, wallet.n);
|
||||
server.signTx({
|
||||
txProposalId: txid,
|
||||
signatures: signatures,
|
||||
}, function(err) {
|
||||
server.rejectTx({
|
||||
txProposalId: txid,
|
||||
}, function(err) {
|
||||
err.code.should.contain('CVOTED');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when rejected a previously signed TX', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
|
||||
server.rejectTx({
|
||||
txProposalId: txid,
|
||||
}, function(err) {
|
||||
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey, wallet.n);
|
||||
server.signTx({
|
||||
txProposalId: txid,
|
||||
signatures: signatures,
|
||||
}, function(err) {
|
||||
err.code.should.contain('CVOTED');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue