diff --git a/lib/script/script.js b/lib/script/script.js index 55b43c11e..f72bad188 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -709,11 +709,11 @@ Script.prototype.toAddress = function(network) { $.checkArgument(network, 'Must provide a network'); if (this.isPublicKeyHashOut()) { return new Address(this.getData(), network, Address.PayToPublicKeyHash); - } - if (this.isScriptHashOut()) { + } else if (this.isScriptHashOut()) { return new Address(this.getData(), network, Address.PayToScriptHash); + } else { + throw new Error('The script type needs to be PayToPublicKeyHash or PayToScriptHash'); } - throw new Error('The script type needs to be PayToPublicKeyHash or PayToScriptHash'); }; /** diff --git a/test/script/script.js b/test/script/script.js index 5ea71769c..48dbfb9e6 100644 --- a/test/script/script.js +++ b/test/script/script.js @@ -585,13 +585,9 @@ describe('Script', function() { expect(BufferUtil.equal(Script('OP_RETURN 1 0xFF').getData(), new Buffer([255]))).to.be.true(); }); it('fails if content is not recognized', function() { - var failed = false; - try { - Script('1 0xFF').getData(); - } catch (e) { - failed = true; - } - failed.should.equal(true); + expect(function() { + return Script('1 0xFF').getData(); + }).to.throw(); }); }); @@ -609,13 +605,9 @@ describe('Script', function() { script.toAddress(Networks.livenet).toString().should.equal(stringAddress); }); it('fails if content is not recognized', function() { - var failed = false; - try { - Script().toAddress(); - } catch (e) { - failed = true; - } - failed.should.equal(true); + expect(function() { + return Script().toAddress(Networks.livenet); + }).to.throw(); }); });