Fixes Script test case for coverage and style

This commit is contained in:
Esteban Ordano 2014-12-30 15:33:52 -03:00
parent c1a1571535
commit ffca4cfb6f
2 changed files with 9 additions and 17 deletions

View File

@ -709,11 +709,11 @@ Script.prototype.toAddress = function(network) {
$.checkArgument(network, 'Must provide a network'); $.checkArgument(network, 'Must provide a network');
if (this.isPublicKeyHashOut()) { if (this.isPublicKeyHashOut()) {
return new Address(this.getData(), network, Address.PayToPublicKeyHash); return new Address(this.getData(), network, Address.PayToPublicKeyHash);
} } else if (this.isScriptHashOut()) {
if (this.isScriptHashOut()) {
return new Address(this.getData(), network, Address.PayToScriptHash); 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');
}; };
/** /**

View File

@ -585,13 +585,9 @@ describe('Script', function() {
expect(BufferUtil.equal(Script('OP_RETURN 1 0xFF').getData(), new Buffer([255]))).to.be.true(); expect(BufferUtil.equal(Script('OP_RETURN 1 0xFF').getData(), new Buffer([255]))).to.be.true();
}); });
it('fails if content is not recognized', function() { it('fails if content is not recognized', function() {
var failed = false; expect(function() {
try { return Script('1 0xFF').getData();
Script('1 0xFF').getData(); }).to.throw();
} catch (e) {
failed = true;
}
failed.should.equal(true);
}); });
}); });
@ -609,13 +605,9 @@ describe('Script', function() {
script.toAddress(Networks.livenet).toString().should.equal(stringAddress); script.toAddress(Networks.livenet).toString().should.equal(stringAddress);
}); });
it('fails if content is not recognized', function() { it('fails if content is not recognized', function() {
var failed = false; expect(function() {
try { return Script().toAddress(Networks.livenet);
Script().toAddress(); }).to.throw();
} catch (e) {
failed = true;
}
failed.should.equal(true);
}); });
}); });