UNPKG

parsec-node

Version:

https://parseclabs.readthedocs.io/en/latest/

53 lines (47 loc) 1.6 kB
const { Tx, Input, Outpoint, Output } = require('parsec-lib'); const checkConsolidate = require('./checkConsolidate'); const ADDR_1 = '0x4436373705394267350db2c06613990d34621d69'; describe('checkConsolidate', () => { test('with 1 input', () => { const deposit = Tx.deposit(12, 500, ADDR_1, 0); const state = { unspent: { [new Outpoint(deposit.hash(), 0).hex()]: deposit.outputs[0].toJSON(), }, }; expect(() => { checkConsolidate( state, Tx.consolidate( [new Input(new Outpoint(deposit.hash(), 0))], new Output(1000, ADDR_1, 0) ) ); }).toThrow('Consolidate tx should have > 1 input'); }); test('with !== 1 output', () => { const deposit1 = Tx.deposit(12, 500, ADDR_1, 0); const deposit2 = Tx.deposit(13, 500, ADDR_1, 0); const state = { unspent: { [new Outpoint(deposit1.hash(), 0).hex()]: deposit1.outputs[0].toJSON(), [new Outpoint(deposit2.hash(), 0).hex()]: deposit2.outputs[0].toJSON(), }, }; const consolidate = Tx.consolidate( [ new Input(new Outpoint(deposit1.hash(), 0)), new Input(new Outpoint(deposit2.hash(), 0)), ], new Output(1000, ADDR_1, 0) ); consolidate.outputs.push(new Output(1000, ADDR_1, 0)); expect(() => { checkConsolidate(state, consolidate); }).toThrow('Consolidate tx should have only 1 output'); consolidate.outputs = []; expect(() => { checkConsolidate(state, consolidate); }).toThrow('Consolidate tx should have only 1 output'); }); });