wallet test passings
This commit is contained in:
parent
5d2b50f77f
commit
dc3bbb8859
4 changed files with 23 additions and 70 deletions
|
|
@ -53,14 +53,9 @@ TxProposal.prototype.setSent = function(sentTxid) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.fromObj = function(o, forceOpts) {
|
TxProposal.fromObj = function(o, forceOpts) {
|
||||||
|
|
||||||
console.log('[TxProposal.js.56]'); //TODO
|
|
||||||
preconditions.checkArgument(o.builderObj);
|
preconditions.checkArgument(o.builderObj);
|
||||||
|
|
||||||
console.log('[TxProposal.js.59]'); //TODO
|
|
||||||
delete o['builder'];
|
delete o['builder'];
|
||||||
|
|
||||||
console.log('[TxProposal.js.62]'); //TODO
|
|
||||||
try {
|
try {
|
||||||
// force opts is requested.
|
// force opts is requested.
|
||||||
for (var k in forceOpts) {
|
for (var k in forceOpts) {
|
||||||
|
|
@ -69,19 +64,16 @@ TxProposal.fromObj = function(o, forceOpts) {
|
||||||
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
o.builder = TransactionBuilder.fromObj(o.builderObj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
console.log('[TxProposal.js.71]'); //TODO
|
|
||||||
if (!o.version) {
|
if (!o.version) {
|
||||||
o.builder = new BuilderMockV0(o.builderObj);
|
o.builder = new BuilderMockV0(o.builderObj);
|
||||||
o.readonly = 1;
|
o.readonly = 1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[TxProposal.js.78]', o); //TODO
|
|
||||||
var t = new TxProposal(o);
|
var t = new TxProposal(o);
|
||||||
t._check();
|
t._check();
|
||||||
t._updateSignedBy();
|
t._updateSignedBy();
|
||||||
|
|
||||||
console.log('[TxProposal.js.78]'); //TODO
|
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -125,7 +117,6 @@ TxProposal._verifySignatures = function(inKeys, scriptSig, txSigHash) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal._infoFromRedeemScript = function(s) {
|
TxProposal._infoFromRedeemScript = function(s) {
|
||||||
console.log('[TxProposal.js.127]',s.getBuffer().toString('hex')); //TODO
|
|
||||||
var redeemScript = new Script(s.chunks[s.chunks.length - 1]);
|
var redeemScript = new Script(s.chunks[s.chunks.length - 1]);
|
||||||
if (!redeemScript)
|
if (!redeemScript)
|
||||||
throw new Error('Bad scriptSig (no redeemscript)');
|
throw new Error('Bad scriptSig (no redeemscript)');
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,6 @@ Wallet.prototype._handleTxProposal = function(senderId, data) {
|
||||||
try {
|
try {
|
||||||
mergeInfo = this.txProposals.mergeFromObj(data.txProposal, senderId, Wallet.builderOpts);
|
mergeInfo = this.txProposals.mergeFromObj(data.txProposal, senderId, Wallet.builderOpts);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('[Wallet.js.141]',e); //TODO
|
|
||||||
var corruptEvent = {
|
var corruptEvent = {
|
||||||
type: 'corrupt',
|
type: 'corrupt',
|
||||||
cId: senderId,
|
cId: senderId,
|
||||||
|
|
|
||||||
|
|
@ -198,8 +198,18 @@ describe('TxProposal', function() {
|
||||||
(function() { txp._check();} ).should.throw('no ins');
|
(function() { txp._check();} ).should.throw('no ins');
|
||||||
txp.builder.tx.ins = backup;
|
txp.builder.tx.ins = backup;
|
||||||
});
|
});
|
||||||
it('FAIL signhash', function() {
|
it('FAIL signhash SINGLE', function() {
|
||||||
sinon.stub(txp.builder.tx,'getHashType').returns(2);
|
sinon.stub(txp.builder.tx,'getHashType').returns(Transaction.SIGHASH_SINGLE);
|
||||||
|
(function() { txp._check();} ).should.throw('signatures');
|
||||||
|
txp.builder.tx.getHashType.restore();
|
||||||
|
});
|
||||||
|
it('FAIL signhash NONE', function() {
|
||||||
|
sinon.stub(txp.builder.tx,'getHashType').returns(Transaction.SIGHASH_NONE);
|
||||||
|
(function() { txp._check();} ).should.throw('signatures');
|
||||||
|
txp.builder.tx.getHashType.restore();
|
||||||
|
});
|
||||||
|
it('FAIL signhash ANYONECANPAY', function() {
|
||||||
|
sinon.stub(txp.builder.tx,'getHashType').returns(Transaction.SIGHASH_ANYONECANPAY);
|
||||||
(function() { txp._check();} ).should.throw('signatures');
|
(function() { txp._check();} ).should.throw('signatures');
|
||||||
txp.builder.tx.getHashType.restore();
|
txp.builder.tx.getHashType.restore();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1023,30 +1023,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validate txProposals', function() {
|
describe('validate txProposals', function() {
|
||||||
var a1 = 'n1pKARYYUnZwxBuGj3y7WqVDu6VLN7n971';
|
var testValidate = function(shouldThrow, result, done) {
|
||||||
var a2 = 'mtxYYJXZJmQc2iJRHQ4RZkfxU5K7TE2qMJ';
|
|
||||||
var utxos = [{
|
|
||||||
address: a1,
|
|
||||||
txid: '2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1',
|
|
||||||
vout: 1,
|
|
||||||
scriptPubKey: Address.getScriptPubKeyFor(a1).serialize().toString('hex'),
|
|
||||||
amount: 0.5,
|
|
||||||
confirmations: 200
|
|
||||||
}, {
|
|
||||||
address: a2,
|
|
||||||
txid: '88c4520ffd97ea565578afe0b40919120be704b36561c71ba4e450e83cb3c9fd',
|
|
||||||
vout: 1,
|
|
||||||
scriptPubKey: Address.getScriptPubKeyFor(a2).serialize().toString('hex'),
|
|
||||||
amount: 0.5001,
|
|
||||||
confirmations: 200
|
|
||||||
}];
|
|
||||||
var destAddress = 'myuAQcCc1REUgXGsCTiYhZvPPc3XxZ36G1';
|
|
||||||
var outs = [{
|
|
||||||
address: destAddress,
|
|
||||||
amount: 1.0
|
|
||||||
}];
|
|
||||||
|
|
||||||
var testValidate = function(signhash, result, done) {
|
|
||||||
var w = cachedCreateW();
|
var w = cachedCreateW();
|
||||||
var spy = sinon.spy();
|
var spy = sinon.spy();
|
||||||
w.on('txProposalEvent', spy);
|
w.on('txProposalEvent', spy);
|
||||||
|
|
@ -1054,50 +1031,26 @@ describe('Wallet model', function() {
|
||||||
e.type.should.equal(result);
|
e.type.should.equal(result);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
var opts = {};
|
|
||||||
opts.signhash = signhash;
|
|
||||||
var txb = new TransactionBuilder(opts)
|
|
||||||
.setUnspent(utxos)
|
|
||||||
.setOutputs(outs)
|
|
||||||
.sign(['cVBtNonMyTydnS3NnZyipbduXo9KZfF1aUZ3uQHcvJB6UARZbiWG',
|
|
||||||
'cRVF68hhZp1PUQCdjr2k6aVYb2cn6uabbySDPBizAJ3PXF7vDXTL'
|
|
||||||
]);
|
|
||||||
var txp = {
|
var txp = {
|
||||||
'txProposal': {
|
'txProposal': { dummy: 1}
|
||||||
builderObj: txb.toObj(),
|
|
||||||
inputChainPaths: 'm/1',
|
|
||||||
creator: '1234',
|
|
||||||
createdTs: Date.now(),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
var merge = sinon.stub(w.txProposals, 'mergeFromObj', function() {
|
||||||
|
if (shouldThrow) throw new Error();
|
||||||
|
return {events: [{type:'new'}]};
|
||||||
|
});
|
||||||
|
|
||||||
w._handleTxProposal('senderID', txp, true);
|
w._handleTxProposal('senderID', txp, true);
|
||||||
spy.callCount.should.equal(1);
|
spy.callCount.should.equal(1);
|
||||||
|
merge.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should validate for undefined', function(done) {
|
it('should validate for undefined', function(done) {
|
||||||
var result = 'corrupt';
|
var result = 'corrupt';
|
||||||
var signhash;
|
testValidate(1, result, done);
|
||||||
testValidate(signhash, result, done);
|
|
||||||
});
|
});
|
||||||
it.only('should validate for SIGHASH_ALL', function(done) {
|
it('should validate for SIGHASH_ALL', function(done) {
|
||||||
var result = 'new';
|
var result = 'new';
|
||||||
var signhash = Transaction.SIGHASH_ALL;
|
testValidate(0, result, done);
|
||||||
testValidate(signhash, result, done);
|
|
||||||
});
|
|
||||||
it('should not validate for different SIGHASH_NONE', function(done) {
|
|
||||||
var result = 'corrupt';
|
|
||||||
var signhash = Transaction.SIGHASH_NONE;
|
|
||||||
testValidate(signhash, result, done);
|
|
||||||
});
|
|
||||||
it('should not validate for different SIGHASH_SINGLE', function(done) {
|
|
||||||
var result = 'corrupt';
|
|
||||||
var signhash = Transaction.SIGHASH_SINGLE;
|
|
||||||
testValidate(signhash, result, done);
|
|
||||||
});
|
|
||||||
it('should not validate for different SIGHASH_ANYONECANPAY', function(done) {
|
|
||||||
var result = 'corrupt';
|
|
||||||
var signhash = Transaction.SIGHASH_ANYONECANPAY;
|
|
||||||
testValidate(signhash, result, done);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue