예제 #1
0
 def test_tx_ids(self):
     t = tx.SproutTx(**self.tx)
     self.assertEqual(
         t.tx_id_le,
         '1add6cdbe72ede27cd3b6cd85f45d02081b9d57f173090df80648cdb927eb167')
     self.assertEqual(
         t.tx_id,
         '67b17e92db8c6480df9030177fd5b98120d0455fd86c3bcd27de2ee7db6cdd1a')
예제 #2
0
    def attr_assert(self, attr_name, replacement, err_text):
        # Removes a named key from a dictionary and replaces it with b'\x00'
        temp_dict = dict((a, self.tx[a]) for a in self.tx if a != attr_name)
        temp_dict[attr_name] = replacement
        with self.assertRaises(ValueError) as context:
            tx.SproutTx(**temp_dict)

        self.assertIn(err_text, str(context.exception))
예제 #3
0
def make_tx(version, tx_ins, tx_outs, lock_time,
            expiry=None, value_balance=None, tx_shielded_spends=None,
            tx_shielded_outputs=None, tx_witnesses=None, tx_joinsplits=None,
            joinsplit_pubkey=None, joinsplit_sig=None, binding_sig=None):
    '''
    int, list(TxIn), list(TxOut), int, list(InputWitness) -> Tx
    '''
    n = riemann.get_current_network_name()
    if 'decred' in n:
        return tx.DecredTx(
            version=utils.i2le_padded(version, 4),
            tx_ins=tx_ins,
            tx_outs=tx_outs,
            lock_time=utils.i2le_padded(lock_time, 4),
            expiry=utils.i2le_padded(expiry, 4),
            tx_witnesses=[tx_witnesses])
    if 'sprout' in n and tx_joinsplits is not None:
        return tx.SproutTx(
            version=version,
            tx_ins=tx_ins,
            tx_outs=tx_outs,
            lock_time=utils.i2le_padded(lock_time, 4),
            tx_joinsplits=tx_joinsplits if tx_joinsplits is not None else [],
            joinsplit_pubkey=joinsplit_pubkey,
            joinsplit_sig=joinsplit_sig)
    if 'overwinter' in n:
        return tx.OverwinterTx(
            tx_ins=tx_ins,
            tx_outs=tx_outs,
            lock_time=utils.i2le_padded(lock_time, 4),
            expiry_height=utils.i2le_padded(expiry, 4),
            tx_joinsplits=tx_joinsplits if tx_joinsplits is not None else [],
            joinsplit_pubkey=joinsplit_pubkey,
            joinsplit_sig=joinsplit_sig)
    if 'sapling' in n:
        return tx.SaplingTx(
            tx_ins=tx_ins,
            tx_outs=tx_outs,
            lock_time=utils.i2le_padded(lock_time, 4),
            expiry_height=utils.i2le_padded(expiry, 4),
            value_balance=utils.i2le_padded[value_balance],
            tx_shielded_spends=(tx_shielded_spends
                                if tx_shielded_spends is not None else []),
            tx_shielded_outputs=(tx_shielded_outputs
                                 if tx_shielded_outputs is not None else []),
            tx_joinsplits=tx_joinsplits if tx_joinsplits is not None else [],
            joinsplit_pubkey=joinsplit_pubkey,
            joinsplit_sig=joinsplit_sig,
            binding_sig=binding_sig)
    flag = riemann.network.SEGWIT_TX_FLAG \
        if tx_witnesses is not None else None
    return tx.Tx(version=utils.i2le_padded(version, 4),
                 flag=flag,
                 tx_ins=tx_ins,
                 tx_outs=tx_outs,
                 tx_witnesses=tx_witnesses,
                 lock_time=utils.i2le_padded(lock_time, 4))
예제 #4
0
    def test_no_inputs(self):
        temp_dict = self.tx.copy()
        temp_dict['version'] = b'\x01\x00\x00\x00'
        temp_dict['tx_joinsplits'] = []

        with self.assertRaises(ValueError) as context:
            tx.SproutTx(**temp_dict)

        self.assertIn('Version 1 txns must have at least 1 input',
                      str(context.exception))
예제 #5
0
    def test_from_bytes_with_tx_in(self):
        # This is a bit hard to read
        temp_dict = self.tx.copy()
        temp_dict['tx_ins'] = \
            [tx.TxIn.from_bytes(P2SH['ser']['ins'][0]['input'])]

        # Take the current serialization's version,
        # Add b'\x01' for 1 tx_in
        # Add the tx_in from another transaction
        # Add back the rest of the serialization
        temp_ser = \
            self.tx_ser[0:4] \
            + b'\x01' \
            + P2SH['ser']['ins'][0]['input'] \
            + self.tx_ser[5:]

        self.assertEqual(tx.SproutTx.from_bytes(temp_ser),
                         tx.SproutTx(**temp_dict))
예제 #6
0
 def test_calculate_fee(self):
     t = tx.SproutTx(**self.tx)
     self.assertEqual(t.calculate_fee([]), 10000)
예제 #7
0
 def test_print_sighash(self):
     t = tx.SproutTx(**self.tx)
     print('SproutTx Test Sighash:', t.sighash_all())
예제 #8
0
    def test_copy(self):
        t = tx.SproutTx(**self.tx)
        t_copy = t.copy()

        self.assertEqual(t, t_copy)
        self.assertIsNot(t, t_copy)
예제 #9
0
 def test_from_bytes(self):
     self.assertEqual(tx.SproutTx.from_bytes(self.tx_ser),
                      tx.SproutTx(**self.tx))
예제 #10
0
 def test_print_sighash(self):
     t = tx.SproutTx(**self.tx)
     print('SproutTx Test Sighash:',
           t.sighash_all(index=0, script=b'\x0100'))