Browse Source

fix a browser test

patch-2
Manuel Araoz 10 years ago
parent
commit
6c5198b743
  1. 14
      lib/script.js
  2. 4
      test/script.js

14
lib/script.js

@ -3,9 +3,9 @@
var BufferReader = require('./encoding/bufferreader');
var BufferWriter = require('./encoding/bufferwriter');
var Opcode = require('./opcode');
var Address = require('./address');
var PublicKey = require('./publickey');
var Hash = require('./crypto/hash');
var bu = require('./util/buffer');
var Script = function Script(from) {
if (!(this instanceof Script)) {
@ -14,7 +14,7 @@ var Script = function Script(from) {
this.chunks = [];
if (Buffer.isBuffer(from)) {
if (bu.isBuffer(from)) {
return Script.fromBuffer(from);
} else if (typeof from === 'string') {
return Script.fromString(from);
@ -205,7 +205,7 @@ Script.prototype.isPublicKeyHashIn = function() {
*/
Script.prototype.isPublicKeyOut = function() {
return this.chunks.length === 2 &&
Buffer.isBuffer(this.chunks[0].buf) &&
bu.isBuffer(this.chunks[0].buf) &&
PublicKey.isValid(this.chunks[0].buf) &&
this.chunks[1] === Opcode('OP_CHECKSIG').toNumber();
};
@ -215,7 +215,7 @@ Script.prototype.isPublicKeyOut = function() {
*/
Script.prototype.isPublicKeyIn = function() {
return this.chunks.length === 1 &&
Buffer.isBuffer(this.chunks[0].buf) &&
bu.isBuffer(this.chunks[0].buf) &&
this.chunks[0].buf.length === 0x47;
};
@ -259,7 +259,7 @@ Script.prototype.isMultisigOut = function() {
return (this.chunks.length > 3 &&
Opcode.isSmallIntOp(this.chunks[0]) &&
this.chunks.slice(1, this.chunks.length - 2).every(function(obj) {
return obj.buf && Buffer.isBuffer(obj.buf);
return obj.buf && bu.isBuffer(obj.buf);
}) &&
Opcode.isSmallIntOp(this.chunks[this.chunks.length - 2]) &&
this.chunks[this.chunks.length - 1] === Opcode.map.OP_CHECKMULTISIG);
@ -273,7 +273,7 @@ Script.prototype.isMultisigIn = function() {
return this.chunks[0] === 0 &&
this.chunks.slice(1, this.chunks.length).every(function(obj) {
return obj.buf &&
Buffer.isBuffer(obj.buf) &&
bu.isBuffer(obj.buf) &&
obj.buf.length === 0x47;
});
};
@ -367,7 +367,7 @@ Script.prototype._addByType = function(obj, prepend) {
this._addOpcode(obj, prepend);
} else if (obj.constructor && obj.constructor.name && obj.constructor.name === 'Opcode') {
this._addOpcode(obj, prepend);
} else if (Buffer.isBuffer(obj)) {
} else if (bu.isBuffer(obj)) {
this._addBuffer(obj, prepend);
} else if (typeof obj === 'object') {
this._insertAtPosition(obj, prepend);

4
test/script.js

@ -458,10 +458,10 @@ describe('Script', function() {
});
describe('#buildScriptHashOut', function() {
it('should create script from another script', function() {
var inner = new Script('OP_DUP OP_HASH160 06c06f6d931d7bfba2b5bd5ad0d19a8f257af3e3 OP_EQUALVERIFY OP_CHECKSIG');
var inner = new Script('OP_DUP OP_HASH160 20 0x06c06f6d931d7bfba2b5bd5ad0d19a8f257af3e3 OP_EQUALVERIFY OP_CHECKSIG');
var s = Script.buildScriptHashOut(inner);
should.exist(s);
s.toString().should.equal('OP_HASH160 20 0xb96d20131e15d948aa9196e477e9611d8e43c8f0 OP_EQUAL');
s.toString().should.equal('OP_HASH160 20 0x45ea3f9133e7b1cef30ba606f8433f993e41e159 OP_EQUAL');
s.isScriptHashOut().should.equal(true);
});
});

Loading…
Cancel
Save