Browse Source

start adding script tests

patch-2
Manuel Araoz 11 years ago
parent
commit
bed6ccaac0
  1. 8
      lib/Script.js
  2. 18
      test/test.Script.js

8
lib/Script.js

@ -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

18
test/test.Script.js

@ -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…
Cancel
Save