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