Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge 5a890c0 into 9b11eca
Browse files Browse the repository at this point in the history
  • Loading branch information
isocolsky committed May 17, 2016
2 parents 9b11eca + 5a890c0 commit 3810d7b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 59 deletions.
25 changes: 23 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ API.prototype._processTxps = function(txps) {
txp.hasUnconfirmedInputs = _.any(txp.inputs, function(input) {
return input.confirmations == 0;
});
if (txp.note) {
txp.note.encryptedEditedByName = txp.note.editedByName;
txp.note.editedByName = API._decryptMessage(txp.note.editedByName, encryptingKey);
}
});
};

Expand Down Expand Up @@ -2140,8 +2144,8 @@ API.prototype.startScan = function(opts, cb) {
});
};

/*
Adds access to the current copayer
/**
* Adds access to the current copayer
* @param {Object} opts
* @param {bool} opts.generateNewKey Optional: generate a new key for the new access
* @param {string} opts.restrictions
Expand Down Expand Up @@ -2180,6 +2184,23 @@ API.prototype.addAccess = function(opts, cb) {
});
};

/**
* Edit a note associated to the specified txid
* @param {Object} opts
* @param {string} opts.txid - The txid to associate this note with
* @param {string} opts.body - The contents of the note
*/
API.prototype.editTxNote = function(opts, cb) {
$.checkState(this.credentials && this.credentials.canSign());

opts = opts || {};

this._doPutRequest('/v1/txnotes/' + opts.txid + '/', opts, function(err, res) {
return cb(err);
});

};

/**
* Returns exchange rate for the specified currency & timestamp.
* @param {Object} opts
Expand Down
130 changes: 73 additions & 57 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3299,7 +3299,7 @@ describe('client API', function() {
});
});
});
it('should get transaction history decorated with proposal', function(done) {
it('should get transaction history decorated with proposal & notes', function(done) {
async.waterfall([

function(next) {
Expand Down Expand Up @@ -3337,6 +3337,14 @@ describe('client API', function() {
});
});
},
function(txp, next) {
clients[1].editTxNote({
txid: txp.txid,
body: 'just a note'
}, function(err) {
return next(err, txp);
});
},
function(txp, next) {
var history = _.cloneDeep(TestData.history);
history[0].txid = txp.txid;
Expand All @@ -3357,6 +3365,11 @@ describe('client API', function() {
});
should.exist(rejection);
rejection.comment.should.equal('some reason');

var note = decorated.note;
should.exist(note);
note.body.should.equal('just a note');
note.editedByName.should.equal('copayer 1');
next();
});
}
Expand Down Expand Up @@ -4722,6 +4735,7 @@ describe('client API', function() {
});
});
});

describe('#formatAmount', function() {
it('should successfully format amount', function() {
var cases = [{
Expand Down Expand Up @@ -4817,76 +4831,79 @@ describe('client API', function() {
});
});

describe('import', function(done) {
it('should handle import with invalid JSON', function(done) {
var importString = 'this is not valid JSON';
var client = new Client();
(function() {
client.import(importString);
}).should.throw(Errors.INVALID_BACKUP);
done();
describe('Import', function() {

describe('#import', function(done) {
it('should handle import with invalid JSON', function(done) {
var importString = 'this is not valid JSON';
var client = new Client();
(function() {
client.import(importString);
}).should.throw(Errors.INVALID_BACKUP);
done();
});
});
});

describe('_import', function() {
it('should handle not being able to add access', function(done) {
var sandbox = sinon.sandbox.create();
var client = new Client();
client.credentials = {};
describe('#_import', function() {
it('should handle not being able to add access', function(done) {
var sandbox = sinon.sandbox.create();
var client = new Client();
client.credentials = {};

var ow = sandbox.stub(client, 'openWallet', function(callback) {
callback(new Error());
});
var ow = sandbox.stub(client, 'openWallet', function(callback) {
callback(new Error());
});

var ip = sandbox.stub(client, 'isPrivKeyExternal', function() {
return false;
});
var ip = sandbox.stub(client, 'isPrivKeyExternal', function() {
return false;
});

var aa = sandbox.stub(client, 'addAccess', function(options, callback) {
callback(new Error());
});
var aa = sandbox.stub(client, 'addAccess', function(options, callback) {
callback(new Error());
});

client._import(function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.WALLET_DOES_NOT_EXIST);
sandbox.restore();
done();
client._import(function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.WALLET_DOES_NOT_EXIST);
sandbox.restore();
done();
});
});
});
});

describe('importFromMnemonic', function() {
it('should handle importing an invalid mnemonic', function(done) {
var client = new Client();
var mnemonicWords = 'this is an invalid mnemonic';
client.importFromMnemonic(mnemonicWords, {}, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
describe('#importFromMnemonic', function() {
it('should handle importing an invalid mnemonic', function(done) {
var client = new Client();
var mnemonicWords = 'this is an invalid mnemonic';
client.importFromMnemonic(mnemonicWords, {}, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
});
});
});
});

describe('importFromExtendedPrivateKey', function() {
it('should handle importing an invalid extended private key', function(done) {
var client = new Client();
var xPrivKey = 'this is an invalid key';
client.importFromExtendedPrivateKey(xPrivKey, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
describe('#importFromExtendedPrivateKey', function() {
it('should handle importing an invalid extended private key', function(done) {
var client = new Client();
var xPrivKey = 'this is an invalid key';
client.importFromExtendedPrivateKey(xPrivKey, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
});
});
});
});

describe('importFromExtendedPublicKey', function() {
it('should handle importing an invalid extended private key', function(done) {
var client = new Client();
var xPubKey = 'this is an invalid key';
client.importFromExtendedPublicKey(xPubKey, {}, {}, {}, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
describe('#importFromExtendedPublicKey', function() {
it('should handle importing an invalid extended private key', function(done) {
var client = new Client();
var xPubKey = 'this is an invalid key';
client.importFromExtendedPublicKey(xPubKey, {}, {}, {}, function(err) {
should.exist(err);
err.should.be.an.instanceOf(Errors.INVALID_BACKUP);
done();
});
});
});
});
Expand Down Expand Up @@ -4932,5 +4949,4 @@ describe('client API', function() {
});
});
});

});

0 comments on commit 3810d7b

Please sign in to comment.