Esempio n. 1
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
Esempio n. 2
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)])