Browse Source

fix tests

activeAddress
Ivan Socolsky 10 years ago
parent
commit
50c217c994
  1. 100
      test/integration.js

100
test/integration.js

@ -177,68 +177,70 @@ var db, storage;
describe('Copay server', function() { describe('Copay server', function() {
beforeEach(function() { beforeEach(function() {
db = levelup(memdown, { db = levelup(memdown, {
valueEncoding: 'json' valueEncoding: 'json'
});
storage = new Storage({
db: db
});
CopayServer.initialize({
storage: storage
});
}); });
storage = new Storage({
db: db
});
CopayServer.initialize({
storage: storage
});
});
describe('#getInstanceWithAuth', function() { describe('#getInstanceWithAuth', function() {
beforeEach(function() {}); beforeEach(function() {});
it('should get server instance for existing copayer', function(done) { it('should get server instance for existing copayer', function(done) {
helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) { helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) {
var xpriv = copayers[0].xPrivKey; var xpriv = copayers[0].xPrivKey;
var priv = Bitcore.HDPrivateKey var priv = Bitcore.HDPrivateKey
.fromString(xpriv) .fromString(xpriv)
.derive('m/1/0') .derive('m/1/0')
.privateKey .privateKey
.toString(); .toString();
var message = 'hola'; var message = 'hola';
var sig = SignUtils.sign(message, priv); var sig = SignUtils.sign(message, priv);
CopayServer.getInstanceWithAuth({ CopayServer.getInstanceWithAuth({
copayerId: copayerIds[0], copayerId: copayerIds[0],
message: message, message: message,
signature: sig, signature: sig,
}, function(err, server) { }, function(err, server) {
should.not.exist(err); should.not.exist(err);
done(); done();
});
});
}); });
});
});
it('should fail when requesting for non-existent copayer', function(done) {
CopayServer.getInstanceWithAuth({
copayerId: 'ads',
message: TestData.message.text,
signature: TestData.message.signature,
}, function(err, server) {
err.code.should.equal('NOTAUTHORIZED');
err.message.should.contain('Copayer not found');
done();
});
});
it('should fail when requesting for non-existent copayer', function(done) { it('should fail when message signature cannot be verified', function(done) {
helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) {
CopayServer.getInstanceWithAuth({ CopayServer.getInstanceWithAuth({
copayerId: 'ads', copayerId: copayerIds[0],
message: 'dummy', message: 'dummy',
signature: 'dummy', signature: 'dummy',
}, function(err, server) { }, function(err, server) {
err.should.contain('Copayer not found'); err.code.should.equal('NOTAUTHORIZED');
err.message.should.contain('Invalid signature');
done(); done();
}); });
}); });
it('should fail when message signature cannot be verified', function(done) {
helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) {
CopayServer.getInstanceWithAuth({
copayerId: copayerIds[0],
message: 'dummy',
signature: 'dummy',
}, function(err, server) {
err.should.contain('Invalid signature');
done();
});
});
});
}); });
});
describe('#createWallet', function() { describe('#createWallet', function() {
var server; var server;
@ -1253,8 +1255,8 @@ describe('Copay server', function() {
server.getNotifications({ server.getNotifications({
limit: 5, limit: 5,
reverse: true, reverse: true,
maxTs: Date.now()/1000, maxTs: Date.now() / 1000,
minTs: Date.now()/1000-1000, minTs: Date.now() / 1000 - 1000,
}, function(err, notifications) { }, function(err, notifications) {
should.not.exist(err); should.not.exist(err);
var types = _.pluck(notifications, 'type'); var types = _.pluck(notifications, 'type');

Loading…
Cancel
Save