UNPKG

@owstack/bch-lib

Version:

A Javascript library to build bitcoin cash and blockchain-based applications.

76 lines (63 loc) 2.33 kB
'use strict'; var should = require('chai').should(); var keyLib = require('@owstack/key-lib'); var bchLib = require('../../..'); var Address = bchLib.Address; var PrivateKey = keyLib.PrivateKey; var Transaction = bchLib.Transaction; describe('PublicKeyInput', function() { var utxo = { txid: '7f3b688cb224ed83e12d9454145c26ac913687086a0a62f2ae0bc10934a4030f', vout: 0, address: 'bitcoincash:qragvhtwjfqgcx7p96yv460m5myfv0qgfydjf9zvyp', scriptPubKey: '2103c9594cb2ebfebcb0cfd29eacd40ba012606a197beef76f0269ed8c101e56ceddac', amount: 50, confirmations: 104, spendable: true }; var privateKey = PrivateKey.fromWIF('cQ7tSSQDEwaxg9usnnP1Aztqvm9nCQVfNWz9kU2rdocDjknF2vd6'); var addressFromKey = Address.fromPrivateKey(privateKey, 'BCH'); utxo.address.should.equal(addressFromKey.toString()); var destKey = new PrivateKey(); it('will correctly sign a publickey out transaction', function() { var tx = new Transaction(); tx.from(utxo); tx.to(Address.fromPrivateKey(destKey), 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(Address.fromPrivateKey(destKey), 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(Address.fromPrivateKey(destKey), 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(Address.fromPrivateKey(destKey), 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(Address.fromPrivateKey(destKey), 10000); var input = tx.inputs[0]; var signatures = input.getSignatures(tx, new PrivateKey(), 0); signatures.length.should.equal(0); }); });