def test_out_point() -> None: out_point = OutPoint() assert out_point.tx_id == b"\x00" * 32 assert out_point.vout == 0xFFFFFFFF assert out_point.hash == int.from_bytes(out_point.tx_id, "big", signed=False) assert out_point.n == out_point.vout assert out_point.is_coinbase() assert out_point == OutPoint.parse(out_point.serialize()) assert out_point == OutPoint.from_dict(out_point.to_dict()) tx_id = "d5b5982254eebca64e4b42a3092a10bfb76ab430455b2bf0cf7c4f7f32db1c2e" vout = 0 out_point = OutPoint(tx_id, vout) assert out_point.tx_id.hex() == tx_id assert out_point.vout == vout assert out_point.hash == int.from_bytes(out_point.tx_id, "big", signed=False) assert out_point.n == out_point.vout assert not out_point.is_coinbase() assert out_point == OutPoint.parse(out_point.serialize()) assert out_point == OutPoint.from_dict(out_point.to_dict())
def test_invalid_outpoint() -> None: out_point = OutPoint(b"\x01" * 31, 18, check_validity=False) with pytest.raises(BTClibValueError, match="invalid OutPoint tx_id: "): out_point.assert_valid() out_point = OutPoint(b"\x01" * 32, -1, check_validity=False) with pytest.raises(BTClibValueError, match="invalid vout: "): out_point.assert_valid() out_point = OutPoint(b"\x01" * 32, 0xFFFFFFFF + 1, check_validity=False) with pytest.raises(BTClibValueError, match="invalid vout: "): out_point.assert_valid() out_point = OutPoint(b"\x00" * 31 + b"\x01", 0xFFFFFFFF, check_validity=False) with pytest.raises(BTClibValueError, match="invalid OutPoint"): out_point.assert_valid() out_point = OutPoint(b"\x00" * 32, 0, check_validity=False) with pytest.raises(BTClibValueError, match="invalid OutPoint"): out_point.assert_valid()
def __init__( self, prev_out: OutPoint = OutPoint(), script_sig: Octets = b"", sequence: int = 0, script_witness: Witness = Witness(), check_validity: bool = True, ) -> None: self.prev_out = prev_out self.script_sig = bytes_from_octets(script_sig) self.sequence = sequence self.script_witness = script_witness if check_validity: self.assert_valid()