check reserialized tx hashes in tx tests.

This commit is contained in:
Christopher Jeffrey 2016-04-19 07:08:00 -07:00
parent 80e6126f0c
commit 716d94ec9b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 15 additions and 9 deletions

View File

@ -203,10 +203,7 @@ describe('Script', function() {
comments += ' (' + expected + ')';
if (witness)
witness = bcoin.witness.fromTestString(witness);
else
witness = new bcoin.witness();
witness = bcoin.witness.fromTestString(witness);
input = bcoin.script.fromTestString(input);
output = bcoin.script.fromTestString(output);

View File

@ -25,15 +25,20 @@ function parseTX(file) {
function clearCache(tx, nocache) {
var i, input, output;
if (!nocache)
return;
if (tx instanceof bcoin.script) {
if (!nocache)
return;
delete tx.raw;
return;
}
delete tx.raw;
if (!nocache) {
assert.equal(tx.hash('hex'), tx.clone().hash('hex'));
return;
}
delete tx._raw;
delete tx._hash;
for (i = 0; i < tx.inputs.length; i++) {
input = tx.inputs[i];
@ -179,7 +184,6 @@ describe('TX', function() {
}
var tx = data.tx;
clearCache(tx, nocache);
var flags = data.flags;
var comments = comment.trim();
if (!comments)
@ -189,27 +193,32 @@ describe('TX', function() {
if (valid) {
if (comments.indexOf('Coinbase') === 0) {
it('should handle valid coinbase' + suffix + ': ' + comments, function () {
clearCache(tx, nocache);
assert.ok(tx.isSane());
});
return;
}
it('should handle valid tx test' + suffix + ': ' + comments, function () {
clearCache(tx, nocache);
assert.ok(tx.verify(null, true, flags));
});
} else {
if (comments === 'Duplicate inputs') {
it('should handle duplicate input test' + suffix + ': ' + comments, function () {
clearCache(tx, nocache);
assert.ok(!tx.isSane());
});
return;
}
if (comments.indexOf('Coinbase') === 0) {
it('should handle invalid coinbase' + suffix + ': ' + comments, function () {
clearCache(tx, nocache);
assert.ok(!tx.isSane());
});
return;
}
it('should handle invalid tx test' + suffix + ': ' + comments, function () {
clearCache(tx, nocache);
assert.ok(!tx.verify(null, true, flags));
});
}