mcore-lib-matrixbit
Version:
A pure and powerful JavaScript Bitcoin Cash library.
71 lines (60 loc) • 2.13 kB
JavaScript
;
var bitcore = require('../../..');
var Transaction = bitcore.Transaction;
var PrivateKey = bitcore.PrivateKey;
describe('PublicKeyInput', function() {
var utxo = {
txid: '33e435fe6217a726351781ac96286c7c4ad25c9bd939cf1dde9095c75e50f2d1',
vout: 0,
address: 'mbxtest:qznww8t5qne2ftsr4eyr47c7wvq6wf6t4s76dxn0q5',
scriptPubKey: '2103cdcc435ff3e7f706c06a4584ff26b37d0fda8c17def85e3c7e434a310d81f4a0ac',
amount: 50,
confirmations: 104,
spendable: true
};
var privateKey = PrivateKey.fromWIF('cT8XXY1R6srqP5TM9wsnvoZGqKTbR881oAX1ABNqidTRLXboSHBa');
var address = privateKey.toAddress();
utxo.address.should.equal(address.toString());
var destKey = new PrivateKey();
it('will correctly sign a publickey out transaction', function() {
var tx = new Transaction();
tx.from(utxo);
tx.to(destKey.toAddress(), 10000);
tx.sign(privateKey);
tx.inputs[0].script.toBuffer().length.should.be.above(0);
});
it('count can count missing signatures', function() {
var tx = new Transaction();
tx.from(utxo);
tx.to(destKey.toAddress(), 10000);
var input = tx.inputs[0];
input.isFullySigned().should.equal(false);
tx.sign(privateKey);
input.isFullySigned().should.equal(true);
});
it('it\'s size can be estimated', function() {
var tx = new Transaction();
tx.from(utxo);
tx.to(destKey.toAddress(), 10000);
var input = tx.inputs[0];
input._estimateSize().should.equal(73);
});
it('it\'s signature can be removed', function() {
var tx = new Transaction();
tx.from(utxo);
tx.to(destKey.toAddress(), 10000);
var input = tx.inputs[0];
tx.sign(privateKey);
input.isFullySigned().should.equal(true);
input.clearSignatures();
input.isFullySigned().should.equal(false);
});
it('returns an empty array if private key mismatches', function() {
var tx = new Transaction();
tx.from(utxo);
tx.to(destKey.toAddress(), 10000);
var input = tx.inputs[0];
var signatures = input.getSignatures(tx, new PrivateKey(), 0);
signatures.length.should.equal(0);
});
});