Add tests for serialization roundtrip of inputs
This commit is contained in:
parent
ff82ccec71
commit
d99d1c9cc2
|
@ -28,7 +28,7 @@
|
|||
"maxcomplexity": 6, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
|
||||
"maxdepth": 4, // Maximum depth of nested control structures
|
||||
"maxlen": 120, // Maximum number of cols in a line
|
||||
"multistr": true // Allow use of multiline EOL escaping
|
||||
"multistr": true, // Allow use of multiline EOL escaping
|
||||
|
||||
"predef": [ // Extra globals.
|
||||
"after",
|
||||
|
|
|
@ -222,6 +222,13 @@ describe('Transaction', function() {
|
|||
var deserialized = new Transaction(serialized);
|
||||
expect(deserialized._change.toString()).to.equal(changeAddress);
|
||||
});
|
||||
it('can avoid checked serialize', function() {
|
||||
var transaction = new Transaction()
|
||||
.from(simpleUtxoWith1BTC)
|
||||
.to(fromAddress, 1);
|
||||
expect(function() { return transaction.serialize(); }).to.throw();
|
||||
expect(function() { return transaction.serialize(true); }).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checked serialize', function() {
|
||||
|
@ -255,6 +262,30 @@ describe('Transaction', function() {
|
|||
expect(JSON.parse(transaction.toJSON()).change).to.equal(changeAddress.toString());
|
||||
});
|
||||
});
|
||||
|
||||
describe('serialization of inputs', function() {
|
||||
it('can serialize and deserialize a P2PKH input', function() {
|
||||
var transaction = new Transaction()
|
||||
.from(simpleUtxoWith1BTC);
|
||||
var deserialized = new Transaction(transaction.toObject());
|
||||
expect(deserialized.inputs[0] instanceof Transaction.Input.PublicKeyHash).to.equal(true);
|
||||
});
|
||||
it('can serialize and deserialize a P2SH input', function() {
|
||||
var private1 = '6ce7e97e317d2af16c33db0b9270ec047a91bff3eff8558afb5014afb2bb5976';
|
||||
var private2 = 'c9b26b0f771a0d2dad88a44de90f05f416b3b385ff1d989343005546a0032890';
|
||||
var public1 = new PrivateKey(private1).publicKey;
|
||||
var public2 = new PrivateKey(private2).publicKey;
|
||||
var transaction = new Transaction()
|
||||
.from({
|
||||
txId: private1,
|
||||
outputIndex: 0,
|
||||
script: Script.buildScriptHashOut(Script.buildMultisigOut([public1, public2], 2)),
|
||||
satoshis: 10000
|
||||
}, [public1, public2], 2);
|
||||
var deserialized = new Transaction(transaction.toObject());
|
||||
expect(deserialized.inputs[0] instanceof Transaction.Input.MultiSigScriptHash).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var tx_empty_hex = '01000000000000000000';
|
||||
|
|
Loading…
Reference in New Issue