Address: Increase test coverage
This commit is contained in:
parent
3c9cc23501
commit
9863b123c0
|
@ -77,7 +77,7 @@ Address._transformHash = function(hash){
|
||||||
throw new TypeError('Address supplied is not a buffer.');
|
throw new TypeError('Address supplied is not a buffer.');
|
||||||
}
|
}
|
||||||
if (hash.length !== 20) {
|
if (hash.length !== 20) {
|
||||||
throw new TypeError('Address hashbuffers must be exactly a 20 bytes.');
|
throw new TypeError('Address hashbuffers must be exactly 20 bytes.');
|
||||||
}
|
}
|
||||||
info.hashBuffer = hash;
|
info.hashBuffer = hash;
|
||||||
return info;
|
return info;
|
||||||
|
|
|
@ -202,6 +202,54 @@ describe('Address', function() {
|
||||||
var b = new Address(str).toString().should.equal(str);
|
var b = new Address(str).toString().should.equal(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should error because of unrecognized data format', function() {
|
||||||
|
(function() {
|
||||||
|
var a = new Address(new Error());
|
||||||
|
}).should.throw('First argument is an unrecognized data format.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect format for pubkey hash', function() {
|
||||||
|
(function() {
|
||||||
|
var a = new Address.fromPubkeyHash('notahash');
|
||||||
|
}).should.throw('Address supplied is not a buffer.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect format for script hash', function() {
|
||||||
|
(function() {
|
||||||
|
var a = new Address.fromScriptHash('notascript');
|
||||||
|
}).should.throw('Address supplied is not a buffer.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect type for transform buffer', function() {
|
||||||
|
(function() {
|
||||||
|
var info = Address._transformBuffer('notabuffer');
|
||||||
|
}).should.throw('Address supplied is not a buffer.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect length buffer for transform buffer', function() {
|
||||||
|
(function() {
|
||||||
|
var info = Address._transformBuffer(new Buffer(20));
|
||||||
|
}).should.throw('Address buffers must be exactly 21 bytes.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect type for pubkey transform', function() {
|
||||||
|
(function() {
|
||||||
|
var info = Address._transformPubkey(new Buffer(20));
|
||||||
|
}).should.throw('Address must be an instance of Pubkey.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect type for script transform', function() {
|
||||||
|
(function() {
|
||||||
|
var info = Address._transformScript(new Buffer(20));
|
||||||
|
}).should.throw('Address must be an instance of Script.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error because of incorrect type for string transform', function() {
|
||||||
|
(function() {
|
||||||
|
var info = Address._transformString(new Buffer(20));
|
||||||
|
}).should.throw('Address supplied is not a string.');
|
||||||
|
});
|
||||||
|
|
||||||
it('should make an address from a pubkey hash buffer', function() {
|
it('should make an address from a pubkey hash buffer', function() {
|
||||||
var hash = pubkeyhash; //use the same hash
|
var hash = pubkeyhash; //use the same hash
|
||||||
var a = Address.fromPubkeyHash(hash).toString().should.equal(str);
|
var a = Address.fromPubkeyHash(hash).toString().should.equal(str);
|
||||||
|
@ -214,7 +262,7 @@ describe('Address', function() {
|
||||||
it('should throw an error for invalid length hashBuffer', function() {
|
it('should throw an error for invalid length hashBuffer', function() {
|
||||||
(function() {
|
(function() {
|
||||||
var a = Address.fromPubkeyHash(buf);
|
var a = Address.fromPubkeyHash(buf);
|
||||||
}).should.throw('Address hashbuffers must be exactly a 20 bytes.');
|
}).should.throw('Address hashbuffers must be exactly 20 bytes.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should make this address from a compressed pubkey object', function() {
|
it('should make this address from a compressed pubkey object', function() {
|
||||||
|
@ -240,10 +288,13 @@ describe('Address', function() {
|
||||||
|
|
||||||
it('should make this address from a script', function() {
|
it('should make this address from a script', function() {
|
||||||
var s = Script().fromString("OP_CHECKMULTISIG");
|
var s = Script().fromString("OP_CHECKMULTISIG");
|
||||||
|
var buf = s.toBuffer();
|
||||||
var a = Address.fromScript(s);
|
var a = Address.fromScript(s);
|
||||||
a.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
|
a.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
|
||||||
var b = new Address(s);
|
var b = new Address(s);
|
||||||
b.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
|
b.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
|
||||||
|
var c = Address.fromScriptHash(bitcore.crypto.Hash.sha256ripemd160(buf));
|
||||||
|
c.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should make this address from other script', function() {
|
it('should make this address from other script', function() {
|
||||||
|
@ -316,4 +367,14 @@ describe('Address', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#inspect', function() {
|
||||||
|
|
||||||
|
it('should output formatted output correctly', function() {
|
||||||
|
var address = new Address(str);
|
||||||
|
var output = '<Address: 16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r, type: pubkeyhash, network: mainnet>';
|
||||||
|
address.inspect().should.equal(output);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue