start adding script tests

This commit is contained in:
Manuel Araoz 2014-07-25 13:03:15 -03:00
parent 26f6770139
commit bed6ccaac0
2 changed files with 22 additions and 4 deletions

View File

@ -115,8 +115,8 @@ Script.prototype.isMultiSig = function() {
this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG); this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG);
}; };
Script.prototype.isPubkeyHashScript = function() { Script.prototype.isPubkeyHashScriptSig = function() {
// TODO: add more restrictions to chunks // TODO: add more restrictions to chunks?
return (this.chunks.length == 2 && return (this.chunks.length == 2 &&
Buffer.isBuffer(this.chunks[0]) && Buffer.isBuffer(this.chunks[0]) &&
Buffer.isBuffer(this.chunks[1])); Buffer.isBuffer(this.chunks[1]));
@ -149,7 +149,7 @@ Script.prototype.countSignatures = function() {
ret = l - 2; ret = l - 2;
} }
// p2pubkeyhash // p2pubkeyhash
else if (this.isPubkeyHashScript()) { else if (this.isPubkeyHashScriptSig()) {
ret = 1; ret = 1;
} }
// p2pubkey // p2pubkey
@ -176,7 +176,7 @@ Script.prototype.getSignatures = function() {
} }
} }
// p2pubkeyhash // p2pubkeyhash
else if (this.isPubkeyHashScript()) { else if (this.isPubkeyHashScriptSig()) {
ret.push(this.chunks[0]); ret.push(this.chunks[0]);
} }
// p2pubkey // p2pubkey

View File

@ -191,5 +191,23 @@ describe('Script', function() {
}); });
}); });
describe('#isPubkeyHashScriptSig', function() {
var testPKHSS = function(raw, result) {
var s = new Script(new Buffer(raw, 'hex');
s.isPubkeyHashScriptSig().should.equal(result);
};
it('should identify pubkeyhash scriptsig', function() {
testPKHSS(pkhss, true);
});
it('should not identify pubkey scriptsig', function() {
testPKHSS(pkss, false);
});
it('should not identify p2sh scriptsig', function() {
testPKHSS(p2shss, false);
});
it('should not identify multisig scriptsig', function() {
testPKHSS(msss, false);
});
});
}); });