-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
496e866
commit d94eae9
Showing
2 changed files
with
95 additions
and
1 deletion.
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,90 @@ | ||
'use strict'; | ||
|
||
const assert = require('bsert'); | ||
const WalletDB = require('../lib/wallet/walletdb'); | ||
const { Network } = require('../lib/protocol'); | ||
const WorkerPool = require('../lib/workers/workerpool'); | ||
const Chain = require('../lib/blockchain/chain'); | ||
const BlockStore = require('../lib/blockstore/level'); | ||
const Miner = require('../lib/mining/miner'); | ||
const CoinView = require('../lib/coins/coinview'); | ||
|
||
const wdb = new WalletDB(); | ||
|
||
const network = Network.get('regtest'); | ||
|
||
const workers = new WorkerPool({ | ||
enabled: true, | ||
size: 2 | ||
}); | ||
|
||
const blocks = new BlockStore({ | ||
memory: true, | ||
network | ||
}); | ||
|
||
const chain = new Chain({ | ||
memory: true, | ||
blocks, | ||
network, | ||
workers | ||
}); | ||
|
||
const miner = new Miner({ | ||
chain, | ||
version: 4, | ||
workers | ||
}); | ||
|
||
let wallet = null; | ||
const addresses = []; | ||
const minedBlocks = []; | ||
const filters = []; | ||
|
||
describe('wallet-neutrino', function() { | ||
before(async () => { | ||
await wdb.open(); | ||
}); | ||
|
||
after(async () => { | ||
await wdb.close(); | ||
}); | ||
|
||
it('should open wallet', async () => { | ||
wallet = await wdb.create(); | ||
}); | ||
|
||
it('should create accounts', async () => { | ||
await wallet.createAccount('foo'); | ||
}); | ||
|
||
it('should generate addresses', async () => { | ||
for (let i = 0; i < 3; i++) { | ||
const key = await wallet.createReceive(0); | ||
const address = key.getAddress(); | ||
addresses.push(address); | ||
} | ||
}); | ||
|
||
it('should create 3 blocks', async () => { | ||
for (let i = 0; i < 3; i++) { | ||
const addr = addresses[i]; | ||
const block = await miner.mineBlock(null, addr); | ||
minedBlocks.push(block); | ||
} | ||
}); | ||
|
||
it('should create filters', async () => { | ||
for (let i = 0; i < 3; i++) { | ||
const filter = minedBlocks[i].toBasicFilter(new CoinView()); | ||
filters.push(filter); | ||
} | ||
}); | ||
|
||
it('should match the filters', async () => { | ||
for (let i = 0; i < 3; i++) { | ||
const match = await wdb.checkFilter(minedBlocks[i].hash(), filters[i]); | ||
assert(match); | ||
} | ||
}); | ||
}); |