def test_txhash(self): ''' https://github.com/decred/dcrd/blob/master/wire/msgtx_test.go#L139-L140 ''' outpoint = tx.DecredOutpoint(tx_id=b'\x00' * 32, index=b'\xff' * 4, tree=b'\x00') tx_ins = [tx.DecredTxIn(outpoint=outpoint, sequence=b'\xff' * 4)] tx_outs = [ tx.DecredTxOut(value=utils.i2le_padded(5000000000, 8), version=b'\xf0\xf0', output_script=helpers.DCR['ser']['hash_pk']) ] tx_witnesses = [ tx.DecredInputWitness( value=utils.i2le_padded(5000000000, 8), height=b'\x34' * 4, index=b'\x2E' * 4, stack_script=bytes([0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62]), redeem_script=b'') ] version = helpers.DCR['ser']['version'] t = tx.DecredTx(version=version, tx_ins=tx_ins, tx_outs=tx_outs, lock_time=b'\x00' * 4, expiry=b'\x00' * 4, tx_witnesses=tx_witnesses) self.assertEqual(t.tx_id, helpers.DCR['ser']['tx']['expected_hash'])
def setUp(self): super().setUp() self.version = helpers.DCR['ser']['version'] self.outpoint_index = helpers.DCR['ser']['ins'][0]['index'] self.outpoint_tx_id = helpers.DCR['ser']['ins'][0]['hash'] self.outpoint_tree = helpers.DCR['ser']['ins'][0]['tree'] self.sequence = helpers.DCR['ser']['ins'][0]['sequence'] self.outpoint = tx.DecredOutpoint(self.outpoint_tx_id, self.outpoint_index, self.outpoint_tree) self.tx_in = tx.DecredTxIn(self.outpoint, self.sequence) self.output_value = helpers.DCR['ser']['outs'][0]['value'] self.output_version = helpers.DCR['ser']['outs'][0]['version'] self.output_script = helpers.DCR['ser']['outs'][0]['pk_script'] self.tx_out = tx.DecredTxOut(self.output_value, self.output_version, self.output_script) self.lock_time = helpers.DCR['ser']['locktime'] self.expiry = helpers.DCR['ser']['expiry'] self.witness_value = helpers.DCR['ser']['witnesses'][0]['value'] self.height = helpers.DCR['ser']['witnesses'][0]['height'] self.witness_index = helpers.DCR['ser']['witnesses'][0]['index'] self.stack_script = helpers.DCR['ser']['witnesses'][0]['stack_script'] self.redeem_script = \ helpers.DCR['ser']['witnesses'][0]['redeem_script'] self.witness = tx.DecredInputWitness(value=self.witness_value, height=self.height, index=self.witness_index, stack_script=self.stack_script, redeem_script=self.redeem_script)
def make_witness_input(outpoint, sequence): ''' Outpoint, int -> TxIn ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxIn( outpoint=outpoint, sequence=utils.i2le_padded(sequence, 4)) return tx.TxIn(outpoint=outpoint, stack_script=b'', redeem_script=b'', sequence=utils.i2le_padded(sequence, 4))
def make_legacy_input(outpoint, stack_script, redeem_script, sequence): ''' Outpoint, byte-like, byte-like, int -> TxIn ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxIn( outpoint=outpoint, sequence=utils.i2le_padded(sequence, 4)) return tx.TxIn(outpoint=outpoint, stack_script=stack_script, redeem_script=redeem_script, sequence=utils.i2le_padded(sequence, 4))
def test_copy(self): res = tx.DecredTxIn(self.outpoint, self.sequence) copy = res.copy() self.assertEqual(res, copy) self.assertIsNot(res, copy)
def test_init_bad_sequnce(self): with self.assertRaises(ValueError) as context: tx.DecredTxIn(self.outpoint, 'Hello World') self.assertIn('Expected byte-like object. ', str(context.exception))
def test_init(self): tx_in = tx.DecredTxIn(self.outpoint, self.sequence) self.assertEqual(tx_in, helpers.DCR['ser']['tx']['in_unsigned'])
def make_decred_input(outpoint, sequence): return tx.DecredTxIn( outpoint=outpoint, sequence=utils.i2le_padded(sequence, 4))