|
|
@ -67,37 +67,53 @@ describe('Transaction', function() { |
|
|
|
*/ |
|
|
|
// Verify that known valid transactions are intepretted correctly
|
|
|
|
var coreTest = function(data, valid) { |
|
|
|
buffertools.extend(); |
|
|
|
data.forEach(function(datum) { |
|
|
|
if (datum.length < 3) return; |
|
|
|
var raw = datum[1]; |
|
|
|
var verifyP2SH = datum[2]; |
|
|
|
|
|
|
|
it.skip((valid ? '' : 'in') + 'valid tx=' + raw, function(done) { |
|
|
|
var cb = function(err, results) { |
|
|
|
should.not.exist(err); |
|
|
|
should.exist(results); |
|
|
|
results.should.equal(valid); |
|
|
|
done(); |
|
|
|
}; |
|
|
|
|
|
|
|
var testTx = parse_test_transaction(datum); |
|
|
|
buffertools.toHex(testTx.transaction.serialize()).should.equal(raw); |
|
|
|
var inputs = testTx.transaction.inputs(); |
|
|
|
for (var i = 0; i < inputs.length; i++) { |
|
|
|
var input = inputs[i]; |
|
|
|
buffertools.reverse(input[0]); |
|
|
|
input[0] = buffertools.toHex(input[0]); |
|
|
|
var mapKey = [input]; |
|
|
|
var scriptPubKey = testTx.inputs[mapKey]; |
|
|
|
if (!scriptPubKey) throw new Error('Bad test: '+datum); |
|
|
|
testTx.transaction.verifyInput( |
|
|
|
i, |
|
|
|
scriptPubKey, { |
|
|
|
verifyP2SH: verifyP2SH, |
|
|
|
dontVerifyStrictEnc: true |
|
|
|
}, |
|
|
|
cb); |
|
|
|
} |
|
|
|
var testTx = parse_test_transaction(datum); |
|
|
|
var tx = testTx.transaction; |
|
|
|
|
|
|
|
describe((valid ? '' : 'in') + 'valid tx=' + raw, function() { |
|
|
|
it('should parse correctly', function() { |
|
|
|
buffertools.toHex(tx.serialize()).toLowerCase().should.equal(raw.toLowerCase()); |
|
|
|
}); |
|
|
|
|
|
|
|
var inputs = tx.inputs(); |
|
|
|
var j = 0; |
|
|
|
inputs.forEach(function(input) { |
|
|
|
var i = j; |
|
|
|
j += 1; |
|
|
|
it('should validate input #' + i, function(done) { |
|
|
|
|
|
|
|
var outpointHash = new Buffer(input[0].length); |
|
|
|
input[0].copy(outpointHash); |
|
|
|
input[0] = buffertools.reverse(outpointHash); |
|
|
|
input[0] = buffertools.toHex(input[0]); |
|
|
|
var mapKey = [input]; |
|
|
|
var scriptPubKey = testTx.inputs[mapKey]; |
|
|
|
if (!scriptPubKey) throw new Error('Bad test: ' + datum); |
|
|
|
tx.verifyInput( |
|
|
|
i, |
|
|
|
scriptPubKey, { |
|
|
|
verifyP2SH: verifyP2SH, |
|
|
|
dontVerifyStrictEnc: true |
|
|
|
}, |
|
|
|
function(err, results) { |
|
|
|
if (valid) { |
|
|
|
should.not.exist(err); |
|
|
|
should.exist(results); |
|
|
|
results.should.equal(valid); |
|
|
|
} else { |
|
|
|
var invalid = (typeof err !== 'undefined') || results === false; |
|
|
|
invalid.should.equal(true); |
|
|
|
} |
|
|
|
done(); |
|
|
|
} |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|