Skip to content

Commit

Permalink
Merge pull request #1 from dashevo/govobj.verifyaddress
Browse files Browse the repository at this point in the history
Merging Govobj.verifyaddress - fix for verifyAddress.
  • Loading branch information
Alex-Werner committed May 8, 2017
2 parents dfed9f9 + 8965f34 commit e80be6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 2 additions & 6 deletions lib/govobject/govobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,8 @@ GovObject.prototype._verifyPayment = function(payment) {
return Boolean((parsedPayment <= 0));
};

GovObject.prototype._verifyAddress = function(address) {
return address.length > 26;
// - disable full check until checksum bug in Ubuntu Firefox is fixed

// var validAddress = Address.isValid(address, network);
// return validAddress;
GovObject.prototype._verifyAddress = function(address, network) {
return Address.isValid(address, network);
};

GovObject.prototype._verifyUrl = function(url) {
Expand Down
4 changes: 2 additions & 2 deletions lib/govobject/types/proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ Proposal.prototype.getSerializationError = function(opts) {
return new errors.GovObject.Proposal.invalidDateWindow();
}

// verify address (only verifies length > 26)
if (!this._verifyAddress(this.payment_address)) {
// verify address
if (!this._verifyAddress(this.payment_address, this.network)) {
return new errors.GovObject.Proposal.invalidAddress();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitcore-lib-dash",
"version": "0.13.20",
"version": "0.13.21",
"description": "A pure and powerful JavaScript Dash library.",
"author": "BitPay <dev@bitpay.com>",
"main": "index.js",
Expand Down
14 changes: 14 additions & 0 deletions test/govobject/govobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ describe('GovObject', function(){
expect(govObjRes).to.not.throw('Unhandled GovObject type');
govObject.serialize().should.equal(expectedHex);
})
it('should validate address', function(){
var govObject = new GovObject;
govObject._verifyAddress('yXGeNPQXYFXhLAN1ZKrAjxzzBnZ2JZNKnh','testnet').should.equal(true);
govObject._verifyAddress('XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B6','livenet').should.equal(true);
govObject._verifyAddress('XuYDEzZzKxn&&knPDiVKe91sJasfajkshfjD1nQnnn5B6','livenet').should.equal(false);
govObject._verifyAddress('knPDiVKe91sJasfajkshfjD1nQnnn5B6','testnet').should.equal(false);
govObject._verifyAddress('XuYDEzZzKxn&&knPDiVKe91sJa/sfajkshfjD1nQnnn5B6','livenet').should.equal(false);
govObject._verifyAddress('XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B','livenet').should.equal(false);
govObject._verifyAddress(' XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B','livenet').should.equal(false);
govObject._verifyAddress('XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B ','livenet').should.equal(false);
govObject._verifyAddress('$XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B','livenet').should.equal(false);
govObject._verifyAddress('yXGeNPQXYFXhLAN1ZKrAjxzzBnZ2JZNKnh','livenet').should.equal(false);
govObject._verifyAddress('XuYDEzZzKxnknPDiVKe91sJaD1nQnnn5B6','testnet').should.equal(false);
})
it('should cast a stringified JSON Proposal into a Proposal Object', function(){
var govObject = new GovObject;
var jsonProposal = {
Expand Down

0 comments on commit e80be6e

Please sign in to comment.