From 175f169504f2f23c1f7dd51a175bacabd1dd4dca Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 19 Oct 2017 14:53:10 -0700 Subject: [PATCH] test: add more wallet double spend tests. --- test/wallet-test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/wallet-test.js b/test/wallet-test.js index 5df77e45..07633f7c 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -479,6 +479,29 @@ describe('Wallet', function() { } }); + it('should handle double-spend (not our input)', async () => { + const wallet = await wdb.create(); + + const t1 = new MTX(); + const input = dummyInput(); + t1.addInput(input); + t1.addOutput(await wallet.receiveAddress(), 50000); + await wdb.addTX(t1.toTX()); + assert.strictEqual((await wallet.getBalance()).unconfirmed, 50000); + + let conflict = false; + wallet.on('conflict', () => { + conflict = true; + }); + + const t2 = new MTX(); + t2.addInput(input); + t2.addOutput(new Address(), 5000); + await wdb.addTX(t2.toTX()); + assert(conflict); + assert.strictEqual((await wallet.getBalance()).unconfirmed, 0); + }); + it('should handle more missed txs', async () => { const alice = await wdb.create(); const bob = await wdb.create();