server/wallet/mempool: get tests passing.

This commit is contained in:
Christopher Jeffrey 2016-12-05 21:02:08 -08:00
parent 5091f69038
commit 4e4dbfba49
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 14 additions and 5 deletions

View File

@ -378,8 +378,10 @@ HTTPServer.prototype._init = function _init() {
enforce(typeof output.address === 'string',
'Address must be a string.');
output.address = Address.fromBase58(output.address);
enforce(output.address.network === this.network,
'Wrong network for address.');
if (this.network.type === 'main') {
enforce(output.address.network === this.network,
'Wrong network for address.');
}
} else if (output.script) {
enforce(typeof output.script === 'string',
'Script must be a string.');

View File

@ -1542,6 +1542,11 @@ Mempool.prototype.fillAllCoins = co(function* fillAllCoins(tx) {
hash = input.prevout.hash;
index = input.prevout.index;
if (this.options.test) {
if (input.coin)
continue;
}
coin = this.getCoin(hash, index);
if (coin) {

View File

@ -1461,7 +1461,7 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
var outputs = options.outputs;
var i, tx, output, total;
assert(Array.isArray(output), 'Outputs must be an array.');
assert(Array.isArray(outputs), 'Outputs must be an array.');
if (outputs.length === 0)
throw new Error('No outputs available.');

View File

@ -8,6 +8,7 @@ var crypto = require('../lib/crypto/crypto');
var assert = require('assert');
var opcodes = constants.opcodes;
var cob = require('../lib/utils/co').cob;
var MempoolEntry = require('../lib/mempool/mempoolentry');
function dummy(prev, prevHash) {
if (!prevHash)
@ -46,7 +47,8 @@ describe('Mempool', function() {
mempool = new bcoin.mempool({
chain: chain,
name: 'mempool-test',
db: 'memory'
db: 'memory',
test: true
});
walletdb = new bcoin.walletdb({
@ -80,7 +82,7 @@ describe('Mempool', function() {
prev = new bcoin.script([kp.publicKey, opcodes.OP_CHECKSIG]);
t1.addInput(dummy(prev));
sig = t1.signature(0, prev, kp.privateKey, 'all', 0);
t1.inputs[0].script = new bcoin.script([sig]),
t1.inputs[0].script = new bcoin.script([sig]);
// balance: 51000
yield w.sign(t1);