-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wallet: fix missing tx when rescan with filter update #519
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,164 @@ | ||||
/* eslint-env mocha */ | ||||
/* eslint prefer-arrow-callback: "off" */ | ||||
|
||||
'use strict'; | ||||
|
||||
const assert = require('bsert'); | ||||
const FullNode = require('../lib/node/fullnode'); | ||||
const WalletNode = require('../lib/wallet/node'); | ||||
const {forValue} = require('./util/common'); | ||||
const WalletKey = require('../lib/wallet/walletkey'); | ||||
|
||||
describe('Node Sync', function() { | ||||
this.timeout(60000); | ||||
|
||||
const mnemonic = [ | ||||
'abandon', 'abandon', 'abandon', 'abandon', | ||||
'abandon', 'abandon', 'abandon', 'abandon', | ||||
'abandon', 'abandon', 'abandon', 'about' | ||||
].join(' '); | ||||
|
||||
const ports = { | ||||
p2p: 49331, | ||||
node: 49332, | ||||
wallet: 49333, | ||||
rs: 49334, | ||||
ns: 49335 | ||||
}; | ||||
|
||||
const lookahead = 10; | ||||
|
||||
let node, node2 = null; | ||||
let node2wallet = null; | ||||
let wdb, wdb2 = null; | ||||
let wallet, wallet2 = null; | ||||
|
||||
before(async () => { | ||||
/** | ||||
* Setup initial nodes and wallets. | ||||
*/ | ||||
|
||||
node = new FullNode({ | ||||
memory: true, | ||||
apiKey: 'foo', | ||||
network: 'regtest', | ||||
workers: true, | ||||
workersSize: 2, | ||||
bip37: true, | ||||
plugins: [require('../lib/wallet/plugin')], | ||||
listen: true, | ||||
port: ports.p2p, | ||||
httpPort: ports.node, | ||||
rsPort: ports.rs, | ||||
nsPort: ports.ns, | ||||
env: { | ||||
'BCOIN_WALLET_HTTP_PORT': ports.wallet.toString() | ||||
} | ||||
}); | ||||
|
||||
await node.open(); | ||||
|
||||
node2 = new FullNode({ | ||||
memory: true, | ||||
apiKey: 'foo', | ||||
network: 'regtest', | ||||
workers: true, | ||||
workersSize: 2, | ||||
port: ports.p2p + 5, | ||||
httpPort: ports.node + 5, | ||||
rsPort: ports.rs + 5, | ||||
nsPort: ports.ns + 5, | ||||
only: [`127.0.0.1:${ports.p2p}`] | ||||
}); | ||||
|
||||
await node2.open(); | ||||
|
||||
node2wallet = new WalletNode({ | ||||
httpPort: ports.wallet + 5, | ||||
nodePort: ports.node + 5, | ||||
nodeApiKey: 'foo', | ||||
network: 'regtest' | ||||
}); | ||||
|
||||
await node2wallet.open(); | ||||
|
||||
/** | ||||
* Generate blocks and transactions. | ||||
*/ | ||||
|
||||
await node.connect(); | ||||
|
||||
// Prepare the miner and wallet. | ||||
const {miner, chain} = node; | ||||
wdb = node.require('walletdb').wdb; | ||||
wallet = await wdb.create(); | ||||
miner.addAddress(await wallet.receiveAddress()); | ||||
|
||||
// Mature the initial coins to use for the | ||||
// use in generating the test case. | ||||
for (let i = 0; i < 200; i++) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in hsd the coinbase maturity for regtest is much smaller so we can reduce this here. Line 745 in c85d9b4
|
||||
const block = await miner.cpu.mineBlock(); | ||||
assert(await chain.add(block)); | ||||
} | ||||
|
||||
assert.strictEqual(chain.height, 200); | ||||
|
||||
// Prepare the full node wallet. | ||||
wdb2 = node2wallet.wdb; | ||||
wallet2 = await wdb2.create({mnemonic}); | ||||
|
||||
let index = 0; | ||||
|
||||
// Generate several blocks of transactions for | ||||
// the identical wallets. | ||||
for (let b = 0; b < 5; b++) { | ||||
const account = await wallet2.getAccount(0); | ||||
assert.equal(account.lookahead, lookahead); | ||||
let count = 0; | ||||
|
||||
// Include more transactions than the lookahead | ||||
// within the block. The filter will need to be updated | ||||
// and re-download the same block. | ||||
while (count < lookahead + 1) { | ||||
const branch = 0; | ||||
const key = account.accountKey.derive(branch).derive(index); | ||||
const ring = WalletKey.fromHD(account, key, branch, index); | ||||
const spvaddr = ring.getAddress(); | ||||
|
||||
await wallet.send({ | ||||
subtractFee: true, | ||||
outputs: [{ | ||||
address: spvaddr, | ||||
value: 10000 | ||||
}] | ||||
}); | ||||
|
||||
index += 1; | ||||
count += 1; | ||||
} | ||||
|
||||
const block = await miner.mineBlock(); | ||||
assert(await chain.add(block)); | ||||
} | ||||
}); | ||||
|
||||
after(async () => { | ||||
await node.close(); | ||||
await node2wallet.close(); | ||||
await node2.close(); | ||||
}); | ||||
|
||||
it('should sync with node and wallet (full)', async () => { | ||||
await node2.connect(); | ||||
await node2.startSync(); | ||||
|
||||
await forValue(wdb2, 'height', 205); | ||||
await forValue(node2.chain, 'height', 205); | ||||
|
||||
await new Promise(r => setTimeout(() => r(), 3000)); | ||||
|
||||
const bal = await wallet2.getBalance(); | ||||
assert.equal(bal.tx, 5 * lookahead + 5); | ||||
assert.equal(bal.coin, 5 * lookahead + 5); | ||||
}); | ||||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need to be changed to
HSD_WALLET_HTTP_PORT
:-)