fixed Script parse tests for all scripts (valid and invalid)
This commit is contained in:
parent
e83590f528
commit
dc56cb8d45
|
@ -270,13 +270,14 @@ function spec(b) {
|
|||
var split = s.split(' ');
|
||||
for (var i = 0; i < split.length; i++) {
|
||||
var word = split[i];
|
||||
if (word === '') continue;
|
||||
if (word.length > 2 && word.substring(0, 2) === '0x') {
|
||||
// raw hex value
|
||||
//console.log('hex value');
|
||||
chunks.push(new Buffer(word.substring(2, word.length), 'hex'));
|
||||
} else {
|
||||
var opcode = Opcode.map['OP_' + word];
|
||||
if (opcode) {
|
||||
if (typeof opcode !== 'undefined') {
|
||||
// op code in string form
|
||||
//console.log('opcode');
|
||||
chunks.push(opcode);
|
||||
|
@ -297,7 +298,7 @@ function spec(b) {
|
|||
}
|
||||
chunks.push(new Buffer(hex,'hex'));
|
||||
} else {
|
||||
throw new Error('Could not parse word from script: ' +word);
|
||||
throw new Error('Could not parse word "' +word+'" from script "'+s+'"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,6 +393,8 @@ function spec(b) {
|
|||
// (x1 x2 - bool)
|
||||
var v1 = this.stackTop(2);
|
||||
var v2 = this.stackTop(1);
|
||||
console.log(v1);
|
||||
console.log(v2);
|
||||
var value = buffertools.compare(v1, v2) === 0;
|
||||
|
||||
// OP_NOTEQUAL is disabled because it would be too easy to say
|
||||
|
|
|
@ -84,7 +84,7 @@ describe('Script', function() {
|
|||
});
|
||||
});
|
||||
|
||||
test_data.dataScriptValid.forEach(function(datum) {
|
||||
test_data.dataScriptAll.forEach(function(datum) {
|
||||
if (datum.length < 2) throw new Error('Invalid test data');
|
||||
var human = datum[0] + ' ' + datum[1];
|
||||
it('should parse script from human readable ' + human, function() {
|
||||
|
|
19
util/util.js
19
util/util.js
|
@ -111,18 +111,27 @@ var intTo64Bits = function(integer) {
|
|||
lo: (integer & 0xFFFFFFFF) >>> 0
|
||||
};
|
||||
};
|
||||
var fitsIn32Bits = function(integer) {
|
||||
var fitsInNBits = function(integer, n) {
|
||||
// TODO: make this efficient!!!
|
||||
return integer.toString(2).replace('-','').length < 32;
|
||||
return integer.toString(2).replace('-','').length < n;
|
||||
}
|
||||
exports.intToBuffer = function(integer) {
|
||||
if (fitsIn32Bits(integer)) {
|
||||
var data = new Buffer(4);
|
||||
var data = null;
|
||||
if (fitsInNBits(integer, 8)) {
|
||||
data = new Buffer(1);
|
||||
data.writeInt8(integer, 0);
|
||||
return data;
|
||||
} else if (fitsInNBits(integer, 16)) {
|
||||
data = new Buffer(2);
|
||||
data.writeInt16LE(integer, 0);
|
||||
return data;
|
||||
} else if (fitsInNBits(integer, 32)) {
|
||||
data = new Buffer(4);
|
||||
data.writeInt32LE(integer, 0);
|
||||
return data;
|
||||
} else {
|
||||
var x = intTo64Bits(integer);
|
||||
var data = new Buffer(8);
|
||||
data = new Buffer(8);
|
||||
data.writeInt32LE(x.hi, 0); // high part contains sign information (signed)
|
||||
data.writeUInt32LE(x.lo, 4); // low part encoded as unsigned integer
|
||||
return data;
|
||||
|
|
Loading…
Reference in New Issue