mempool tests.

This commit is contained in:
Christopher Jeffrey 2016-05-23 19:53:00 -07:00
parent 9c89630490
commit 2fe481659c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -141,6 +141,76 @@ describe('Mempool', function() {
});
});
it('should handle locktime', function(cb) {
var w = new bcoin.wallet();
// Coinbase
var t1 = bcoin.mtx().addOutput(w, 50000).addOutput(w, 10000); // 10000 instead of 1000
var prev = new bcoin.script([w.publicKey, opcodes.OP_CHECKSIG]);
var prevHash = bcoin.ec.random(32).toString('hex');
var dummyInput = {
prevout: {
hash: prevHash,
index: 0
},
coin: {
version: 1,
height: 0,
value: 70000,
script: prev,
coinbase: false,
hash: prevHash,
index: 0
},
script: new bcoin.script([]),
sequence: 0xffffffff
};
t1.addInput(dummyInput);
t1.setLocktime(200);
chain.tip.height = 200;
t1.inputs[0].script = new bcoin.script([t1.createSignature(0, prev, w.privateKey, 'all', 0)]),
mempool.addTX(t1, function(err) {
chain.tip.height = 0;
assert.ifError(err);
cb();
});
});
it('should handle invalid locktime', function(cb) {
var w = new bcoin.wallet();
// Coinbase
var t1 = bcoin.mtx().addOutput(w, 50000).addOutput(w, 10000); // 10000 instead of 1000
var prev = new bcoin.script([w.publicKey, opcodes.OP_CHECKSIG]);
var prevHash = bcoin.ec.random(32).toString('hex');
var dummyInput = {
prevout: {
hash: prevHash,
index: 0
},
coin: {
version: 1,
height: 0,
value: 70000,
script: prev,
coinbase: false,
hash: prevHash,
index: 0
},
script: new bcoin.script([]),
sequence: 0xffffffff
};
t1.addInput(dummyInput);
t1.setLocktime(200);
chain.tip.height = 200 - 1;
t1.inputs[0].script = new bcoin.script([t1.createSignature(0, prev, w.privateKey, 'all', 0)]),
mempool.addTX(t1, function(err) {
chain.tip.height = 0;
assert(err);
cb();
});
});
it('should destroy mempool', function(cb) {
mempool.close(cb);
});