-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add node sendTX test case for "tx" event
- Loading branch information
1 parent
fcccef7
commit 518be85
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-env mocha */ | ||
/* eslint prefer-arrow-callback: "off" */ | ||
|
||
'use strict'; | ||
|
||
const assert = require('bsert'); | ||
const SPVNode = require('../lib/node/spvnode'); | ||
const Input = require('../lib/primitives/input'); | ||
const Outpoint = require('../lib/primitives/outpoint'); | ||
const MTX = require('../lib/primitives/mtx'); | ||
const random = require('bcrypto/lib/random'); | ||
|
||
function dummyInput() { | ||
const hash = random.randomBytes(32); | ||
return Input.fromOutpoint(new Outpoint(hash, 0)); | ||
} | ||
|
||
const node = new SPVNode({ | ||
network: 'regtest', | ||
plugins: [require('../lib/wallet/plugin')] | ||
}); | ||
|
||
const {wdb} = node.require('walletdb'); | ||
|
||
let wallet = null; | ||
|
||
describe.only('SPV Node', function() { | ||
this.timeout(process.browser ? 20000 : 5000); | ||
|
||
if (process.browser) | ||
return; | ||
|
||
it('should open node', async () => { | ||
await node.open(); | ||
}); | ||
|
||
it('should open walletdb', async () => { | ||
wallet = await wdb.create(); | ||
}); | ||
|
||
it('should wake listeners of \'tx\' when sending', async () => { | ||
let notified = false; | ||
const notifier = () => { | ||
notified = true; | ||
}; | ||
node.on('tx', notifier); | ||
|
||
const mtx = new MTX(); | ||
mtx.addInput(dummyInput()); | ||
mtx.addOutput(await wallet.receiveAddress(), 5460); | ||
|
||
await node.sendTX(mtx.toTX()); | ||
|
||
assert(notified); | ||
node.removeListener('tx', notifier); | ||
}); | ||
|
||
it('should cleanup', async () => { | ||
await node.close(); | ||
}); | ||
}); |