Browse Source

cleaner code

activeAddress
Ivan Socolsky 10 years ago
parent
commit
15b79bfd79
  1. 283
      test/integration.js

283
test/integration.js

@ -1158,26 +1158,52 @@ describe('Copay server', function() {
var txpId; var txpId;
async.waterfall([ async.waterfall([
function(next) { function(next) {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey); var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey);
server.createTx(txOpts, function(err, txp) { server.createTx(txOpts, function(err, txp) {
txpId = txp.id; txpId = txp.id;
should.not.exist(err); should.not.exist(err);
should.exist.txp; should.exist.txp;
next(); next();
}); });
}, },
function(next) { function(next) {
server.getPendingTxs({}, function(err, txps) { server.getPendingTxs({}, function(err, txps) {
should.not.exist(err); should.not.exist(err);
txps.length.should.equal(1); txps.length.should.equal(1);
var txp = txps[0]; var txp = txps[0];
_.keys(txp.actions).should.be.empty; _.keys(txp.actions).should.be.empty;
next(null, txp); next(null, txp);
}); });
}, },
function(txp, next) { function(txp, next) {
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey); 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({ server.signTx({
txProposalId: txpId, txProposalId: txpId,
signatures: signatures, signatures: signatures,
@ -1185,143 +1211,110 @@ describe('Copay server', function() {
should.not.exist(err); should.not.exist(err);
next(); next();
}); });
}, });
function(next) { },
server.getPendingTxs({}, function(err, txps) { function(next) {
should.not.exist(err); server.getPendingTxs({}, function(err, txps) {
txps.length.should.equal(1); should.not.exist(err);
var txp = txps[0]; txps.length.should.equal(0);
txp.isPending().should.be.true; next();
txp.isRejected().should.be.false; });
txp.isAccepted().should.be.false; },
_.keys(txp.actions).length.should.equal(1); function(next) {
var action = txp.actions[wallet.copayers[0].id]; server.getTx({
action.type.should.equal('accept'); id: txpId
next(null, txp); }, function(err, txp) {
}); should.not.exist(err);
}, txp.isPending().should.be.false;
function(txp, next) { txp.isRejected().should.be.false;
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) { txp.isAccepted().should.be.true;
helpers.stubBlockExplorer(server, utxos, '999'); txp.isBroadcasted().should.be.true;
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey); txp.txid.should.equal('999');
server.signTx({ _.keys(txp.actions).length.should.equal(2);
txProposalId: txpId, done();
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) { it('tx proposals should accept as many rejections as possible without finally rejecting', function(done) {
var txpId; var txpId;
async.waterfall([ async.waterfall([
function(next) { function(next) {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey); var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey);
server.createTx(txOpts, function(err, txp) { server.createTx(txOpts, function(err, txp) {
txpId = txp.id; txpId = txp.id;
should.not.exist(err); should.not.exist(err);
should.exist.txp; should.exist.txp;
next(); next();
}); });
}, },
function(next) { function(next) {
server.getPendingTxs({}, function(err, txps) { server.getPendingTxs({}, function(err, txps) {
should.not.exist(err); should.not.exist(err);
txps.length.should.equal(1); txps.length.should.equal(1);
var txp = txps[0]; var txp = txps[0];
_.keys(txp.actions).should.be.empty; _.keys(txp.actions).should.be.empty;
next(); next();
}); });
}, },
function(next) { function(next) {
server.rejectTx({
txProposalId: txpId,
reason: 'just because'
}, 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('reject');
action.comment.should.equal('just because');
next();
});
},
function(next) {
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) {
helpers.stubBlockExplorer(server, utxos, '999');
server.rejectTx({ server.rejectTx({
txProposalId: txpId, txProposalId: txpId,
reason: 'just because' reason: 'some other reason'
}, function(err) { }, function(err) {
should.not.exist(err); should.not.exist(err);
next(); next();
}); });
}, });
function(next) { },
server.getPendingTxs({}, function(err, txps) { function(next) {
should.not.exist(err); server.getPendingTxs({}, function(err, txps) {
txps.length.should.equal(1); should.not.exist(err);
var txp = txps[0]; txps.length.should.equal(0);
txp.isPending().should.be.true; next();
txp.isRejected().should.be.false; });
txp.isAccepted().should.be.false; },
_.keys(txp.actions).length.should.equal(1); function(next) {
var action = txp.actions[wallet.copayers[0].id]; server.getTx({
action.type.should.equal('reject'); id: txpId
action.comment.should.equal('just because'); }, function(err, txp) {
next(); should.not.exist(err);
}); txp.isPending().should.be.false;
}, txp.isRejected().should.be.true;
function(next) { txp.isAccepted().should.be.false;
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) { _.keys(txp.actions).length.should.equal(2);
helpers.stubBlockExplorer(server, utxos, '999'); done();
server.rejectTx({ });
txProposalId: txpId, },
reason: 'some other reason' ]);
}, 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.true;
txp.isAccepted().should.be.false;
_.keys(txp.actions).length.should.equal(2);
next();
});
},
],
function() {
done();
});
}); });
}); });

Loading…
Cancel
Save