tests with and without caching.
This commit is contained in:
parent
5bf0824000
commit
80e6126f0c
@ -30,11 +30,9 @@ describe('Script', function() {
|
|||||||
assert.equal(dst.toString('hex'), src);
|
assert.equal(dst.toString('hex'), src);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (0)
|
|
||||||
it('should encode/decode numbers', function() {
|
it('should encode/decode numbers', function() {
|
||||||
var script = [ 0, 1, 2, 16 ];
|
var script = [ 0, 0x51, 0x52, 0x60 ];
|
||||||
var encoded = bcoin.script.encode(script);
|
var encoded = bcoin.script.encode(script);
|
||||||
assert.deepEqual(encoded, [ 0, 0x51, 0x52, 0x60 ]);
|
|
||||||
var decoded = bcoin.script.decode(encoded);
|
var decoded = bcoin.script.decode(encoded);
|
||||||
assert.deepEqual(decoded, script);
|
assert.deepEqual(decoded, script);
|
||||||
});
|
});
|
||||||
@ -218,7 +216,9 @@ describe('Script', function() {
|
|||||||
}
|
}
|
||||||
flags = flag;
|
flags = flag;
|
||||||
|
|
||||||
it('should handle script test: ' + comments, function () {
|
[false, true].forEach(function(nocache) {
|
||||||
|
var suffix = nocache ? ' without cache' : ' with cache';
|
||||||
|
it('should handle script test' + suffix + ': ' + comments, function () {
|
||||||
var coin = bcoin.tx({
|
var coin = bcoin.tx({
|
||||||
version: 1,
|
version: 1,
|
||||||
inputs: [{
|
inputs: [{
|
||||||
@ -255,6 +255,10 @@ describe('Script', function() {
|
|||||||
}],
|
}],
|
||||||
locktime: 0
|
locktime: 0
|
||||||
});
|
});
|
||||||
|
if (nocache) {
|
||||||
|
delete input.raw;
|
||||||
|
delete output.raw;
|
||||||
|
}
|
||||||
var res = Script.verify(input, witness, output, tx, 0, flags);
|
var res = Script.verify(input, witness, output, tx, 0, flags);
|
||||||
if (expected === 'OK')
|
if (expected === 'OK')
|
||||||
assert.ok(res);
|
assert.ok(res);
|
||||||
@ -263,3 +267,4 @@ describe('Script', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -22,6 +22,32 @@ function parseTX(file) {
|
|||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearCache(tx, nocache) {
|
||||||
|
var i, input, output;
|
||||||
|
|
||||||
|
if (!nocache)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tx instanceof bcoin.script) {
|
||||||
|
delete tx.raw;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete tx.raw;
|
||||||
|
|
||||||
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
|
input = tx.inputs[i];
|
||||||
|
delete input.script.raw;
|
||||||
|
if (input.coin)
|
||||||
|
delete input.coin.script.raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < tx.outputs.length; i++) {
|
||||||
|
output = tx.outputs[i];
|
||||||
|
delete output.script.raw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('TX', function() {
|
describe('TX', function() {
|
||||||
var parser = bcoin.protocol.parser;
|
var parser = bcoin.protocol.parser;
|
||||||
var raw = '010000000125393c67cd4f581456dd0805fa8e9db3abdf90dbe1d4b53e28' +
|
var raw = '010000000125393c67cd4f581456dd0805fa8e9db3abdf90dbe1d4b53e28' +
|
||||||
@ -61,28 +87,38 @@ describe('TX', function() {
|
|||||||
'0f7c00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b' +
|
'0f7c00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b' +
|
||||||
'2e88ac00000000';
|
'2e88ac00000000';
|
||||||
|
|
||||||
it('should decode/encode with parser/framer', function() {
|
[false, true].forEach(function(nocache) {
|
||||||
|
var suffix = nocache ? ' without cache' : ' with cache';
|
||||||
|
|
||||||
|
it('should decode/encode with parser/framer' + suffix, function() {
|
||||||
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
||||||
|
clearCache(tx, nocache);
|
||||||
assert.equal(tx.render().toString('hex'), raw);
|
assert.equal(tx.render().toString('hex'), raw);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be verifiable', function() {
|
it('should be verifiable' + suffix, function() {
|
||||||
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
||||||
var p = bcoin.tx(parser.parseTX(new Buffer(inp, 'hex')));
|
var p = bcoin.tx(parser.parseTX(new Buffer(inp, 'hex')));
|
||||||
tx.fillCoins(p);
|
tx.fillCoins(p);
|
||||||
|
|
||||||
|
clearCache(tx, nocache);
|
||||||
|
clearCache(p, nocache);
|
||||||
|
|
||||||
assert(tx.verify());
|
assert(tx.verify());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify non-minimal output', function() {
|
it('should verify non-minimal output' + suffix, function() {
|
||||||
|
clearCache(tx1, nocache);
|
||||||
assert(tx1.verify(null, true, constants.flags.VERIFY_P2SH));
|
assert(tx1.verify(null, true, constants.flags.VERIFY_P2SH));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify tx.version == 0', function() {
|
it('should verify tx.version == 0' + suffix, function() {
|
||||||
|
clearCache(tx2, nocache);
|
||||||
assert(tx2.verify(null, true, constants.flags.VERIFY_P2SH));
|
assert(tx2.verify(null, true, constants.flags.VERIFY_P2SH));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify sighash_single bug w/ findanddelete', function() {
|
it('should verify sighash_single bug w/ findanddelete' + suffix, function() {
|
||||||
|
clearCache(tx3, nocache);
|
||||||
assert(tx3.verify(null, true, constants.flags.VERIFY_P2SH));
|
assert(tx3.verify(null, true, constants.flags.VERIFY_P2SH));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -143,6 +179,7 @@ describe('TX', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tx = data.tx;
|
var tx = data.tx;
|
||||||
|
clearCache(tx, nocache);
|
||||||
var flags = data.flags;
|
var flags = data.flags;
|
||||||
var comments = comment.trim();
|
var comments = comment.trim();
|
||||||
if (!comments)
|
if (!comments)
|
||||||
@ -151,28 +188,28 @@ describe('TX', function() {
|
|||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (comments.indexOf('Coinbase') === 0) {
|
if (comments.indexOf('Coinbase') === 0) {
|
||||||
it('should handle valid coinbase: ' + comments, function () {
|
it('should handle valid coinbase' + suffix + ': ' + comments, function () {
|
||||||
assert.ok(tx.isSane());
|
assert.ok(tx.isSane());
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it('should handle valid tx test: ' + comments, function () {
|
it('should handle valid tx test' + suffix + ': ' + comments, function () {
|
||||||
assert.ok(tx.verify(null, true, flags));
|
assert.ok(tx.verify(null, true, flags));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (comments === 'Duplicate inputs') {
|
if (comments === 'Duplicate inputs') {
|
||||||
it('should handle duplicate input test: ' + comments, function () {
|
it('should handle duplicate input test' + suffix + ': ' + comments, function () {
|
||||||
assert.ok(!tx.isSane());
|
assert.ok(!tx.isSane());
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (comments.indexOf('Coinbase') === 0) {
|
if (comments.indexOf('Coinbase') === 0) {
|
||||||
it('should handle invalid coinbase: ' + comments, function () {
|
it('should handle invalid coinbase' + suffix + ': ' + comments, function () {
|
||||||
assert.ok(!tx.isSane());
|
assert.ok(!tx.isSane());
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it('should handle invalid tx test: ' + comments, function () {
|
it('should handle invalid tx test' + suffix + ': ' + comments, function () {
|
||||||
assert.ok(!tx.verify(null, true, flags));
|
assert.ok(!tx.verify(null, true, flags));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -184,7 +221,9 @@ describe('TX', function() {
|
|||||||
if (data.length === 1)
|
if (data.length === 1)
|
||||||
return;
|
return;
|
||||||
var tx = bcoin.tx.fromRaw(data[0], 'hex');
|
var tx = bcoin.tx.fromRaw(data[0], 'hex');
|
||||||
|
clearCache(tx, nocache);
|
||||||
var script = new bcoin.script(new Buffer(data[1], 'hex'));
|
var script = new bcoin.script(new Buffer(data[1], 'hex'));
|
||||||
|
clearCache(script, nocache);
|
||||||
var index = data[2];
|
var index = data[2];
|
||||||
var type = data[3];
|
var type = data[3];
|
||||||
var expected = utils.revHex(data[4]);
|
var expected = utils.revHex(data[4]);
|
||||||
@ -194,10 +233,11 @@ describe('TX', function() {
|
|||||||
hexType = hexType.toString(16);
|
hexType = hexType.toString(16);
|
||||||
if (hexType.length % 2 !== 0)
|
if (hexType.length % 2 !== 0)
|
||||||
hexType = '0' + hexType;
|
hexType = '0' + hexType;
|
||||||
it('should get signature hash of ' + data[4] + ' (' + hexType + ')', function () {
|
it('should get signature hash of ' + data[4] + ' (' + hexType + ')' + suffix, function () {
|
||||||
var subscript = script.getSubscript();
|
var subscript = script.getSubscript();
|
||||||
var hash = tx.signatureHash(index, subscript, type, 0).toString('hex');
|
var hash = tx.signatureHash(index, subscript, type, 0).toString('hex');
|
||||||
assert.equal(hash, expected);
|
assert.equal(hash, expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user