Esempio n. 1
0
    def test_everything_witness(self):
        version = bytearray([0] * 4)
        flag = b'\x00\x01'
        outpoint_index = utils.i2le_padded(0, 4)
        outpoint_tx_id = bytearray(bytearray.fromhex(
            '10399b3f20cbdd4b5ac3f823afdba28b'
            '9f70e21437a59b312a1b62c42c5cd101'))[::-1]
        outpoint = tx.Outpoint(outpoint_tx_id, outpoint_index)

        sequence = utils.i2le_padded(0, 4)

        script = bytearray(bytearray.fromhex('473044022000e02ea97289a35181a9bfabd324f12439410db11c4e94978cdade6a665bf1840220458b87c34d8bb5e4d70d01041c7c2d714ea8bfaca2c2d2b1f9e5749c3ee17e3d012102ed0851f0b4c4458f80e0310e57d20e12a84642b8e097fe82be229edbd7dbd53920f6665740b1f950eb58d646b1fae9be28cef842da5e51dc78459ad2b092e7fd6e514c5163a914bb408296de2420403aa79eb61426bb588a08691f8876a91431b31321831520e346b069feebe6e9cf3dd7239c670400925e5ab17576a9140d22433293fe9652ea00d21c5061697aef5ddb296888ac'))  # noqa: E501

        tx_in = tx.TxIn(outpoint, script, bytearray(), sequence)
        tx_ins = [tx_in]

        tx_outs = [
            tx.TxOut(
                value=bytearray(utils.i2le_padded(2000, 8)),
                output_script=bytearray(bytearray.fromhex('76a914f2539f42058da784a9d54615ad074436cf3eb85188ac')))  # noqa: E501
        ]
        none_witnesses = [
            tx.InputWitness(
                [
                    tx.WitnessStackItem(bytearray([0x88] * 18)),
                    tx.WitnessStackItem(bytearray([0x99] * 18))
                ]
            )
        ]
        lock_time = bytearray([0xff] * 4)

        tx.Tx(version, flag, tx_ins, tx_outs, none_witnesses, lock_time)
Esempio n. 2
0
    def setUp(self):
        self.outpoint_index = helpers.P2PKH1['ser']['ins'][0]['index']
        self.outpoint_tx_id = helpers.P2PKH1['ser']['ins'][0]['hash']

        self.stack_script = helpers.P2PKH1['ser']['ins'][0]['stack_script']
        self.redeem_script = helpers.P2PKH1['ser']['ins'][0]['redeem_script']
        self.sequence = helpers.P2PKH1['ser']['ins'][0]['sequence']
        self.outpoint = tx.Outpoint(self.outpoint_tx_id, self.outpoint_index)

        self.tx_in = tx.TxIn(self.outpoint, self.stack_script,
                             self.redeem_script, self.sequence)

        self.value_0 = helpers.P2PKH1['ser']['outs'][0]['value']
        self.output_script_0 = \
            helpers.P2PKH1['ser']['outs'][0]['pk_script']
        self.value_1 = helpers.P2PKH1['ser']['outs'][1]['value']
        self.output_script_1 = \
            helpers.P2PKH1['ser']['outs'][1]['pk_script']

        self.tx_out_0 = tx.TxOut(self.value_0, self.output_script_0)
        self.tx_out_1 = tx.TxOut(self.value_1, self.output_script_1)

        self.version = helpers.P2PKH1['ser']['version']
        self.none_flag = None
        self.tx_ins = [self.tx_in]
        self.tx_outs = [self.tx_out_0, self.tx_out_1]
        self.none_witnesses = None
        self.lock_time = helpers.P2PKH1['ser']['locktime']

        self.segwit_flag = b'\x00\x01'
        self.stack = [
            tx.WitnessStackItem(b)
            for b in helpers.P2WSH['ser']['witnesses'][0]['wit_stack_items']
        ]
        self.tx_witnesses = [tx.InputWitness(self.stack)]
Esempio n. 3
0
 def test_create_stack_item(self):
     w = tx.WitnessStackItem(self.stack_item_bytes)
     self.assertEqual(w.item, self.stack_item_bytes)
     self.assertEqual(w.item_len, len(self.stack_item_bytes))
     self.assertEqual(
         w,
         bytes([len(self.stack_item_bytes)]) + self.stack_item_bytes)
Esempio n. 4
0
 def setUp(self):
     self.stack = [
         tx.WitnessStackItem(b)
         for b in helpers.P2WSH['ser']['witnesses'][0]['wit_stack_items']
     ]
Esempio n. 5
0
 def test_item_too_long(self):
     with self.assertRaises(ValueError) as context:
         tx.WitnessStackItem(b'\xff' * 521)
     self.assertIn('Item is too large. Expected <=520 bytes. ',
                   str(context.exception))
Esempio n. 6
0
def make_witness_stack_item(data):
    '''
    bytearray -> WitnessStackItem
    '''
    return tx.WitnessStackItem(item=data)