wallet tests. fixes.

This commit is contained in:
Christopher Jeffrey 2016-02-12 22:32:54 -08:00
parent 60abff853a
commit 9d727cebae
4 changed files with 62 additions and 4 deletions

View File

@ -1362,6 +1362,14 @@ script._getInputData = function _getInputData(s, type) {
assert(typeof type === 'string');
if (s.length === 0) {
return {
type: 'unknown',
side: 'input',
none: true
};
}
if (type === 'pubkey') {
sig = s[0];
return {

View File

@ -47,7 +47,10 @@ TXPool.prototype._init = function init() {
var self = this;
if (!this._storage) {
this._loaded = true;
utils.nextTick(function() {
self._loaded = true;
self.emit('load', self._lastTs, self._lastHeight);
});
return;
}

View File

@ -640,7 +640,7 @@ Wallet.prototype.getOutputDepth = function getOutputDepth(tx) {
var i, path;
for (i = 0; i < paths.length; i++) {
path = this.parsePath(path);
path = this.parsePath(paths[i]);
if (path.change) {
if (path.index > depth.change)
depth.change = path.index;

View File

@ -282,15 +282,31 @@ describe('Wallet', function() {
var utx = bcoin.tx();
utx.output({ address: addr, value: 5460 * 10 });
// Simulate a confirmation
utx.ps = 0;
utx.ts = 1;
utx.height = 1;
assert.equal(w1.receiveDepth, 1);
w1.addTX(utx);
w2.addTX(utx);
w3.addTX(utx);
assert.equal(w1.receiveDepth, 2);
assert.equal(w1.changeDepth, 1);
assert(w1.getAddress() !== addr);
addr = w1.getAddress();
assert.equal(w1.getAddress(), addr);
assert.equal(w2.getAddress(), addr);
assert.equal(w3.getAddress(), addr);
// Create a tx requiring 2 signatures
var send = bcoin.tx();
send.output({ address: receive.getAddress(), value: 5460 });
assert(!send.verify());
var result = w1.fill(send);
var result = w1.fill(send, { m: w1.m, n: w1.n });
assert(result);
w1.sign(send);
@ -301,10 +317,41 @@ describe('Wallet', function() {
assert(send.verify());
assert.equal(w1.changeDepth, 1);
var change = w1.changeAddress.getAddress();
assert.equal(w1.changeAddress.getAddress(), change);
assert.equal(w2.changeAddress.getAddress(), change);
assert.equal(w3.changeAddress.getAddress(), change);
// Simulate a confirmation
send.ps = 0;
send.ts = 1;
send.height = 1;
w1.addTX(send);
w2.addTX(send);
w3.addTX(send);
assert.equal(w1.receiveDepth, 2);
assert.equal(w1.changeDepth, 2);
assert(w1.getAddress() === addr);
assert(w1.changeAddress.getAddress() !== change);
change = w1.changeAddress.getAddress();
assert.equal(w1.changeAddress.getAddress(), change);
assert.equal(w2.changeAddress.getAddress(), change);
assert.equal(w3.changeAddress.getAddress(), change);
send.inputs[0].script[2] = [];
assert(!send.verify());
assert(!send.verify(null, true));
assert.equal(send.getFee().toNumber(), 10000);
w3 = bcoin.wallet.fromJSON(w3.toJSON());
assert.equal(w3.receiveDepth, 2);
assert.equal(w3.changeDepth, 2);
assert.equal(w3.getAddress(), addr);
assert.equal(w3.changeAddress.getAddress(), change);
cb();
});
});