diff --git a/test/mempool-test.js b/test/mempool-test.js index 00335016..335b35de 100644 --- a/test/mempool-test.js +++ b/test/mempool-test.js @@ -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); });