Merge pull request #918 from eordano/test/coverage/addchange
Improve test coverage
This commit is contained in:
commit
ce7a9d33c6
|
@ -49,6 +49,8 @@ function Transaction(serialized) {
|
|||
return Transaction.shallowCopy(serialized);
|
||||
} else if (util.isHexa(serialized)) {
|
||||
this.fromString(serialized);
|
||||
} else if (util.isValidJSON(serialized)) {
|
||||
this.fromJSON(serialized);
|
||||
} else if (bufferUtil.isBuffer(serialized)) {
|
||||
this.fromBuffer(serialized);
|
||||
} else if (_.isObject(serialized)) {
|
||||
|
@ -221,7 +223,7 @@ Transaction.prototype.toObject = function toObject() {
|
|||
outputs.push(output.toObject());
|
||||
});
|
||||
return {
|
||||
change: this._change ? this._change.toObject() : undefined,
|
||||
change: this._change ? this._change.toString() : undefined,
|
||||
version: this.version,
|
||||
inputs: inputs,
|
||||
outputs: outputs,
|
||||
|
|
|
@ -456,6 +456,16 @@ describe('Address', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('throws an error if it couldn\'t instantiate', function() {
|
||||
expect(function() {
|
||||
return new Address(1);
|
||||
}).to.throw(TypeError);
|
||||
});
|
||||
it('can roundtrip from/to a object', function() {
|
||||
var address = new Address(P2SHLivenet[0]);
|
||||
expect(new Address(address.toObject()).toString()).to.equal(P2SHLivenet[0]);
|
||||
});
|
||||
|
||||
describe('creating a P2SH address from public keys', function() {
|
||||
|
||||
var public1 = '02da5798ed0c055e31339eb9b5cef0d3c0ccdec84a62e2e255eb5c006d4f3e7f5b';
|
||||
|
|
|
@ -243,6 +243,18 @@ describe('Transaction', function() {
|
|||
}).to.throw(errors.Transaction.FeeError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('to and from JSON', function() {
|
||||
it('takes a string that is a valid JSON and deserializes from it', function() {
|
||||
var transaction = new Transaction();
|
||||
expect(new Transaction(transaction.toJSON()).serialize()).to.equal(transaction.serialize());
|
||||
});
|
||||
it('serializes the `change` information', function() {
|
||||
var transaction = new Transaction();
|
||||
transaction.change(changeAddress);
|
||||
expect(JSON.parse(transaction.toJSON()).change).to.equal(changeAddress.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var tx_empty_hex = '01000000000000000000';
|
||||
|
|
Loading…
Reference in New Issue