Esempio n. 1
0
    def test_init_errors(self):

        with self.assertRaises(ValueError) as context:
            tx.DecredInputWitness('Hello World', self.height, self.index,
                                  self.stack_script, self.redeem_script)

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredInputWitness(self.value, 'Hello World', self.index,
                                  self.stack_script, self.redeem_script)

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredInputWitness(self.value, self.height, 'Hello World',
                                  self.stack_script, self.redeem_script)

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredInputWitness(self.value, self.height, self.index,
                                  'Hello World', self.redeem_script)

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredInputWitness(self.value, self.height, self.index,
                                  self.redeem_script, 'Hello World')

        self.assertIn('Expected byte-like object', str(context.exception))
Esempio n. 2
0
    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'])
Esempio n. 3
0
    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)
Esempio n. 4
0
def make_decred_witness(value, height, index, stack_script, redeem_script):
    return tx.DecredInputWitness(
        value=value,
        height=height,
        index=index,
        stack_script=stack_script,
        redeem_script=redeem_script)
Esempio n. 5
0
    def test_init(self):
        input_witness = tx.DecredInputWitness(value=self.value,
                                              height=self.height,
                                              index=self.index,
                                              stack_script=self.stack_script,
                                              redeem_script=self.redeem_script)

        self.assertEqual(input_witness,
                         helpers.DCR['ser']['witnesses'][0]['witness'])
Esempio n. 6
0
    def test_copy(self):
        res = tx.DecredInputWitness(value=self.value,
                                    height=self.height,
                                    index=self.index,
                                    stack_script=self.stack_script,
                                    redeem_script=self.redeem_script)
        copy = res.copy()

        self.assertEqual(res, copy)
        self.assertIsNot(res, copy)
Esempio n. 7
0
    def test_sighash(self):
        tx_in_0 = tx.DecredTxIn.from_bytes(helpers.DCR1['ser']['ins'][0]['in'])
        tx_in_1 = tx.DecredTxIn.from_bytes(helpers.DCR1['ser']['ins'][1]['in'])
        tx_in_2 = tx.DecredTxIn.from_bytes(helpers.DCR1['ser']['ins'][2]['in'])

        tx_ins = [tx_in_0, tx_in_1, tx_in_2]

        tx_out_0 = tx.DecredTxOut.from_bytes(
            helpers.DCR1['ser']['outs'][0]['output'])
        tx_out_1 = tx.DecredTxOut.from_bytes(
            helpers.DCR1['ser']['outs'][1]['output'])

        tx_outs = [tx_out_0, tx_out_1]

        tx_witness_0 = tx.DecredInputWitness(
            value=helpers.DCR1['ser']['witness'][0]['value'],
            height=helpers.DCR1['ser']['witness'][0]['height'],
            index=helpers.DCR1['ser']['witness'][0]['index'],
            stack_script=helpers.DCR1['ser']['witness'][0]['stack_script'],
            redeem_script=b'')
        tx_witness_1 = tx.DecredInputWitness(
            value=helpers.DCR1['ser']['witness'][1]['value'],
            height=helpers.DCR1['ser']['witness'][1]['height'],
            index=helpers.DCR1['ser']['witness'][1]['index'],
            stack_script=helpers.DCR1['ser']['witness'][1]['stack_script'],
            redeem_script=b'')
        tx_witness_2 = tx.DecredInputWitness(
            value=helpers.DCR1['ser']['witness'][2]['value'],
            height=helpers.DCR1['ser']['witness'][2]['height'],
            index=helpers.DCR1['ser']['witness'][2]['index'],
            stack_script=helpers.DCR1['ser']['witness'][2]['stack_script'],
            redeem_script=b'')

        tx_witnesses = [tx_witness_0, tx_witness_1, tx_witness_2]

        tx.DecredTx(version=helpers.DCR1['ser']['version'],
                    tx_ins=tx_ins,
                    tx_outs=tx_outs,
                    lock_time=helpers.DCR1['ser']['locktime'],
                    expiry=helpers.DCR1['ser']['expiry'],
                    tx_witnesses=tx_witnesses)
Esempio n. 8
0
    def test_init_errors(self):
        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version='Hello World',
                        tx_ins=[self.tx_in],
                        tx_outs=[self.tx_out],
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=[self.witness])

            self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=['Hello World'],
                        tx_outs=[self.tx_out],
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=[self.witness])

        self.assertIn('Invalid TxIn.', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[self.tx_in],
                        tx_outs=['Hello World'],
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=[self.witness])

        self.assertIn('Invalid TxOut.', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[self.tx_in],
                        tx_outs=[self.tx_out],
                        lock_time='Hello World',
                        expiry=self.expiry,
                        tx_witnesses=[self.witness])

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[self.tx_in],
                        tx_outs=[self.tx_out],
                        lock_time=self.lock_time,
                        expiry='Hello World',
                        tx_witnesses=[self.witness])

        self.assertIn('Expected byte-like object', str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[self.tx_in],
                        tx_outs=[self.tx_out],
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=['Hello World'])

        self.assertIn('Invalid TxWitness', str(context.exception))

        # with self.assertRaises(ValueError) as context:
        #     tx.DecredTx(
        #         version=self.version,
        #         tx_ins=[self.tx_in] * 2,
        #         tx_outs=[self.tx_out],
        #         lock_time=self.lock_time,
        #         expiry=self.expiry,
        #         tx_witnesses=[self.witness])
        #
        # self.assertIn('Witness and TxIn lists must be same length. ',
        #               str(context.exception))

        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[],
                        tx_outs=[self.tx_out],
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=[])

        self.assertIn('Too few inputs or outputs. Stop that.',
                      str(context.exception))

        long_witness = tx.DecredInputWitness(self.witness_value, self.height,
                                             self.witness_index,
                                             self.stack_script * 64,
                                             self.redeem_script * 64)
        with self.assertRaises(ValueError) as context:
            tx.DecredTx(version=self.version,
                        tx_ins=[self.tx_in] * 255,
                        tx_outs=[self.tx_out] * 255,
                        lock_time=self.lock_time,
                        expiry=self.expiry,
                        tx_witnesses=[long_witness] * 255)

        self.assertIn('Tx is too large. Expect less than 100kB.',
                      str(context.exception))