start adding script tests
This commit is contained in:
parent
26f6770139
commit
bed6ccaac0
|
@ -115,8 +115,8 @@ Script.prototype.isMultiSig = function() {
|
|||
this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG);
|
||||
};
|
||||
|
||||
Script.prototype.isPubkeyHashScript = function() {
|
||||
// TODO: add more restrictions to chunks
|
||||
Script.prototype.isPubkeyHashScriptSig = function() {
|
||||
// TODO: add more restrictions to chunks?
|
||||
return (this.chunks.length == 2 &&
|
||||
Buffer.isBuffer(this.chunks[0]) &&
|
||||
Buffer.isBuffer(this.chunks[1]));
|
||||
|
@ -149,7 +149,7 @@ Script.prototype.countSignatures = function() {
|
|||
ret = l - 2;
|
||||
}
|
||||
// p2pubkeyhash
|
||||
else if (this.isPubkeyHashScript()) {
|
||||
else if (this.isPubkeyHashScriptSig()) {
|
||||
ret = 1;
|
||||
}
|
||||
// p2pubkey
|
||||
|
@ -176,7 +176,7 @@ Script.prototype.getSignatures = function() {
|
|||
}
|
||||
}
|
||||
// p2pubkeyhash
|
||||
else if (this.isPubkeyHashScript()) {
|
||||
else if (this.isPubkeyHashScriptSig()) {
|
||||
ret.push(this.chunks[0]);
|
||||
}
|
||||
// p2pubkey
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue