tests.
This commit is contained in:
parent
c3774261b4
commit
d5529996ef
@ -463,7 +463,7 @@ Block.prototype._verify = function _verify(ret) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.merkleRoot !== merkle) {
|
if (this.merkleRoot !== merkle) {
|
||||||
ret.reason = 'bad-txnmrkleroot';
|
ret.reason = 'bad-txnmrklroot';
|
||||||
ret.score = 100;
|
ret.score = 100;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,12 +136,15 @@ describe('Block', function() {
|
|||||||
assert(block.verify());
|
assert(block.verify());
|
||||||
assert(block.txs[0].isCoinbase());
|
assert(block.txs[0].isCoinbase());
|
||||||
assert(block.txs[0].isSane());
|
assert(block.txs[0].isSane());
|
||||||
|
assert(!block.hasWitness());
|
||||||
|
assert.equal(block.getCost(), 1136924);
|
||||||
var flags = constants.flags.VERIFY_P2SH | constants.flags.VERIFY_DERSIG;
|
var flags = constants.flags.VERIFY_P2SH | constants.flags.VERIFY_DERSIG;
|
||||||
for (var i = 1; i < block.txs.length; i++) {
|
for (var i = 1; i < block.txs.length; i++) {
|
||||||
var tx = block.txs[i];
|
var tx = block.txs[i];
|
||||||
assert(tx.isSane());
|
assert(tx.isSane());
|
||||||
assert(tx.checkInputs(block.height));
|
assert(tx.checkInputs(block.height));
|
||||||
assert(tx.verify(flags));
|
assert(tx.verify(flags));
|
||||||
|
assert(!tx.hasWitness());
|
||||||
}
|
}
|
||||||
assert.equal(block.getReward(), 2507773345);
|
assert.equal(block.getReward(), 2507773345);
|
||||||
assert.equal(block.getReward(), block.txs[0].outputs[0].value);
|
assert.equal(block.getReward(), block.txs[0].outputs[0].value);
|
||||||
@ -149,9 +152,12 @@ describe('Block', function() {
|
|||||||
|
|
||||||
it('should fail with a bad merkle root', function() {
|
it('should fail with a bad merkle root', function() {
|
||||||
var block2 = new bcoin.block(block);
|
var block2 = new bcoin.block(block);
|
||||||
|
block2.hash();
|
||||||
block2.merkleRoot = constants.NULL_HASH;
|
block2.merkleRoot = constants.NULL_HASH;
|
||||||
delete block2._valid;
|
delete block2._valid;
|
||||||
assert(!block2.verify());
|
var ret = {};
|
||||||
|
assert(!block2.verify(ret));
|
||||||
|
assert.equal(ret.reason, 'bad-txnmrklroot');
|
||||||
delete block2._valid;
|
delete block2._valid;
|
||||||
delete block2._hash;
|
delete block2._hash;
|
||||||
block2.merkleRoot = block.merkleRoot;
|
block2.merkleRoot = block.merkleRoot;
|
||||||
@ -160,8 +166,11 @@ describe('Block', function() {
|
|||||||
|
|
||||||
it('should fail on merkle block with a bad merkle root', function() {
|
it('should fail on merkle block with a bad merkle root', function() {
|
||||||
var mblock2 = new bcoin.merkleblock(mblock);
|
var mblock2 = new bcoin.merkleblock(mblock);
|
||||||
|
mblock2.hash();
|
||||||
mblock2.merkleRoot = constants.NULL_HASH;
|
mblock2.merkleRoot = constants.NULL_HASH;
|
||||||
assert(!mblock2.verify());
|
var ret = {};
|
||||||
|
assert(!mblock2.verify(ret));
|
||||||
|
assert.equal(ret.reason, 'bad-txnmrklroot');
|
||||||
delete mblock2._validPartial;
|
delete mblock2._validPartial;
|
||||||
delete mblock2._valid;
|
delete mblock2._valid;
|
||||||
delete mblock2._hash;
|
delete mblock2._hash;
|
||||||
@ -171,14 +180,25 @@ describe('Block', function() {
|
|||||||
|
|
||||||
it('should fail with a low target', function() {
|
it('should fail with a low target', function() {
|
||||||
var block2 = new bcoin.block(block);
|
var block2 = new bcoin.block(block);
|
||||||
|
block2.hash();
|
||||||
block2.bits = 403014710;
|
block2.bits = 403014710;
|
||||||
assert(!block2.verify());
|
var ret = {};
|
||||||
|
assert(!block2.verify(ret));
|
||||||
|
assert.equal(ret.reason, 'high-hash');
|
||||||
delete block2._valid;
|
delete block2._valid;
|
||||||
delete block2._hash;
|
delete block2._hash;
|
||||||
block2.bits = block.bits;
|
block2.bits = block.bits;
|
||||||
assert(block2.verify());
|
assert(block2.verify());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail on duplicate txs', function() {
|
||||||
|
var block2 = new bcoin.block(block);
|
||||||
|
block2.txs.push(block2.txs[block2.txs.length - 1]);
|
||||||
|
var ret = {};
|
||||||
|
assert(!block2.verify(ret));
|
||||||
|
assert.equal(ret.reason, 'bad-txns-duplicate');
|
||||||
|
});
|
||||||
|
|
||||||
it('should verify with headers', function() {
|
it('should verify with headers', function() {
|
||||||
var headers = new bcoin.headers(block);
|
var headers = new bcoin.headers(block);
|
||||||
assert(headers.verify());
|
assert(headers.verify());
|
||||||
|
|||||||
@ -343,8 +343,28 @@ describe('Script', function() {
|
|||||||
locktime: 0
|
locktime: 0
|
||||||
});
|
});
|
||||||
if (nocache) {
|
if (nocache) {
|
||||||
delete coin._raw;
|
tx._raw = null;
|
||||||
delete tx._raw;
|
tx._size = null;
|
||||||
|
tx._witnessSize = null;
|
||||||
|
tx._lastWitnessSize = 0;
|
||||||
|
tx._hash = null;
|
||||||
|
tx._inputValue = null;
|
||||||
|
tx._outputValue = null;
|
||||||
|
tx._hashPrevouts = null;
|
||||||
|
tx._hashSequence = null;
|
||||||
|
tx._hashOutputs = null;
|
||||||
|
|
||||||
|
coin._raw = null;
|
||||||
|
coin._size = null;
|
||||||
|
coin._witnessSize = null;
|
||||||
|
coin._lastWitnessSize = 0;
|
||||||
|
coin._hash = null;
|
||||||
|
coin._inputValue = null;
|
||||||
|
coin._outputValue = null;
|
||||||
|
coin._hashPrevouts = null;
|
||||||
|
coin._hashSequence = null;
|
||||||
|
coin._hashOutputs = null;
|
||||||
|
|
||||||
delete input.redeem;
|
delete input.redeem;
|
||||||
delete input._address;
|
delete input._address;
|
||||||
delete output._address;
|
delete output._address;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ function clearCache(tx, nocache) {
|
|||||||
if (tx instanceof bcoin.script) {
|
if (tx instanceof bcoin.script) {
|
||||||
if (!nocache)
|
if (!nocache)
|
||||||
return;
|
return;
|
||||||
delete tx.redeem;
|
tx.redeem = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,24 +47,27 @@ function clearCache(tx, nocache) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete tx._raw;
|
tx._raw = null;
|
||||||
delete tx._hash;
|
tx._size = null;
|
||||||
delete tx._inputValue;
|
tx._witnessSize = null;
|
||||||
delete tx._outputValue;
|
tx._lastWitnessSize = 0;
|
||||||
|
tx._hash = null;
|
||||||
tx._size = 0;
|
tx._inputValue = null;
|
||||||
tx._witnessSize = 0;
|
tx._outputValue = null;
|
||||||
|
tx._hashPrevouts = null;
|
||||||
|
tx._hashSequence = null;
|
||||||
|
tx._hashOutputs = null;
|
||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
delete input._address;
|
input._address = null;
|
||||||
delete input.script.redeem;
|
input.script.redeem = null;
|
||||||
delete input.witness.redeem;
|
input.witness.redeem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < tx.outputs.length; i++) {
|
for (i = 0; i < tx.outputs.length; i++) {
|
||||||
output = tx.outputs[i];
|
output = tx.outputs[i];
|
||||||
delete output._address;
|
output._address = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user