Ejemplo n.º 1
0
 def test_init_segwit(self):
     txin = [TxIn(b'script', b'txid', b'\x04', b'witness', sequence=b'\xff\xff\xff\xff')]
     txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
     txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')
     assert txobj.version == b'\x01\x00\x00\x00'
     assert txobj.TxIn == txin
     assert txobj.TxOut == txout
     assert txobj.locktime == b'\x00\x00\x00\x00'
Ejemplo n.º 2
0
    def test_bytes_repr(self):
        txin = [TxIn(b'script', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')

        assert bytes(txobj) == b''.join([b'\x01\x00\x00\x00',
                                         b'\x01txid\x04\x06script\xff\xff\xff\xff',
                                         b'\x01\x88\x13\x00\x00\x00\x00\x00\x00\rscript_pubkey',
                                         b'\x00\x00\x00\x00'])
Ejemplo n.º 3
0
    def test_tx_size(self):
        txin = [
            TxIn(b'script', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')
        ]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin, txout,
                      b'\x00\x00\x00\x00')

        assert txobj.size == 104
Ejemplo n.º 4
0
    def test_repr(self):
        txin = [TxIn(b'script', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')

        assert repr(txobj) == "TxObj({}, {}, {}, {})" \
                              "".format(repr(b'\x01\x00\x00\x00'),
                                        repr(txin),
                                        repr(txout),
                                        repr(b'\x00\x00\x00\x00'))
Ejemplo n.º 5
0
    def test_equality(self):
        txin1 = [
            TxIn(b'script', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')
        ]
        txin2 = [
            TxIn(b'scrip2', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')
        ]
        txout1 = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txout2 = [TxOut(b'\x88\x14\x00\x00\x00\x00\x00\x00', b'script_pubkey')]

        txobj1 = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin1, txout1,
                       b'\x00\x00\x00\x00')
        txobj2 = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin1, txout1,
                       b'\x00\x00\x00\x00')
        txobj3 = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin1, txout2,
                       b'\x00\x00\x00\x00')
        txobj4 = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin2, txout1,
                       b'\x00\x00\x00\x00')
        txobj5 = TxObj(b'\x02\x00\x00\x00', b'\xb0Z\xd1\\', txin1, txout1,
                       b'\x00\x00\x00\x00')
        txobj6 = TxObj(b'\x01\x00\x00\x00', b'\xb0Z\xd1\\', txin1, txout1,
                       b'\x01\x00\x00\x00')

        assert txobj1 == txobj2
        assert txobj1 != txobj3
        assert txobj1 != txobj4
        assert txobj1 != txobj5
        assert txobj1 != txobj6
Ejemplo n.º 6
0
def create_unsigned(inputs: List[Unspent], outputs: List[Output]) -> TxObj:
    """Creates an unsigned transaction object"""

    raw_outputs = construct_outputs(outputs)
    raw_inputs = [
        TxIn(
            script_sig=EMPTY_SCRIPT_SIG,
            txid=serialize_txid(utxo.txid),
            txindex=serialize_txindex(utxo.txindex),
            amount=serialize_amount(utxo.amount),
        ) for utxo in inputs
    ]
    return TxObj(VERSION_2, raw_inputs, raw_outputs, LOCK_TIME)
Ejemplo n.º 7
0
    def test_calculate_preimages(self):
        txin = [
            TxIn(b'script',
                 b'txid',
                 b'\x04',
                 b'witness',
                 sequence=b'\xff\xff\xff\xff')
        ]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')

        want = b'yI\x8d\x99H\xcb\xe3\x88\xce\x83}\xc1\xfc\xaf\xf7\xd5\\\xf67\x93\x86\xb5\xc7M\xd1\xdb\xd2LyJ`<'
        assert calculate_preimages(txobj, [(0, HASH_TYPE, False)])[0] == want

        want = b'\xed\x85\xc1\x0f\xc2\xb1\xc9\x05\xbf\xa6S\x15\xba$\x84\xad\x14\x8dni\x17\x1eD\xd6\xf7e\xd8\x0e\xfb\x05\x93\x1a'
        assert calculate_preimages(txobj, [(0, HASH_TYPE, True)])[0] == want
Ejemplo n.º 8
0
    def test_is_segwit(self):
        txin = [
            TxIn(b'script', b'txid', b'\x04', sequence=b'\xff\xff\xff\xff')
        ]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')
        assert not TxObj.is_segwit(txobj)
        assert not TxObj.is_segwit(bytes(txobj))
        assert not TxObj.is_segwit(bytes(txobj).hex())

        txin = [
            TxIn(b'script',
                 b'txid',
                 b'\x04',
                 b'witness',
                 sequence=b'\xff\xff\xff\xff')
        ]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')
        assert TxObj.is_segwit(txobj)
        assert TxObj.is_segwit(bytes(txobj))
        assert TxObj.is_segwit(bytes(txobj).hex())
Ejemplo n.º 9
0
    def test_calculate_preimages_unsupported_hashtypes(self):
        txin = [
            TxIn(b'script',
                 b'txid',
                 b'\x04',
                 b'witness',
                 sequence=b'\xff\xff\xff\xff')
        ]
        txout = [TxOut(b'\x88\x13\x00\x00\x00\x00\x00\x00', b'script_pubkey')]
        txobj = TxObj(b'\x01\x00\x00\x00', txin, txout, b'\x00\x00\x00\x00')

        with pytest.raises(ValueError):
            calculate_preimages(txobj, [(0, b'\x02\x00\x00\x00', False)])

        with pytest.raises(ValueError):
            calculate_preimages(txobj, [(0, b'\x03\x00\x00\x00', False)])

        with pytest.raises(ValueError):
            calculate_preimages(txobj, [(0, b'\x81\x00\x00\x00', False)])

        with pytest.raises(ValueError):
            calculate_preimages(txobj, [(0, b'\x04\x00\x00\x00', False)])