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_output(value, output_script, version=None): ''' byte-like, byte-like -> TxOut ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxOut( value=value, version=version, output_script=output_script) return tx.TxOut(value=value, output_script=output_script)
def test_copy(self): res = tx.DecredTxOut(self.value, self.version, self.output_script) copy = res.copy() self.assertEqual(res, copy) self.assertIsNot(res, copy)
def test_bad_script(self): with self.assertRaises(ValueError) as context: tx.DecredTxOut(self.value, self.version, 'Hello World') self.assertIn('Expected byte-like object. ', str(context.exception))
def test_init(self): tx_out = tx.DecredTxOut(self.value, self.version, self.output_script) self.assertEqual(tx_out, helpers.DCR['ser']['outs'][0]['output'])