def test_zip243(self):
        coin = coins.by_name("Zcash")

        for v in self.VECTORS:
            tx = SignTx(
                coin_name="Zcash",
                inputs_count=len(v["inputs"]),
                outputs_count=len(v["outputs"]),
                version=v["version"],
                lock_time=v["lock_time"],
                expiry=v["expiry"],
                overwintered=(v["version"] >= 3),
                version_group_id=v["version_group_id"],
            )
            zip243 = Zip243()
            for i in v["inputs"]:
                txi = TxInputType()
                txi.amount = i["amount"]
                txi.prev_hash = unhexlify(i["prevout"][0])
                txi.prev_index = i["prevout"][1]
                txi.script_type = i["script_type"]
                txi.sequence = i["sequence"]
                zip243.add_prevouts(txi)
                zip243.add_sequence(txi)
            for o in v["outputs"]:
                txo = TxOutputBinType()
                txo.amount = o["amount"]
                txo.script_pubkey = unhexlify(o["script_pubkey"])
                zip243.add_output(txo)

            self.assertEqual(hexlify(zip243.get_prevouts_hash()),
                             v["prevouts_hash"])
            self.assertEqual(hexlify(zip243.get_sequence_hash()),
                             v["sequence_hash"])
            self.assertEqual(hexlify(zip243.get_outputs_hash()),
                             v["outputs_hash"])
            self.assertEqual(
                hexlify(
                    zip243.preimage_hash(coin, tx, txi,
                                         unhexlify(i["pubkeyhash"]),
                                         v["hash_type"])),
                v["preimage_hash"],
            )
Esempio n. 2
0
    def test_tx_input(self):
        inp = TxInputType(
            address_n=[0],
            amount=390000,
            prev_hash=unhexlify(
                "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
            ),
            prev_index=0,
            sequence=0xffffffff,
            script_sig=b"0123456789",
        )

        b = bytearray()
        writers.write_tx_input(b, inp)
        self.assertEqual(len(b), 32 + 4 + 1 + 10 + 4)

        for bad_prevhash in (b"", b"x", b"hello", b"x" * 33):
            inp.prev_hash = bad_prevhash
            self.assertRaises(AssertionError, writers.write_tx_input, b, inp)
Esempio n. 3
0
    def test_zip143(self):
        coin = coins.by_name("Zcash")

        for v in self.VECTORS:
            tx = SignTx(
                coin_name="Zcash",
                inputs_count=len(v["inputs"]),
                outputs_count=len(v["outputs"]),
                version=v["version"],
                lock_time=v["lock_time"],
                expiry=v["expiry"],
                version_group_id=v["version_group_id"],
            )

            zip143 = Overwintered(tx, None, coin)

            for i in v["inputs"]:
                txi = TxInputType()
                txi.amount = i["amount"]
                txi.prev_hash = unhexlify(i["prevout"][0])
                txi.prev_index = i["prevout"][1]
                txi.script_type = i["script_type"]
                txi.sequence = i["sequence"]
                zip143.hash143_add_input(txi)
            for o in v["outputs"]:
                txo = TxOutputBinType()
                txo.amount = o["amount"]
                txo.script_pubkey = unhexlify(o["script_pubkey"])
                zip143.hash143_add_output(txo, txo.script_pubkey)

            self.assertEqual(hexlify(get_tx_hash(zip143.h_prevouts)),
                             v["prevouts_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip143.h_sequence)),
                             v["sequence_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip143.h_outputs)),
                             v["outputs_hash"])
            self.assertEqual(
                hexlify(
                    zip143.hash143_preimage_hash(txi,
                                                 unhexlify(i["pubkeyhash"]))),
                v["preimage_hash"],
            )