# ruff: noqa
from algopy import *

class BooleanBinaryOps(Contract):
    def approval_program(self) -> bool:
        test_boolean_binary_ops(true=True, false=False)
        test_boolean_shortcircuit_binary_ops()
        type_coercion()
        test_union_boolean_binary_ops()
        test_literal_boolean_binary_ops()
        test_literal_conditionals(true=True, false=False)
        return True

    def clear_state_program(self) -> bool:
        assert bool() == False
        return True

@subroutine
def test_boolean_binary_ops(*, true: bool, false: bool) -> None:
    assert not (true and false)
    assert not (false and true)
    assert true and true
    assert not (false and false)

    assert true or false
    assert false or true
    assert true or true
    assert not (false or false)

@subroutine
def bool_to_bytes(x: bool) -> Bytes:
    return Bytes(b"true" if x else b"false")

@subroutine
def test_boolean_shortcircuit_binary_ops() -> None:
    for lhs in (True, False):
        for rhs in (True, False):
            and_msg = b"_" + bool_to_bytes(lhs) + b"_and_" + bool_to_bytes(rhs)
            and_result = log_and_return(lhs, b"lhs" + and_msg) and log_and_return(
                rhs, b"rhs" + and_msg
            )
            assert and_result == (lhs and rhs)
            or_msg = b"_" + bool_to_bytes(lhs) + b"_or_" + bool_to_bytes(rhs)
            or_result = log_and_return(lhs, b"lhs" + or_msg) or log_and_return(
                rhs, b"rhs" + or_msg
            )
            assert or_result == (lhs or rhs)

@subroutine
def log_and_return(x: bool, msg: Bytes) -> bool:
    log(msg)
    return x

@subroutine
def type_coercion() -> None:
    b = UInt64(0) or OnCompleteAction.OptIn
    assert b > 0
    c = TransactionType.ApplicationCall or UInt64(0) or OnCompleteAction.OptIn
    assert c == TransactionType.ApplicationCall

@subroutine
def test_union_boolean_binary_ops() -> None:
    ok = bool(Bytes() or UInt64(1))
    assert ok

    x = UInt64(0)
    y = Bytes(b"y")
    z = String("z")
    assert (x or y) or (y or z)
    assert (x or y) and (x or y)
    assert x or (y or z)
    assert (x or y) or z

    assert (String("left") and String("right")).startswith("ri")
    assert String("right").startswith(String("le") and String("ri"))

    bytes_to_iterate = Bytes(b"abc")
    for idx, b in uenumerate(Bytes(b"never seen") and bytes_to_iterate):
        assert b == bytes_to_iterate[idx]
    assert (Bytes(b"left") and Bytes(b"right"))[1] == b"i"
    assert (Bytes(b"left") or Bytes(b"right"))[0:2] == b"le"
    assert "ight" in (String("left") and String("right"))

    assert (UInt64(1) and UInt64(2)) + 3 == 5
    assert ~(UInt64(1) or UInt64(2)) == ~UInt64(1)

@subroutine
def test_literal_boolean_binary_ops() -> None:
    assert 0 or 1
    assert "abc" and 1
    assert UInt64(0) or 1
    assert False or Bytes(b"abc")

    a = bool(0 or 1)
    b = bool("abc" and 1)
    c = bool(UInt64(0) or 1)
    d = bool(False or Bytes(b"abc"))
    assert a and b and c and d

    if 0 and 1:
        assert False
    if "abc" and 0:
        assert False
    if UInt64(0) or 0:
        assert False
    if False or Bytes(b""):
        assert False

    assert UInt64(1 and 2) == 2

    one = UInt64(1)
    assert op.bitlen(one and 4) == 3
    empty_bytes = Bytes()
    assert op.bitlen(empty_bytes or b"hello") > 0

@subroutine
def test_literal_conditionals(*, true: bool, false: bool) -> None:
    assert (3 if false else 0) or 4
    assert 0 or (3 if true else 0)
    assert b"123" or (3 if true else 0)
    assert (3 if false else 0) or b"123"
    y = UInt64((3 if false else 0) or 4)
    assert y == 4
    z = UInt64(0 or (3 if true else 0))
    assert z == 3


from algopy import Contract, UInt64, subroutine, urange

@subroutine(inline=False)
def get_bool() -> bool:
    return True

class MyContract(Contract):
    def approval_program(self) -> UInt64:
        val = UInt64(0)
        for _idx in urange(2):
            if get_bool():
                pass
            elif get_bool():  # noqa: SIM102
                if not get_bool():
                    val += UInt64(123)
        return val

    def clear_state_program(self) -> bool:
        return True


from algopy import Bytes, Contract, subroutine

class BiguintBinaryOps(Contract):
    def approval_program(self) -> bool:
        do_some_ops(
            left=Bytes.from_hex("FF"),
            right=Bytes.from_hex("0F"),
            concat=Bytes.from_hex("FF0F"),
            bitwise_or=Bytes.from_hex("FF"),
            bitwise_xor=Bytes.from_hex("F0"),
            bitwise_and=Bytes.from_hex("0F"),
        )
        do_augmented_assignment_ops(Bytes.from_hex("FF"))
        return True

    def clear_state_program(self) -> bool:
        return True

@subroutine
def do_some_ops(
    *,
    left: Bytes,
    right: Bytes,
    concat: Bytes,
    bitwise_or: Bytes,
    bitwise_xor: Bytes,
    bitwise_and: Bytes,
) -> None:
    result = left + right
    assert result == concat
    result = left | right
    assert result == bitwise_or
    result = left ^ right
    assert result == bitwise_xor
    result = left & right
    assert result == bitwise_and

@subroutine
def do_augmented_assignment_ops(seed: Bytes) -> None:
    seed &= Bytes.from_hex("00")

    assert seed == Bytes.from_hex("00")

    five = Bytes.from_hex("05")

    seed |= five

    assert seed == five

    sixteen = Bytes.from_hex("10")

    seed ^= sixteen

    assert seed == Bytes.from_hex("15")

    seed ^= five

    assert seed == sixteen

    seed += five

    assert seed == Bytes.from_hex("1005")


from algopy import Contract, UInt64, log, subroutine

class MyContract(Contract):
    def approval_program(self) -> UInt64:
        log(42)
        self.echo(UInt64(1), UInt64(2))
        return UInt64(1)

    @subroutine
    def echo(self, a: UInt64, b: UInt64) -> None:
        log(a)
        log(b)

    def clear_state_program(self) -> UInt64:
        return UInt64(1)


import abc

from algopy import Bytes, Contract, log, subroutine

WAVE = "👋".encode()

class BaseContract(Contract, abc.ABC):
    def __init__(self) -> None:
        self.state1 = self.state2 = join_log_and_return(
            right=Bytes(WAVE),
            left=Bytes(b"Hello, world!"),
        )

class ChainedAssignment(BaseContract):
    def __init__(self) -> None:
        super().__init__()

    def approval_program(self) -> bool:
        return True

    def clear_state_program(self) -> bool:
        return True

@subroutine
def join_log_and_return(*, left: Bytes, right: Bytes) -> Bytes:
    result = left + b" " + right
    log(result)
    return result


from algopy import (
    Account,
    ARC4Contract,
    BigUInt,
    Bytes,
    String,
    TemplateVar,
    UInt64,
    arc4,
    logicsig,
    subroutine,
)

@logicsig
def always_approve_sig() -> bool:
    return True

class HelloBase(ARC4Contract):
    def __init__(self) -> None:
        self.greeting = String()

    @arc4.abimethod(allow_actions=["DeleteApplication"])
    def delete(self) -> None:
        pass

    @arc4.baremethod(allow_actions=["UpdateApplication"])
    def update(self) -> None:
        pass

    @arc4.abimethod()
    def greet(self, name: String) -> String:
        return self.greeting + " " + name

class LargeProgram(ARC4Contract):
    @arc4.abimethod()
    def get_big_bytes_length(self) -> UInt64:
        return get_big_bytes().length

    @arc4.abimethod(allow_actions=["DeleteApplication"])
    def delete(self) -> None:
        pass

@subroutine
def get_big_bytes() -> Bytes:
    return Bytes.from_hex("00" * 4096)

class Hello(HelloBase):
    @arc4.abimethod(create="require")
    def create(self, greeting: String) -> None:
        self.greeting = greeting

class HelloTmpl(HelloBase):
    def __init__(self) -> None:
        self.greeting = TemplateVar[String]("GREETING")

    @arc4.abimethod(create="require")
    def create(self) -> None:
        pass

class HelloPrfx(HelloBase):
    def __init__(self) -> None:
        self.greeting = TemplateVar[String]("GREETING", prefix="PRFX_")

    @arc4.abimethod(create="require")
    def create(self) -> None:
        pass

class HelloOtherConstants(ARC4Contract):
    def __init__(self) -> None:
        self.greeting = TemplateVar[String]("GREETING")
        self.num = TemplateVar[BigUInt]("NUM")
        self.address = TemplateVar[Account]("ACCOUNT")
        self.method = TemplateVar[Bytes]("METHOD")

    @arc4.abimethod(create="require")
    def create(self) -> UInt64:
        return UInt64(1)

    @arc4.abimethod(allow_actions=["DeleteApplication"])
    def delete(self) -> None:
        pass

    @arc4.abimethod()
    def greet(self, name: String) -> Bytes:
        num_alpha = (self.num + 48).bytes[-1]
        return (
            self.greeting.bytes + b" " + name.bytes + num_alpha + self.address.bytes + self.method
        )


from algopy import (
    Account,
    ARC4Contract,
    BigUInt,
    Global,
    OnCompleteAction,
    String,
    UInt64,
    arc4,
    compile_contract,
    compile_logicsig,
    itxn,
)

from test_cases.compile.apps import (
    Hello,
    HelloOtherConstants,
    HelloPrfx,
    HelloTmpl,
    LargeProgram,
    always_approve_sig,
)

class HelloFactory(ARC4Contract):
    @arc4.abimethod()
    def test_logicsig(self) -> arc4.Address:
        return arc4.Address(compile_logicsig(always_approve_sig).account)

    @arc4.abimethod()
    def test_compile_contract(self) -> None:
        # create app
        compiled = compile_contract(Hello)
        hello_app = (
            itxn.ApplicationCall(
                app_args=(arc4.arc4_signature("create(string)void"), arc4.String("hello")),
                approval_program=compiled.approval_program,
                clear_state_program=compiled.clear_state_program,
                global_num_bytes=1,
            )
            .submit()
            .created_app
        )

        # call the new app
        txn = itxn.ApplicationCall(
            app_args=(arc4.arc4_signature("greet(string)string"), arc4.String("world")),
            app_id=hello_app,
        ).submit()
        result = arc4.String.from_log(txn.last_log)

        # delete the app
        itxn.ApplicationCall(
            app_id=hello_app,
            app_args=(arc4.arc4_signature("delete()void"),),
            on_completion=OnCompleteAction.DeleteApplication,
        ).submit()

        assert result == "hello world"

    @arc4.abimethod()
    def test_compile_contract_tmpl(self) -> None:
        # create app
        greeting = String("hey")
        compiled = compile_contract(HelloTmpl, template_vars={"GREETING": greeting})
        hello_app = (
            itxn.ApplicationCall(
                app_args=(arc4.arc4_signature("create()void"),),
                approval_program=compiled.approval_program,
                clear_state_program=compiled.clear_state_program,
                global_num_uint=compiled.global_uints,
                global_num_bytes=compiled.global_bytes,
                local_num_uint=compiled.local_uints,
                local_num_bytes=compiled.local_bytes,
            )
            .submit()
            .created_app
        )

        # call the new app
        txn = itxn.ApplicationCall(
            app_args=(arc4.arc4_signature("greet(string)string"), arc4.String("world")),
            app_id=hello_app,
        ).submit()
        result = arc4.String.from_log(txn.last_log)

        # delete the app
        itxn.ApplicationCall(
            app_id=hello_app,
            app_args=(arc4.arc4_signature("delete()void"),),
            on_completion=OnCompleteAction.DeleteApplication,
        ).submit()

        assert result == "hey world"

    @arc4.abimethod()
    def test_compile_contract_prfx(self) -> None:
        # create app
        compiled = compile_contract(
            HelloPrfx, template_vars={"GREETING": String("hi")}, template_vars_prefix="PRFX_"
        )
        hello_app = (
            itxn.ApplicationCall(
                app_args=(arc4.arc4_signature("create()void"),),
                approval_program=compiled.approval_program,
                clear_state_program=compiled.clear_state_program,
                global_num_bytes=compiled.global_bytes,
            )
            .submit()
            .created_app
        )

        # call the new app
        txn = itxn.ApplicationCall(
            app_args=(arc4.arc4_signature("greet(string)string"), arc4.String("world")),
            app_id=hello_app,
        ).submit()
        result = arc4.String.from_log(txn.last_log)

        # delete the app
        itxn.ApplicationCall(
            app_id=hello_app,
            app_args=(arc4.arc4_signature("delete()void"),),
            on_completion=OnCompleteAction.DeleteApplication,
        ).submit()

        assert result == "hi world"

    @arc4.abimethod()
    def test_compile_contract_large(self) -> None:
        # create app
        compiled = compile_contract(LargeProgram)
        hello_app = (
            itxn.ApplicationCall(
                approval_program=compiled.approval_program,
                clear_state_program=compiled.clear_state_program,
                extra_program_pages=compiled.extra_program_pages,
                global_num_bytes=compiled.global_bytes,
            )
            .submit()
            .created_app
        )

        # call the new app
        txn = itxn.ApplicationCall(
            app_args=(arc4.arc4_signature("get_big_bytes_length()uint64"),),
            app_id=hello_app,
        ).submit()
        result = arc4.UInt64.from_log(txn.last_log)

        # delete the app
        itxn.ApplicationCall(
            app_id=hello_app,
            app_args=(arc4.arc4_signature("delete()void"),),
            on_completion=OnCompleteAction.DeleteApplication,
        ).submit()

        assert result == 4096

    @arc4.abimethod()
    def test_arc4_create(self) -> None:
        # create app
        hello_app = arc4.arc4_create(Hello.create, "hello").created_app

        # call the new app
        result, _txn = arc4.abi_call(Hello.greet, "world", app_id=hello_app)

        # delete the app
        arc4.abi_call(
            Hello.delete,
            app_id=hello_app,
            # on_complete is inferred from Hello.delete ARC4 definition
        )

        assert result == "hello world"

    @arc4.abimethod()
    def test_arc4_create_tmpl(self) -> None:
        # create app
        compiled = compile_contract(HelloTmpl, template_vars={"GREETING": String("tmpl2")})
        hello_app = arc4.arc4_create(
            HelloTmpl.create,
            compiled=compiled,
        ).created_app

        # call the new app
        result, _txn = arc4.abi_call(HelloTmpl.greet, "world", app_id=hello_app)

        # delete the app
        arc4.abi_call(
            HelloTmpl.delete,
            app_id=hello_app,
            # on_complete is inferred from Hello.delete ARC4 definition
        )

        assert result == "tmpl2 world"

    @arc4.abimethod()
    def test_arc4_create_prfx(self) -> None:
        # create app
        compiled = compile_contract(
            HelloPrfx, template_vars_prefix="PRFX_", template_vars={"GREETING": String("prfx2")}
        )
        hello_app = arc4.arc4_create(
            HelloPrfx.create,
            compiled=compiled,
        ).created_app

        # call the new app
        result, _txn = arc4.abi_call(HelloPrfx.greet, "world", app_id=hello_app)

        # delete the app
        arc4.abi_call(
            HelloPrfx.delete,
            app_id=hello_app,
            # on_complete is inferred from Hello.delete ARC4 definition
        )

        assert result == "prfx2 world"

    @arc4.abimethod()
    def test_arc4_create_large(self) -> None:
        # create app
        app = arc4.arc4_create(LargeProgram).created_app

        # call the new app
        result, _txn = arc4.abi_call(LargeProgram.get_big_bytes_length, app_id=app)
        assert result == 4096

        # delete the app
        arc4.abi_call(
            LargeProgram.delete,
            app_id=app,
        )

    @arc4.abimethod()
    def test_arc4_create_modified_compiled(self) -> None:
        compiled = compile_contract(Hello)
        compiled = compiled._replace(
            local_uints=UInt64(3),
            global_uints=UInt64(4),
            local_bytes=UInt64(5),
            global_bytes=UInt64(6),
        )
        app = arc4.arc4_create(
            Hello.create,
            String("hey"),
            compiled=compiled,
        ).created_app

        assert app.local_num_uint == 3
        assert app.global_num_uint == 4
        assert app.local_num_bytes == 5
        assert app.global_num_bytes == 6

        result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)

        assert result == "hey there"

        # delete the app
        arc4.abi_call(Hello.delete, app_id=app)

    @arc4.abimethod()
    def test_arc4_update(self) -> None:
        # create app
        app = arc4.arc4_create(
            HelloTmpl,
            compiled=compile_contract(
                HelloTmpl,
                template_vars={"GREETING": String("hi")},
                extra_program_pages=1,
                global_uints=2,
                global_bytes=2,
                local_bytes=2,
                local_uints=2,
            ),
        ).created_app

        # call the new app
        result, _txn = arc4.abi_call(HelloTmpl.greet, "there", app_id=app)
        assert result == "hi there"

        # update the app
        arc4.arc4_update(Hello, app_id=app)

        # call the updated app
        result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)
        assert result == "hi there"

        # delete the app
        arc4.abi_call(
            Hello.delete,
            app_id=app,
            # on_complete is inferred from Hello.delete ARC4 definition
        )

    @arc4.abimethod()
    def test_other_constants(self) -> None:
        app = arc4.arc4_create(
            HelloOtherConstants,
            compiled=compile_contract(
                HelloOtherConstants,
                template_vars={
                    "NUM": BigUInt(5),
                    "GREETING": String("hello"),
                    "ACCOUNT": Account(
                        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ"
                    ),
                    "METHOD": arc4.arc4_signature("something()void"),
                },
            ),
        ).created_app

        result, _txn = arc4.abi_call(HelloOtherConstants.greet, "Johnny", app_id=app)

        assert result == (
            b"hello Johnny5" + Global.zero_address.bytes + arc4.arc4_signature("something()void")
        )

        # delete the app
        arc4.abi_call(HelloOtherConstants.delete, app_id=app)

    @arc4.abimethod()
    def test_abi_call_create_params(self) -> None:
        compiled = compile_contract(Hello)
        app = arc4.abi_call(
            Hello.create,
            String("hey"),
            approval_program=compiled.approval_program,
            clear_state_program=compiled.clear_state_program,
            global_num_uint=compiled.global_uints,
            global_num_bytes=compiled.global_bytes,
            local_num_uint=compiled.local_uints,
            local_num_bytes=compiled.local_bytes,
            extra_program_pages=compiled.extra_program_pages,
        ).created_app

        result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)

        assert result == "hey there"

        # delete the app
        arc4.abi_call(Hello.delete, app_id=app)


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Hello(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
        greeting: algopy.arc4.String,
    ) -> None: ...

    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def greet(
        self,
        name: algopy.arc4.String,
    ) -> algopy.arc4.String: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class HelloBase(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def greet(
        self,
        name: algopy.arc4.String,
    ) -> algopy.arc4.String: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class HelloFactory(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def test_logicsig(
        self,
    ) -> algopy.arc4.Address: ...

    @algopy.arc4.abimethod
    def test_compile_contract(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_compile_contract_tmpl(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_compile_contract_prfx(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_compile_contract_large(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_create(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_create_tmpl(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_create_prfx(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_create_large(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_create_modified_compiled(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_arc4_update(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_other_constants(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_abi_call_create_params(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class HelloOtherConstants(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...

    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def greet(
        self,
        name: algopy.arc4.String,
    ) -> algopy.arc4.DynamicBytes: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class HelloPrfx(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def greet(
        self,
        name: algopy.arc4.String,
    ) -> algopy.arc4.String: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class HelloTmpl(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def greet(
        self,
        name: algopy.arc4.String,
    ) -> algopy.arc4.String: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class LargeProgram(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def get_big_bytes_length(
        self,
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...

    @algopy.arc4.abimethod(allow_actions=['DeleteApplication'])
    def delete(
        self,
    ) -> None: ...


from algopy import Contract, subroutine

class ConditionalExecutionContract(Contract):
    def __init__(self) -> None:
        self.did_execute_a = False
        self.did_execute_b = False

    def approval_program(self) -> bool:
        # 'or' won't execute rhs if lhs is True
        self.func_a(True) or self.func_b(True)
        self.assert_and_reset(
            self.did_execute_a and not self.did_execute_b,
        )

        # 'or' executes rhs if lhs is False
        self.func_a(False) or self.func_b(True)
        self.assert_and_reset(
            self.did_execute_a and self.did_execute_b,
        )

        # 'and' won't execute rhs if lhs is False
        self.func_a(False) and self.func_b(True)
        self.assert_and_reset(
            self.did_execute_a and not self.did_execute_b,
        )

        # 'and' executes rhs if lhs is True
        self.func_a(True) and self.func_b(True)
        self.assert_and_reset(
            self.did_execute_a and self.did_execute_b,
        )

        # Tuples are fully evaluated before indexing is done
        (self.func_a(True), self.func_b(True))[0]
        self.assert_and_reset(
            self.did_execute_a and self.did_execute_b,
        )

        # Ternary condition won't execute <false expr> if condition is True
        self.func_a(True) if self.func_c(True) else self.func_b(True)
        self.assert_and_reset(
            self.did_execute_a and not self.did_execute_b,
        )

        # Ternary condition won't execute <true expr> if condition is False
        self.func_a(True) if self.func_c(False) else self.func_b(True)
        self.assert_and_reset(
            not self.did_execute_a and self.did_execute_b,
        )

        return True

    def clear_state_program(self) -> bool:
        return True

    @subroutine
    def assert_and_reset(self, condition: bool) -> None:
        assert condition
        self.did_execute_b = False
        self.did_execute_a = False

    @subroutine
    def func_a(self, ret_val: bool) -> bool:
        self.did_execute_a = True
        return ret_val

    @subroutine
    def func_b(self, ret_val: bool) -> bool:
        self.did_execute_b = True
        return ret_val

    @subroutine
    def func_c(self, ret_val: bool) -> bool:
        return ret_val


from algopy import Contract, UInt64, log, op, subroutine

class MyContract(Contract):
    """My contract"""

    def approval_program(self) -> UInt64:
        a = UInt64(1)
        b = UInt64(2)

        c = a or b
        d = b and a

        e = self.expensive_op(UInt64(0)) or self.side_effecting_op(UInt64(1))
        f = self.expensive_op(UInt64(3)) or self.side_effecting_op(UInt64(42))

        g = self.side_effecting_op(UInt64(0)) and self.expensive_op(UInt64(42))
        h = self.side_effecting_op(UInt64(2)) and self.expensive_op(UInt64(3))

        i = a if b < c else d + e

        result = a * b * c * d * f * h - e - g + i

        log(op.itob(result))

        return result

    def clear_state_program(self) -> UInt64:
        return UInt64(0)

    @subroutine
    def expensive_op(self, val: UInt64) -> UInt64:
        assert val != 42, "Can't be 42"
        log("expensive_op")
        return val

    @subroutine
    def side_effecting_op(self, val: UInt64) -> UInt64:
        assert val != 42, "Can't be 42"
        log("side_effecting_op")
        return val


from algopy import Contract, UInt64, subroutine

class Literals(Contract):
    def approval_program(self) -> bool:
        self.with_variable_condition(condition=False)
        self.with_variable_condition(condition=True)

        return True

    def clear_state_program(self) -> bool:
        return True

    @subroutine
    def with_variable_condition(self, *, condition: bool) -> None:
        x = UInt64(1 if condition else 0)
        assert bool(x) == condition
        assert x == -(-1 if condition else 0)  # test unary op propagation
        y = x + ((1 if condition else 2) - 1)  # test binary op with non-literal & literal
        y2 = ((1 if condition else 2) - 1) + x  # test binary op with literal & non-literal
        assert y == 1
        assert y2 == 1
        maybe = (1 if condition else 0) < y  # test comparison with non-literal
        assert maybe == (not condition)
        assert (1 if condition else 0) != 2  # test comparison with literal


from algopy import Account, Contract, log, op

class AddressConstantContract(Contract):
    def approval_program(self) -> bool:
        some_address = Account()
        assert not some_address
        some_address = Account(SOME_ADDRESS)
        assert some_address
        some_address = Account.from_bytes(some_address.bytes)
        some_address = Account(some_address.bytes)

        sender = op.Txn.sender
        sender_bytes = sender.bytes
        log(sender_bytes)
        is_some_address = op.Txn.sender == some_address

        return not is_some_address

    def clear_state_program(self) -> bool:
        return True

SOME_ADDRESS = "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA"


from algopy import Bytes, Contract, UInt64, log, op

class ByteConstantsContract(Contract):
    def approval_program(self) -> UInt64:
        base_64 = Bytes.from_base64("QmFzZSA2NCBlbmNvZGVk")
        base_32 = Bytes.from_base32("IJQXGZJAGMZCAZLOMNXWIZLE")
        base_16 = Bytes.from_hex("4261736520313620656E636F646564")
        utf8 = Bytes(b"UTF-8 Encoded")

        result = base_16 + b"|" + base_64 + b"|" + base_32 + b"|" + utf8
        log(result)
        log(op.itob(result.length))
        return UInt64(1)

    def clear_state_program(self) -> bool:
        return True


# vim:fileencoding=iso-8859-7

OMEGA = "Ω".encode("iso-8859-7")


from algopy import Application, BigUInt, Bytes, Contract, String, UInt64, arc4, subroutine

class MyContract(Contract):
    """My contract"""

    def approval_program(self) -> UInt64:
        not_ten = UInt64(15)

        one_true = self.is_in_tuple_1(UInt64(10), (UInt64(10), not_ten, Bytes(b"five")))
        one_false = self.is_in_tuple_1(UInt64(5), (UInt64(10), not_ten, Bytes(b"five")))
        assert one_true, "Should be true"
        assert not one_false, "Should be false"

        two_true = self.is_in_tuple_2(
            Bytes(b"hello"), (Bytes(b"hello"), UInt64(0), Bytes(b"bonjour"))
        )
        two_false = self.is_in_tuple_2(
            Bytes(b"ciao"), (Bytes(b"hello"), UInt64(0), Bytes(b"bonjour"))
        )
        assert two_true, "Should be true"
        assert not two_false, "Should be false"

        three_true = self.is_in_tuple_3(
            BigUInt(32323423423423), (BigUInt(32323423423423), BigUInt(8439439483934))
        )
        three_false = self.is_in_tuple_3(
            BigUInt(32323423423423) + BigUInt(32323423423423),
            (BigUInt(32323423423423), BigUInt(8439439483934)),
        )
        assert three_true, "Should be true"
        assert not three_false, "Should be false"

        self.test_string_types()
        self.test_numeric_types()

        return UInt64(1)

    def clear_state_program(self) -> UInt64:
        return UInt64(1)

    @subroutine
    def is_in_tuple_1(self, x: UInt64, y: tuple[UInt64, UInt64, Bytes]) -> bool:
        return x in y

    @subroutine
    def is_in_tuple_2(self, x: Bytes, y: tuple[Bytes, UInt64, Bytes]) -> bool:
        return x in y

    @subroutine
    def is_in_tuple_3(self, x: BigUInt, y: tuple[BigUInt, BigUInt]) -> bool:
        return x in y

    @subroutine
    def test_string_types(self) -> None:
        assert foo_string() in (foo_string(), baz_string()), "foo in (foo, baz)"
        assert foo_string() not in (bar_string(), baz_string()), "foo not in (bar, baz)"
        assert foo_string() in (foo_arc4(), baz_string(), bar_string()), "foo in (foo, baz, bar)"
        assert foo_arc4() in (foo_string(), baz_string(), bar_string()), "foo in (foo, baz, bar)"
        assert foo_string() not in (bar_arc4(), baz_string()), "foo not in (bar, baz)"
        assert foo_arc4() not in (bar_arc4(), baz_string()), "foo not in (bar, baz)"
        assert foo_string() in (
            bar_arc4(),
            baz_string(),
            foo_string(),
            one_u64(),
        ), "foo in (bar, baz, foo, 1)"
        assert foo_arc4() in (
            bar_arc4(),
            baz_string(),
            foo_string(),
            one_u64(),
        ), "foo in (bar, baz, foo, 1)"
        assert foo_string() not in (
            bar_arc4(),
            baz_string(),
            one_u64(),
        ), "foo not in (bar, baz, 1)"
        assert foo_arc4() not in (bar_arc4(), baz_string(), one_u64()), "foo not in (bar, baz, 1)"
        assert Bytes(b"foo") not in (
            foo_string(),
            foo_arc4(),
            Bytes(b"bar"),
        ), "b'foo' not in (foo, foo, b'bar')"

    @subroutine
    def test_numeric_types(self) -> None:
        assert one_u64() in (one_u64(), two_u64()), "1 in (1, 2)"
        assert one_u64() not in (UInt64(3), two_u64()), "1 not in (3, 2)"

        assert one_u64() in (one_u64(), UInt64(3), two_u8()), "1 in (1, 3, 2)"
        assert one_u64() in (one_arc4u64(), UInt64(4), two_u8()), "1 in (1, 4, 2)"
        assert UInt64(2) in (one_arc4u64(), UInt64(3), two_u8()), "2 in (1, 3, 2)"
        assert two_u8() in (one_arc4u64(), UInt64(3), two_u8()), "2 in (1, 3, 2)"
        assert two_u8() in (one_arc4u64(), UInt64(2), UInt64(3)), "2 in (1, 2, 3)"
        assert three_u512() in (UInt64(3), UInt64(4)), "3 in (3, 4)"
        assert four_biguint() in (UInt64(5), UInt64(4)), "4 in (5, 4)"

        assert one_u64() not in (UInt64(5), two_u8()), "1 not in (5, 2)"
        assert one_u64() not in (Application(1), UInt64(3), two_u8()), "1 not in (app(1), 3, 2)"
        assert one_u64() not in (UInt64(3), two_u8()), "1 not in (3, 2)"
        assert UInt64(2) not in (one_arc4u64(), UInt64(3)), "2 not in (1, 3)"
        assert two_u8() not in (one_arc4u64(), UInt64(3)), "2 not in (1, 3)"
        assert two_u8() not in (one_arc4u64(), UInt64(3)), "2 not in (1, 3)"
        assert three_u512() not in (UInt64(5), UInt64(7)), "3 not in (5, 7)"
        assert four_biguint() not in (UInt64(2), UInt64(9)), "4 not in (2, 9)"

        assert one_u64() in (
            foo_string(),
            one_u64(),
            UInt64(3),
            two_u8(),
        ), "1 in (foo, 1, 3, 2)"
        assert one_u64() in (one_arc4u64(), bar_string(), two_u8()), "1 in (1, bar, 2)"
        assert UInt64(2) in (foo_arc4(), UInt64(3), two_u8()), "2 in (foo, 3, 2)"
        assert two_u8() in (bar_arc4(), UInt64(3), two_u8()), "2 in (bar, 3, 2)"
        assert two_u8() in (foo_string(), UInt64(2), UInt64(3)), "2 in foo(2, 3)"
        assert three_u512() in (UInt64(5), UInt64(3), foo_string()), "3 in (5, 3, foo)"

        assert one_u64() not in (
            foo_string(),
            UInt64(3),
            two_u8(),
        ), "1 not in (foo, 3, 2)"
        assert one_u64() not in (bar_string(), two_u8()), "1 not in (bar, 2)"
        assert UInt64(2) not in (foo_arc4(), UInt64(3)), "2 not in (foo, 3)"
        assert two_u8() not in (bar_arc4(), UInt64(3)), "2 not in (bar, 3)"
        assert two_u8() not in (foo_string(), UInt64(3)), "2 not in (foo, 3)"
        assert three_u512() not in (UInt64(5), foo_string()), "3 not in (5, foo)"
        assert arc4.UInt8(65) not in (
            Bytes(b"A"),
            UInt64(64),
            UInt64(66),
        ), "65 not in (b'A', 64, 66)"

@subroutine
def one_u64() -> UInt64:
    return UInt64(1)

@subroutine
def one_arc4u64() -> arc4.UInt64:
    return arc4.UInt64(1)

@subroutine
def two_u64() -> UInt64:
    return UInt64(2)

@subroutine
def two_u8() -> arc4.UInt8:
    return arc4.UInt8(2)

@subroutine
def three_u512() -> arc4.UInt512:
    return arc4.UInt512(3)

@subroutine
def four_biguint() -> BigUInt:
    return BigUInt(4)

@subroutine
def foo_string() -> String:
    return String("foo")

@subroutine
def foo_arc4() -> arc4.String:
    return arc4.String("foo")

@subroutine
def bar_string() -> String:
    return String("bar")

@subroutine
def bar_arc4() -> arc4.String:
    return arc4.String("bar")

@subroutine
def baz_string() -> String:
    return String("baz")


from algopy import Contract, UInt64, log, op

class MyContract(Contract):
    def approval_program(self) -> bool:
        do_log = False
        match op.Txn.num_app_args:
            case UInt64(1):
                do_log = True
            case UInt64(3):
                do_log = True
        if do_log:
            log(op.itob(op.Txn.num_app_args))
        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import Bytes, TemplateVar, UInt64, arc4, log, subroutine

class DebugContract(arc4.ARC4Contract):
    @arc4.abimethod
    def test(self, x: UInt64, y: UInt64, z: UInt64) -> UInt64:
        a = x * TemplateVar[UInt64]("A_MULT")
        b = x + y
        c = b * z
        if b < c:
            a = a + y
        elif a < c:
            a = a + z
        elif b < a:
            a = a * 3
        elif b > a:
            b = b + a

        if a + b < c:
            a *= some_func(a, y)
        else:
            b *= some_func(b, z)

        bee = itoa(b)
        c = a + b
        cea = itoa(c)

        if a < c:
            a += c
        if a < b:
            a += b
        if a < b + c:
            a = a * z

        aye = itoa(a)
        log(aye, bee, cea, sep=" ")

        return a

@subroutine
def some_func(a: UInt64, b: UInt64) -> UInt64:
    a += b
    b *= a
    a += b
    a *= 2
    x = a + b
    y = a * b
    return x if x < y else y

@subroutine
def itoa(i: UInt64) -> Bytes:
    digits = Bytes(b"0123456789")
    radix = digits.length
    if i < radix:
        return digits[i]
    return itoa(i // radix) + digits[i % radix]


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class DebugContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def test(
        self,
        x: algopy.arc4.UIntN[typing.Literal[64]],
        y: algopy.arc4.UIntN[typing.Literal[64]],
        z: algopy.arc4.UIntN[typing.Literal[64]],
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...


from algopy import arc4, log

from test_cases.diamond_mro.gp import GP

class Base1(GP):
    def __init__(self) -> None:
        log("base1.__init__")
        super().__init__()

    @arc4.abimethod
    def method(self) -> None:
        log("base1.method")
        super().method()


from algopy import arc4, log

from test_cases.diamond_mro.gp import GP

class Base2(GP):
    def __init__(self) -> None:
        log("base2.__init__")
        super().__init__()

    @arc4.abimethod
    def method(self) -> None:
        log("base2.method")
        super().method()


from algopy import arc4, log

from test_cases.diamond_mro.base1 import Base1
from test_cases.diamond_mro.base2 import Base2

class Derived(Base1, Base2):
    def __init__(self) -> None:
        log("derived.__init__")
        super().__init__()

    @arc4.abimethod
    def method(self) -> None:
        log("derived.method")
        super().method()


import abc

from algopy import ARC4Contract, arc4, log

class GP(ARC4Contract, abc.ABC):
    def __init__(self) -> None:
        log("gp.__init__")
        super().__init__()

    @arc4.abimethod(create="require")
    def create(self) -> None:
        pass

    @arc4.abimethod
    def method(self) -> None:
        log("gp.method")


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Base1(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def method(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Base2(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def method(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Derived(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def method(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class GP(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def method(
        self,
    ) -> None: ...


from algopy import Contract, Txn

class MyContract(Contract):
    def approval_program(self) -> bool:
        a = Txn.application_args(0)
        b = Txn.application_args(1)

        assert a + b
        return (b + a).length > 0

    def clear_state_program(self) -> bool:
        return True


from algopy import Contract, UInt64, log, op

class VerifyContract(Contract):
    def approval_program(self) -> bool:
        assert op.Txn.num_app_args == 3
        result = op.ed25519verify_bare(
            op.Txn.application_args(0),
            op.Txn.application_args(1),
            op.Txn.application_args(2),
        )
        log(op.itob(UInt64(1) if result else UInt64(0)))
        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import Bytes, Contract, UInt64, subroutine, uenumerate, urange

class EnumerationContract(Contract):
    def approval_program(self) -> bool:
        iteration_count, item_sum, index_sum = enumerate_urange(UInt64(10), UInt64(21), UInt64(5))

        assert iteration_count == 6
        assert item_sum == 90
        assert index_sum == 3

        iteration_count, item_concat, index_sum = enumerate_tuple(
            (Bytes(b"How"), Bytes(b"Now"), Bytes(b"Brown"), Bytes(b"Cow"))
        )

        assert iteration_count == 8
        assert item_concat == Bytes(b"HowNowBrownCowHowNowBrownCow")
        assert index_sum == 6

        iteration_count, item_concat, index_sum = enumerate_bytes(Bytes(b"abcdefg"))

        assert iteration_count == 14
        assert item_concat == Bytes(b"abcdefgabcdefg")
        assert index_sum == 21

        return True

    def clear_state_program(self) -> bool:
        return True

@subroutine
def enumerate_urange(start: UInt64, stop: UInt64, step: UInt64) -> tuple[UInt64, UInt64, UInt64]:
    iteration_count = UInt64(0)
    item_sum = UInt64(0)
    index_sum = UInt64(0)

    for item in urange(start, stop, step):
        iteration_count += 1
        item_sum += item

    for index, item in uenumerate(urange(start, stop, step)):
        iteration_count += 1
        item_sum += item
        index_sum += index

    return iteration_count, item_sum, index_sum

@subroutine
def enumerate_tuple(tup: tuple[Bytes, Bytes, Bytes, Bytes]) -> tuple[UInt64, Bytes, UInt64]:
    iteration_count = UInt64(0)
    item_concat = Bytes(b"")
    index_sum = UInt64(0)

    for item in tup:
        iteration_count += 1
        item_concat += item
    for index, item in uenumerate(tup):
        iteration_count += 1
        item_concat += item
        index_sum += index

    return iteration_count, item_concat, index_sum

@subroutine
def enumerate_bytes(bytes_: Bytes) -> tuple[UInt64, Bytes, UInt64]:
    iteration_count = UInt64(0)
    item_concat = Bytes(b"")
    index_sum = UInt64(0)

    for item in bytes_:
        iteration_count += 1
        item_concat += item
    for index, item in uenumerate(bytes_):
        iteration_count += 1
        item_concat += item
        index_sum += index

    return iteration_count, item_concat, index_sum


import typing as t

__all__ = [
    "BANNED",
]
__all__ += [
    "EXT_ZERO",
    "EXT_ONE",
]

BANNED = HACKER = "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA"
EXT_ZERO: t.Final = 0
EXT_ONE = 1


from algopy import (
    Account,
    ARC4Contract,
    LocalState,
    OnCompleteAction,
    UInt64,
    op,
    subroutine,
)
from algopy.arc4 import (
    String,
    UInt64 as arc4_UInt64,
    abimethod,
)

from test_cases.everything.constants import BANNED, EXT_ONE
from test_cases.everything.my_base import MyMiddleBase, multiplicative_identity

ZERO = ZER0 = 0  # lol
ONE = ZERO + (ZER0 * 2) + (2 - 1) // EXT_ONE

@subroutine
def get_banned() -> Account:
    addr = Account(BANNED)
    return addr

@subroutine
def add_one(x: UInt64) -> UInt64:
    new_value = x
    one = UInt64(ONE)
    new_value += one
    return new_value

class Everything(ARC4Contract, MyMiddleBase, name="MyContract"):
    def __init__(self) -> None:
        self.name = LocalState(String)

    @abimethod(create="require")
    def create(self) -> None:
        self._check_ban_list()
        self.remember_creator()
        self.counter = UInt64(ZERO)

    @abimethod(allow_actions=["NoOp", "OptIn"])
    def register(self, name: String) -> None:
        self._check_ban_list()
        if op.Txn.on_completion == OnCompleteAction.OptIn:
            sender_name, sender_name_existed = self.name.maybe(account=0)
            if not sender_name_existed:
                self.counter += multiplicative_identity()  # has full FuncDef
        self.name[0] = name

    @abimethod
    def say_hello(self) -> String:
        self._check_ban_list()
        name, exists = self.name.maybe(account=0)
        if not exists:
            return String("Howdy stranger!")
        return "Hello, " + name + "!"

    @abimethod
    def calculate(self, a: arc4_UInt64, b: arc4_UInt64) -> arc4_UInt64:
        c = super().calculate(a, b)
        return arc4_UInt64(c.native * b.native)

    @abimethod(allow_actions=["CloseOut"])
    def close_out(self) -> None:
        self._remove_sender()

    def clear_state_program(self) -> bool:
        self._remove_sender()
        return True

    @subroutine
    def _check_ban_list(self) -> None:
        assert op.Txn.sender != get_banned(), "You are banned, goodbye"

    @subroutine
    def _remove_sender(self) -> None:
        self.counter -= positive_one()

@subroutine
def positive_one() -> UInt64:
    return UInt64(1)


from abc import ABC

from algopy import Contract, UInt64, arc4, op, subroutine

class MyBase(Contract, ABC):
    @subroutine
    def remember_creator(self) -> None:
        self.creator = op.Txn.sender

class MyMiddleBase(MyBase, ABC):
    @subroutine
    def calculate(self, a: arc4.UInt64, b: arc4.UInt64) -> arc4.UInt64:
        return arc4.UInt64(a.native + b.native)

@subroutine
def multiplicative_identity() -> UInt64:
    return UInt64(1)


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class MyContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod(create='require')
    def create(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod(allow_actions=['NoOp', 'OptIn'])
    def register(
        self,
        name: algopy.arc4.String,
    ) -> None: ...

    @algopy.arc4.abimethod
    def say_hello(
        self,
    ) -> algopy.arc4.String: ...

    @algopy.arc4.abimethod
    def calculate(
        self,
        a: algopy.arc4.UIntN[typing.Literal[64]],
        b: algopy.arc4.UIntN[typing.Literal[64]],
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...

    @algopy.arc4.abimethod(allow_actions=['CloseOut'])
    def close_out(
        self,
    ) -> None: ...


from algopy import ARC4Contract, Global, UInt64, arc4, gtxn, op

class AppExpectingEffects(ARC4Contract):
    @arc4.abimethod
    def create_group(
        self,
        asset_create: gtxn.AssetConfigTransaction,
        app_create: gtxn.ApplicationCallTransaction,
    ) -> tuple[UInt64, UInt64]:
        assert asset_create.created_asset.id, "expected asset created"
        assert (
            op.gaid(asset_create.group_index) == asset_create.created_asset.id
        ), "expected correct asset id"
        assert app_create.created_app.id, "expected app created"
        assert (
            op.gaid(app_create.group_index) == app_create.created_app.id
        ), "expected correct app id"

        return asset_create.created_asset.id, app_create.created_app.id

    @arc4.abimethod
    def log_group(self, app_call: gtxn.ApplicationCallTransaction) -> None:
        assert app_call.app_args(0) == arc4.arc4_signature(
            "some_value()uint64"
        ), "expected correct method called"
        assert app_call.num_logs == 1, "expected logs"
        assert (
            arc4.UInt64.from_log(app_call.last_log)
            == (app_call.group_index + 1) * Global.group_size
        )


from algopy import ARC4Contract, Global, Txn, UInt64, arc4

class AppCall(ARC4Contract):
    @arc4.abimethod()
    def some_value(self) -> UInt64:
        return Global.group_size * (Txn.group_index + 1)


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class AppCall(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def some_value(
        self,
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class AppExpectingEffects(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def create_group(
        self,
        asset_create: algopy.gtxn.AssetConfigTransaction,
        app_create: algopy.gtxn.ApplicationCallTransaction,
    ) -> algopy.arc4.Tuple[algopy.arc4.UIntN[typing.Literal[64]], algopy.arc4.UIntN[typing.Literal[64]]]: ...

    @algopy.arc4.abimethod
    def log_group(
        self,
        app_call: algopy.gtxn.ApplicationCallTransaction,
    ) -> None: ...


import algopy

from test_cases.inheritance.grandparent import GrandParentContract
from test_cases.inheritance.parent import ParentContract

class ChildContract(ParentContract):
    @algopy.subroutine
    def method(self) -> bool:
        algopy.log("ChildContract.method called")
        return GrandParentContract.method(self)


import algopy

class GreatGrandParentContract(algopy.Contract):
    def approval_program(self) -> bool:
        return self.method()

    def clear_state_program(self) -> bool:
        return True

    @algopy.subroutine
    def method(self) -> bool:
        algopy.log("GrandParentContract.method called")
        return True

class GrandParentContract(GreatGrandParentContract):
    pass


import algopy

from test_cases.inheritance.grandparent import GrandParentContract

class ParentContract(GrandParentContract):
    @algopy.subroutine
    def method(self) -> bool:
        algopy.log("ParentContract.method called")
        return super().method()


import typing

from algopy import Contract, UInt64, arc4, op, subroutine

class MyContract(Contract):
    def approval_program(self) -> bool:
        z = zero()
        a = one()
        b = one()
        assert z + a + b == 2
        never_returns()
        return True

    def clear_state_program(self) -> bool:
        return True

@subroutine(inline=True)
def never_returns() -> typing.Never:
    op.err()

@subroutine(inline=True)
def one() -> UInt64:
    return zero() + 1

@subroutine(inline=True)
def zero() -> UInt64:
    return UInt64(0)

class NeverReturns(arc4.ARC4Contract):
    @arc4.abimethod()
    def err(self) -> None:
        op.err()


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class NeverReturns(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def err(
        self,
    ) -> None: ...


from algopy import (
    ARC4Contract,
    Bytes,
    arc4,
    itxn,
)

LOG_1ST_ARG_AND_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x36\x1a\x00"  # txna ApplicationArgs 0
    b"\xb0"  # log
    b"\x81\x01"  # pushint 1
)
ALWAYS_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x81\x01"  # pushint 1
)

class ArrayAccessContract(ARC4Contract):
    @arc4.abimethod
    def test_branching_array_call(self, maybe: arc4.Bool) -> None:
        if maybe:
            create_app_txn = itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                app_args=(Bytes(b"1"), Bytes(b"2")),
            ).submit()
        else:
            create_app_txn = itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                app_args=(Bytes(b"3"), Bytes(b"4"), Bytes(b"5")),
                note=b"different param set",
            ).submit()
        if maybe:
            assert create_app_txn.app_args(0) == b"1", "correct args used 1"
            assert create_app_txn.app_args(1) == b"2", "correct args used 2"
        else:
            assert create_app_txn.app_args(0) == b"3", "correct args used 1"
            assert create_app_txn.app_args(1) == b"4", "correct args used 2"
            assert create_app_txn.app_args(2) == b"5", "correct args used 3"


from algopy import (
    ARC4Contract,
    Global,
    arc4,
    itxn,
    op,
)

class CreateAndTransferContract(ARC4Contract):
    @arc4.abimethod()
    def create_and_transfer(self) -> None:
        # create
        new_asset = (
            itxn.AssetConfig(
                total=1000,
                asset_name="test",
                unit_name="TST",
                decimals=0,
                manager=op.Global.current_application_address,
                clawback=op.Global.current_application_address,
            )
            .submit()
            .created_asset
        )

        # transfer
        itxn.AssetTransfer(
            asset_sender=new_asset.creator,
            asset_receiver=Global.current_application_address,
            asset_amount=1000,
            xfer_asset=new_asset,
        ).submit()


from algopy import Application, ARC4Contract, Bytes, UInt64, arc4, itxn, log

from test_cases.inner_transactions.programs import HELLO_WORLD_APPROVAL_HEX, HELLO_WORLD_CLEAR

class Greeter(ARC4Contract):
    def __init__(self) -> None:
        self.hello_app = Application()

    @arc4.abimethod()
    def bootstrap(self) -> UInt64:
        assert not self.hello_app, "already bootstrapped"
        self.hello_app = (
            itxn.ApplicationCall(
                approval_program=Bytes.from_hex(HELLO_WORLD_APPROVAL_HEX),
                clear_state_program=HELLO_WORLD_CLEAR,
            )
            .submit()
            .created_app
        )
        return self.hello_app.id

    @arc4.abimethod()
    def log_greetings(self, name: arc4.String) -> None:
        hello_call = itxn.ApplicationCall(
            app_id=self.hello_app,
            app_args=(arc4.arc4_signature("hello(string)string"), name),
        ).submit()
        greeting = arc4.String.from_log(hello_call.last_log)
        log("HelloWorld returned: ", greeting.native)


from algopy import (
    Bytes,
    Contract,
    OnCompleteAction,
    itxn,
    op,
    subroutine,
)

LOG_1ST_ARG_AND_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x36\x1a\x00"  # txna ApplicationArgs 0
    b"\xb0"  # log
    b"\x81\x01"  # pushint 1
)
ALWAYS_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x81\x01"  # pushint 1
)

class MyContract(Contract):
    def __init__(self) -> None:
        self.name = Bytes(b"")

    def approval_program(self) -> bool:
        if op.Txn.num_app_args:
            match op.Txn.application_args(0):
                case Bytes(b"test1"):
                    self.test1()
                case Bytes(b"test2"):
                    self.test2()
                case Bytes(b"test3"):
                    self.test3()
                case Bytes(b"test4"):
                    self.test4()
        return True

    def clear_state_program(self) -> bool:
        return True

    @subroutine
    def test1(self) -> None:
        self.name = Bytes(b"AST1")
        asset_params = itxn.AssetConfig(
            total=1000,
            asset_name=self.name,
            unit_name=b"unit",
            decimals=3,
            manager=op.Global.current_application_address,
            reserve=op.Global.current_application_address,
        )
        self.name = Bytes(b"AST2")
        asset1_txn = asset_params.submit()

        asset_params.set(
            asset_name=self.name,
        )

        asset2_txn = asset_params.submit()

        assert asset1_txn.asset_name == b"AST1", "asset1_txn is correct"
        assert asset2_txn.asset_name == b"AST2", "asset2_txn is correct"

        assert asset1_txn.created_asset.name == b"AST1", "created asset 1 is correct"
        assert asset2_txn.created_asset.name == b"AST2", "created asset 2 is correct"

        app_create_params = itxn.ApplicationCall(
            approval_program=b"\x09\x81\x01",
            clear_state_program=Bytes.from_hex("098101"),
            fee=0,
        )

        asset_params.set(
            asset_name=Bytes(b"AST3"),
        )

        app_create_txn, asset3_txn = itxn.submit_txns(app_create_params, asset_params)

        assert app_create_txn.created_app, "created app"
        assert asset3_txn.asset_name == b"AST3", "asset3_txn is correct"

        app_create_params.set(note=b"3rd")
        asset_params.set(note=b"3rd")
        # unassigned result
        itxn.submit_txns(app_create_params, asset_params)

    @subroutine
    def test2(self) -> None:
        if op.Txn.num_app_args:
            args = Bytes(b"1"), Bytes(b"2")
            create_app_params = itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                app_args=args,
                on_completion=OnCompleteAction.NoOp,
                note=b"with args param set",
            )
        else:
            create_app_params = itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                app_args=(Bytes(b"3"), Bytes(b"4"), Bytes(b"5")),
                note=b"no args param set",
            )
        create_app_txn = create_app_params.submit()
        assert create_app_txn.app_args(0) == b"1", "correct args used 1"
        assert create_app_txn.app_args(1) == b"2", "correct args used 2"

        if op.Txn.num_app_args > 1:
            create_app_txn2 = itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                on_completion=OnCompleteAction.DeleteApplication,
                app_args=(Bytes(b"42"),),
            ).submit()
            assert create_app_txn2.app_args(0) == b"42", "correct args used 2"
            assert create_app_txn.note == b"with args param set"

    @subroutine
    def test3(self) -> None:
        app_p_1 = itxn.ApplicationCall(
            approval_program=LOG_1ST_ARG_AND_APPROVE,
            clear_state_program=ALWAYS_APPROVE,
            on_completion=OnCompleteAction.DeleteApplication,
            app_args=(Bytes(b"1"),),
        )

        app_p_2 = app_p_1.copy().copy()
        app_p_2.set(app_args=(Bytes(b"2"),))

        app_p_3 = app_p_1.copy()
        app_p_3.set(app_args=(Bytes(b"3"),))

        app_p_4 = app_p_1.copy()
        app_p_4.set(app_args=(Bytes(b"4"),))

        app_p_5 = app_p_1.copy()
        app_p_5.set(app_args=(Bytes(b"5"),))

        app_p_6 = app_p_1.copy()
        app_p_6.set(app_args=(Bytes(b"6"),))

        app_p_7 = app_p_1.copy()
        app_p_7.set(app_args=(Bytes(b"7"),))

        app_p_8 = app_p_1.copy()
        app_p_8.set(app_args=(Bytes(b"8"),))

        app_p_9 = app_p_1.copy()
        app_p_9.set(app_args=(Bytes(b"9"),))

        app_p_10 = app_p_1.copy()
        app_p_10.set(app_args=(Bytes(b"10"),))

        app_p_11 = app_p_1.copy()
        app_p_11.set(app_args=(Bytes(b"11"),))

        app_p_12 = app_p_1.copy()
        app_p_12.set(app_args=(Bytes(b"12"),))

        app_p_13 = app_p_1.copy()
        app_p_13.set(app_args=(Bytes(b"13"),))

        app_p_14 = app_p_1.copy()
        app_p_14.set(app_args=(Bytes(b"14"),))

        app_p_15 = app_p_1.copy()
        app_p_15.set(app_args=(Bytes(b"15"),))

        app_p_16 = app_p_1.copy()
        app_p_16.set(app_args=(Bytes(b"16"),))
        (
            app1,
            app2,
            app3,
            app4,
            app5,
            app6,
            app7,
            app8,
            app9,
            app10,
            app11,
            app12,
            app13,
            app14,
            app15,
            app16,
        ) = itxn.submit_txns(
            app_p_1,
            app_p_2,
            app_p_3,
            app_p_4,
            app_p_5,
            app_p_6,
            app_p_7,
            app_p_8,
            app_p_9,
            app_p_10,
            app_p_11,
            app_p_12,
            app_p_13,
            app_p_14,
            app_p_15,
            app_p_16,
        )

        assert app1.logs(0) == b"1"
        assert app2.logs(0) == b"2"
        assert app3.logs(0) == b"3"
        assert app4.logs(0) == b"4"
        assert app5.logs(0) == b"5"
        assert app6.logs(0) == b"6"
        assert app7.logs(0) == b"7"
        assert app8.logs(0) == b"8"
        assert app9.logs(0) == b"9"
        assert app10.logs(0) == b"10"
        assert app11.logs(0) == b"11"
        assert app12.logs(0) == b"12"
        assert app13.logs(0) == b"13"
        assert app14.logs(0) == b"14"
        assert app15.logs(0) == b"15"
        assert app16.logs(0) == b"16"

    @subroutine
    def test4(self) -> None:
        lots_of_bytes = op.bzero(2044)
        approval_1 = Bytes(ALWAYS_APPROVE)
        approval_2 = (
            Bytes(
                b"\x80"  # pushbytes
                b"\xfc\x0f"  # varuint 2044
            )
            + lots_of_bytes
            + Bytes(b"\x48")  # pop
        )
        app_p_1 = itxn.ApplicationCall(
            approval_program=(approval_1, approval_2, approval_2, approval_2),
            clear_state_program=ALWAYS_APPROVE,
            on_completion=OnCompleteAction.DeleteApplication,
            app_args=(Bytes(b"1"),),
            extra_program_pages=3,
        )
        app_1 = app_p_1.submit()
        assert app_1.extra_program_pages == 3, "extra_pages == 3"
        assert app_1.num_approval_program_pages == 2, "approval_pages == 2"
        assert (
            app_1.approval_program_pages(0) == approval_1 + approval_2 + approval_2[:-3]
        ), "expected approval page 0"
        assert (
            app_1.approval_program_pages(1) == approval_2[-3:] + approval_2
        ), "expected approval page 1"
        assert app_1.num_clear_state_program_pages == 1, "clear_state_pages == 1"
        assert app_1.clear_state_program_pages(0) == ALWAYS_APPROVE, "expected clear_state_pages"

@subroutine
def echo(v: Bytes) -> Bytes:
    return v


from algopy import (
    ARC4Contract,
    Bytes,
    OnCompleteAction,
    String,
    UInt64,
    arc4,
    itxn,
    op,
)

LOG_1ST_ARG_AND_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x36\x1a\x00"  # txna ApplicationArgs 0
    b"\xb0"  # log
    b"\x81\x01"  # pushint 1
)
ALWAYS_APPROVE = (
    b"\x09"  # pragma version 9
    b"\x81\x01"  # pushint 1
)

class FieldTupleContract(ARC4Contract):
    @arc4.abimethod
    def test_assign_tuple(self) -> None:
        create_txns = (
            itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                on_completion=OnCompleteAction.DeleteApplication,
                app_args=(
                    Bytes(b"1a"),
                    Bytes(b"2a"),
                    b"hello",
                    "world",
                    String("!"),
                    UInt64(42),
                    True,
                ),
            ),
            itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                on_completion=OnCompleteAction.DeleteApplication,
                app_args=(Bytes(b"3a"), Bytes(b"4a"), Bytes(b"5a")),
                note=b"different param set",
            ),
        )
        txn_1, txn_2 = itxn.submit_txns(create_txns[0], create_txns[1])

        assert txn_1.app_args(0) == b"1a"
        assert txn_1.app_args(1) == b"2a"
        assert txn_1.app_args(2) == b"hello"
        assert txn_1.app_args(3) == b"world"
        assert txn_1.app_args(4) == b"!"
        assert txn_1.app_args(5) == op.itob(42)
        assert txn_1.app_args(6) == op.itob(1)
        assert txn_2.app_args(0) == b"3a"
        assert txn_2.app_args(1) == b"4a"
        assert txn_2.app_args(2) == b"5a"

        create_txns[0].set(app_args=(Bytes(b"1b"), Bytes(b"2b")))
        create_txns[1].set(app_args=(Bytes(b"3b"), Bytes(b"4b"), Bytes(b"5b")))

        txn_1, txn_2 = itxn.submit_txns(create_txns[1], create_txns[0])

        assert txn_2.app_args(0) == b"1b"
        assert txn_2.app_args(1) == b"2b"
        assert txn_1.app_args(0) == b"3b"
        assert txn_1.app_args(1) == b"4b"
        assert txn_1.app_args(2) == b"5b"

        create_txns[0].set(app_args=(Bytes(b"1c"), Bytes(b"2c")))
        create_txns[1].set(app_args=(Bytes(b"3c"), Bytes(b"4c"), Bytes(b"5c")))

        txn_tuple = itxn.submit_txns(create_txns[0], create_txns[1])

        assert txn_tuple[0].app_args(0) == b"1c"
        assert txn_tuple[0].app_args(1) == b"2c"
        assert txn_tuple[1].app_args(0) == b"3c"
        assert txn_tuple[1].app_args(1) == b"4c"
        assert txn_tuple[1].app_args(2) == b"5c"

    @arc4.abimethod
    def test_assign_tuple_mixed(self) -> None:
        tuple_with_txn_fields = (
            itxn.ApplicationCall(
                approval_program=ALWAYS_APPROVE,
                clear_state_program=ALWAYS_APPROVE,
                on_completion=OnCompleteAction.DeleteApplication,
                app_args=(Bytes(b"1a"), Bytes(b"2a")),
            ),
            Bytes(b"some other value"),
        )
        result_with_txn = tuple_with_txn_fields[0].submit(), tuple_with_txn_fields[1]

        assert result_with_txn[0].app_args(0) == b"1a"
        assert result_with_txn[0].app_args(1) == b"2a"
        assert result_with_txn[1] == b"some other value"


from algopy import (
    Bytes,
    Contract,
    OnCompleteAction,
    UInt64,
    itxn,
    log,
    op,
    urange,
)

from test_cases.inner_transactions import programs

class MyContract(Contract, name="itxn_loop"):
    def clear_state_program(self) -> bool:
        return True

    def approval_program(self) -> bool:
        note = Bytes(b"ABCDE")
        app_params = itxn.ApplicationCall(
            approval_program=programs.ALWAYS_APPROVE,
            clear_state_program=programs.ALWAYS_APPROVE,
            on_completion=OnCompleteAction.DeleteApplication,
            note=b"",
        )
        for i in urange(4):
            i_note = op.extract(note, 0, i)
            match i:
                case UInt64(1):
                    app_params.set(note=i_note, app_args=(Bytes(b"1"),))
                case UInt64(2):
                    app_params.set(note=i_note, app_args=(Bytes(b"2"), Bytes(b"1")))
                case UInt64(3):
                    app_params.set(
                        note=i_note,
                        app_args=(Bytes(b"3"), Bytes(b"2"), Bytes(b"1")),
                    )
            app_txn = app_params.submit()
            log(app_txn.note)
            log(app_txn.num_app_args)

        return True


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class ArrayAccessContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def test_branching_array_call(
        self,
        maybe: algopy.arc4.Bool,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class CreateAndTransferContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def create_and_transfer(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class FieldTupleContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def test_assign_tuple(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_assign_tuple_mixed(
        self,
    ) -> None: ...


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Greeter(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def bootstrap(
        self,
    ) -> algopy.arc4.UIntN[typing.Literal[64]]: ...

    @algopy.arc4.abimethod
    def log_greetings(
        self,
        name: algopy.arc4.String,
    ) -> None: ...


from algopy import (
    ARC4Contract,
    Bytes,
    Txn,
    arc4,
    itxn,
    subroutine,
)

class Contract(ARC4Contract):
    @arc4.abimethod
    def test_itxn_slice(self) -> None:
        acfg = itxn.AssetConfig(
            unit_name="TST",
            asset_name="TEST",
            note="acfg",
            total=1,
        )
        pay1 = itxn.Payment(receiver=Txn.sender, amount=0, note="pay1")
        pay2 = pay1.copy()
        pay2.set(note="pay2")
        pay3 = pay2.copy()
        pay3.set(note="pay3")
        sliced_txns = itxn.submit_txns(pay1, acfg, pay2, pay3)[1:-1]
        assert sliced_txns[0].note == b"acfg"
        assert sliced_txns[1].note == b"pay2"

    @arc4.abimethod
    def test_itxn_nested(self) -> None:
        acfg = itxn.AssetConfig(
            unit_name="TST",
            asset_name="TEST",
            note="acfg",
            total=1,
        )
        pay1 = itxn.Payment(receiver=Txn.sender, amount=0, note="pay1")
        pay2 = pay1.copy()
        pay2.set(note="pay2")
        pay3 = pay2.copy()
        pay3.set(note="pay3")
        nested_tuple = (
            echo(Bytes(b"hi")),
            itxn.submit_txns(pay1, acfg, pay2, pay3)[1:-1],
            echo(Bytes(b"there")),
        )
        assert nested_tuple[0] == b"hi"
        assert nested_tuple[1][0].note == b"acfg"
        assert nested_tuple[1][1].note == b"pay2"
        assert nested_tuple[2] == b"there"
        nested_tuple_copy = nested_tuple

        acfg.set(note="acfg2")
        pay2.set(note="pay4")
        pay3.set(note="pay5")

        if echo(Bytes(b"maybe")) == b"maybe":
            nested_tuple = (
                echo(Bytes(b"hi2")),
                itxn.submit_txns(pay1, acfg, pay3)[1:],
                echo(Bytes(b"there2")),
            )
        assert nested_tuple[0] == b"hi2"
        assert nested_tuple[1][0].note == b"acfg2"
        assert nested_tuple[1][1].note == b"pay5"
        assert nested_tuple[2] == b"there2"

        mish_mash = nested_tuple_copy[1][0], nested_tuple_copy[1][1], nested_tuple[1]

        assert mish_mash[0].note == b"acfg"
        assert mish_mash[1].note == b"pay2"
        assert mish_mash[2][0].note == b"acfg2"
        assert mish_mash[2][1].note == b"pay5"

@subroutine
def echo(value: Bytes) -> Bytes:
    return value


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class Contract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def test_itxn_slice(
        self,
    ) -> None: ...

    @algopy.arc4.abimethod
    def test_itxn_nested(
        self,
    ) -> None: ...


from algopy import (
    Bytes,
    Contract,
    OnCompleteAction,
    TransactionType,
    UInt64,
)
from algopy.op import (
    GITxn,
    GTxn,
    ITxn,
    ITxnCreate,
    Txn,
)

class ImmediateVariants(Contract):
    def approval_program(self) -> bool:
        num_app_args = Txn.num_app_args
        assert GTxn.num_app_args(0) == num_app_args
        assert GTxn.num_app_args(UInt64(0)) == num_app_args
        first_arg = Txn.application_args(0)
        assert Txn.application_args(UInt64(0)) == first_arg
        assert GTxn.application_args(0, 0) == first_arg
        assert GTxn.application_args(0, UInt64(0)) == first_arg
        assert GTxn.application_args(UInt64(0), 0) == first_arg
        assert GTxn.application_args(UInt64(0), UInt64(0)) == first_arg

        ITxnCreate.begin()
        ITxnCreate.set_type_enum(TransactionType.ApplicationCall)
        ITxnCreate.set_on_completion(OnCompleteAction.DeleteApplication)
        ITxnCreate.set_approval_program(Bytes.from_hex("068101"))
        ITxnCreate.set_clear_state_program(Bytes.from_hex("068101"))
        ITxnCreate.set_fee(0)  # cover fee with outer txn
        ITxnCreate.set_fee(UInt64(0))  # cover fee with outer txn
        ITxnCreate.set_application_args(first_arg)
        second_arg = first_arg + b"2"
        ITxnCreate.set_application_args(second_arg)
        ITxnCreate.submit()

        assert ITxn.num_app_args() == 2
        assert ITxn.application_args(0) == first_arg
        assert ITxn.application_args(UInt64(1)) == second_arg

        assert GITxn.num_app_args(0) == 2
        assert GITxn.application_args(0, UInt64(0)) == first_arg
        assert GITxn.application_args(0, UInt64(1)) == second_arg
        assert GITxn.application_args(0, 0) == first_arg
        assert GITxn.application_args(0, 1) == second_arg

        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import Contract, GlobalState, UInt64, op

class Overloaded(Contract):
    def __init__(self) -> None:
        self.key = GlobalState(UInt64(0))

    def approval_program(self) -> bool:
        assert op.AppGlobal.get_uint64(b"key") == op.AppGlobal.get_uint64(b"key")
        assert self.key.maybe()[0] == self.key.maybe()[0]
        assert op.setbit_uint64(0, 0, 1) == op.setbit_uint64(0, 0, 1)
        assert op.select_uint64(0, 1, True) == op.select_uint64(1, 0, False)
        assert op.getbit(op.setbit_uint64(2**64 - 1, 3, 0), 3) == 0
        assert op.getbit(op.setbit_uint64(123, 4, 1), 4) == 1
        return True

    def clear_state_program(self) -> bool:
        return True


import abc

from algopy import Bytes, Contract, UInt64, log, subroutine

class IterationTestBase(Contract, abc.ABC):
    def approval_program(self) -> bool:
        log("test_forwards")
        self.test_forwards()
        log("test_reversed")
        self.test_reversed()
        log("test_forwards_with_forwards_index")
        self.test_forwards_with_forwards_index()
        log("test_forwards_with_reverse_index")
        self.test_forwards_with_reverse_index()
        log("test_reverse_with_forwards_index")
        self.test_reverse_with_forwards_index()
        log("test_reverse_with_reverse_index")
        self.test_reverse_with_reverse_index()
        log("test_empty")
        self.test_empty()
        log("test_break")
        self.test_break()
        log("test_tuple_target")
        self.test_tuple_target()
        return True

    def clear_state_program(self) -> bool:
        return True

    @subroutine
    def _log_with_index(self, idx: UInt64, value: Bytes) -> None:
        digits = Bytes(b"0123456789")
        log(digits[idx], value, sep="=")

    @subroutine
    @abc.abstractmethod
    def test_forwards(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_reversed(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_forwards_with_forwards_index(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_forwards_with_reverse_index(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_reverse_with_forwards_index(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_reverse_with_reverse_index(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_empty(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_break(self) -> None: ...

    @subroutine
    @abc.abstractmethod
    def test_tuple_target(self) -> None: ...


import typing

from algopy import Bytes, log, subroutine, uenumerate

from test_cases.iteration.base import IterationTestBase

class IndexableIterationTest(IterationTestBase):
    @typing.override
    @subroutine
    def test_forwards(self) -> None:
        for i in Bytes(b"abc"):
            log(i)

    @typing.override
    @subroutine
    def test_reversed(self) -> None:
        for i in reversed(Bytes(b"abc")):
            log(i)

    @typing.override
    @subroutine
    def test_forwards_with_forwards_index(self) -> None:
        for idx, i in uenumerate(Bytes(b"abc")):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_forwards_with_reverse_index(self) -> None:
        for idx, i in reversed(uenumerate(reversed(Bytes(b"abc")))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_forwards_index(self) -> None:
        for idx, i in uenumerate(reversed(Bytes(b"abc"))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_reverse_index(self) -> None:
        for idx, i in reversed(uenumerate(Bytes(b"abc"))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_empty(self) -> None:
        for i in Bytes():
            log(i)
        for i in reversed(Bytes()):
            log(i)
        for idx, i in uenumerate(Bytes()):
            self._log_with_index(idx, i)
        for idx, i in reversed(uenumerate(reversed(Bytes()))):
            self._log_with_index(idx, i)
        for idx, i in uenumerate(reversed(Bytes())):
            self._log_with_index(idx, i)
        for idx, i in reversed(uenumerate(Bytes())):
            self._log_with_index(idx, i)

    @typing.override
    @subroutine
    def test_break(self) -> None:
        for b in Bytes(b"abc"):
            log(b)
            break

    @typing.override
    @subroutine
    def test_tuple_target(self) -> None:
        for tup in uenumerate(Bytes(b"t")):
            self._log_with_index(tup[0], tup[1])


import typing

from algopy import Bytes, log, subroutine, uenumerate

from test_cases.iteration.base import IterationTestBase

class TupleIterationTest(IterationTestBase):
    @typing.override
    @subroutine
    def test_forwards(self) -> None:
        for i in (Bytes(b"a"), Bytes(b"b"), Bytes(b"c")):
            log(i)

    @typing.override
    @subroutine
    def test_reversed(self) -> None:
        for i in reversed((Bytes(b"a"), Bytes(b"b"), Bytes(b"c"))):
            log(i)

    @typing.override
    @subroutine
    def test_forwards_with_forwards_index(self) -> None:
        for idx, i in uenumerate((Bytes(b"a"), Bytes(b"b"), Bytes(b"c"))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_forwards_with_reverse_index(self) -> None:
        for idx, i in reversed(uenumerate(reversed((Bytes(b"a"), Bytes(b"b"), Bytes(b"c"))))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_forwards_index(self) -> None:
        for idx, i in uenumerate(reversed((Bytes(b"a"), Bytes(b"b"), Bytes(b"c")))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_reverse_index(self) -> None:
        for idx, i in reversed(uenumerate((Bytes(b"a"), Bytes(b"b"), Bytes(b"c")))):
            self._log_with_index(idx, i)
            idx += 1

    @typing.override
    @subroutine
    def test_empty(self) -> None:
        """empty tuples not supported (yet)"""
        # i: Bytes
        # for i in ():
        #     log(i)
        # for i in reversed(()):
        #     log(i)
        # for idx, i in uenumerate(()):
        #     log(idx)
        #     log(i)
        # for idx, i in reversed(uenumerate(reversed(()))):
        #     log(idx)
        #     log(i)
        # for idx, i in uenumerate(reversed(())):
        #     log(idx)
        #     log(i)
        # for idx, i in reversed(uenumerate(())):
        #     log(idx)
        #     log(i)

    @typing.override
    @subroutine
    def test_break(self) -> None:
        for x in (Bytes(b"a"), Bytes(b"b"), Bytes(b"c")):
            log(x)
            break

    @typing.override
    @subroutine
    def test_tuple_target(self) -> None:
        for tup in uenumerate((Bytes(b"t"),)):
            self._log_with_index(tup[0], tup[1])


import typing

from algopy import Bytes, log, subroutine, uenumerate, urange

from test_cases.iteration.base import IterationTestBase

class URangeIterationTest(IterationTestBase):
    @typing.override
    @subroutine
    def test_forwards(self) -> None:
        values = Bytes(b" a b c")
        for i in urange(1, 7, 2):
            log(values[i])
            i += 1

    @typing.override
    @subroutine
    def test_reversed(self) -> None:
        values = Bytes(b" a b c")
        for i in reversed(urange(1, 7, 2)):
            log(values[i])
            i += 1

    @typing.override
    @subroutine
    def test_forwards_with_forwards_index(self) -> None:
        values = Bytes(b" a b c")
        for idx, i in uenumerate(urange(1, 7, 2)):
            self._log_with_index(idx, values[i])
            i += 1
            idx += 1

    @typing.override
    @subroutine
    def test_forwards_with_reverse_index(self) -> None:
        values = Bytes(b" a b c")
        for idx, i in reversed(uenumerate(reversed(urange(1, 7, 2)))):
            self._log_with_index(idx, values[i])
            i += 1
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_forwards_index(self) -> None:
        values = Bytes(b" a b c")
        for idx, i in uenumerate(reversed(urange(1, 7, 2))):
            self._log_with_index(idx, values[i])
            i += 1
            idx += 1

    @typing.override
    @subroutine
    def test_reverse_with_reverse_index(self) -> None:
        values = Bytes(b" a b c")
        for idx, i in reversed(uenumerate(urange(1, 7, 2))):
            self._log_with_index(idx, values[i])
            i += 1
            idx += 1

    @typing.override
    @subroutine
    def test_empty(self) -> None:
        for i in urange(0):
            log(i)
        for i in reversed(urange(0)):
            log(i)
        for idx, i in uenumerate(urange(0)):
            log(idx, i)
        for idx, i in reversed(uenumerate(reversed(urange(0)))):
            log(idx, i)
        for idx, i in uenumerate(reversed(urange(0))):
            log(idx, i)
        for idx, i in reversed(uenumerate(urange(0))):
            log(idx, i)

    @typing.override
    @subroutine
    def test_break(self) -> None:
        values = Bytes(b" a b c")
        for i in urange(1, 7, 2):
            log(values[i])
            break

    @typing.override
    @subroutine
    def test_tuple_target(self) -> None:
        values = Bytes(b"t")
        for tup in uenumerate(urange(1)):
            self._log_with_index(tup[0], values[tup[1]])


from algopy import Contract, UInt64

class MyContract(Contract):
    """My contract"""

    def approval_program(self) -> UInt64:
        a = UInt64(75)
        c = UInt64(77)
        b = a + c
        a = b + 5
        c = b + a

        return c

    def clear_state_program(self) -> UInt64:
        return UInt64(1)


# ruff: noqa: F403, F405
from algopy import *  # note: star import here to explicitly test that

class MyContract(Contract):
    """My contract"""

    def approval_program(self) -> UInt64:
        a = UInt64(1)
        sum_of_evens = UInt64(0)
        product_of_odds = UInt64(0)
        while a < 100:
            if a % 5 == 0:
                continue
            if not a % 21:
                break
            if a % 2 == 0:
                sum_of_evens += a
            else:  # noqa: PLR5501
                if product_of_odds == 0:
                    product_of_odds = a
                else:
                    product_of_odds *= a
            a += 1
        return product_of_odds - sum_of_evens

    def clear_state_program(self) -> UInt64:
        sum_of_squares = UInt64(0)
        for i in urange(1, 100):
            square_root = op.sqrt(i)
            if square_root * square_root == i:
                sum_of_squares += i
            if sum_of_squares > 200:
                break
        return sum_of_squares


# ruff: noqa
from algopy import *

@subroutine
def unary_str() -> None:
    assert not ""
    assert not (not "abc")

@subroutine
def compare_str() -> None:
    assert not ("a" == "b")  # type: ignore[comparison-overlap]
    assert "a" != "b"  # type: ignore[comparison-overlap]
    assert "a" < "b"
    assert "a" <= "b"
    assert not ("a" > "b")
    assert not ("a" >= "b")
    assert "a" not in "b"
    assert not ("a" in "b")
    assert "a" in "abc"

    b = String("b")
    assert not ("a" == b)
    assert "a" != b
    assert "a" not in b
    assert not ("a" in b)
    assert "a" in String("abc")

@subroutine
def binary_op_str() -> None:
    assert "a" and "b"
    assert "a" or "b"
    assert "" or "b"
    assert not ("a" and "")
    assert not ("" or "")
    assert ("a" + "") == "a"

@subroutine
def unary_bytes() -> None:
    assert not b""
    assert not (not b"abc")

@subroutine
def unary_int() -> None:
    assert not 0
    assert not (not 1)
    assert -1 == (0 - 1)
    assert +1 == (0 + 1)
    assert ~0 == -1

@subroutine
def compare_int() -> None:
    assert not (0 == 1)  # type: ignore[comparison-overlap]
    assert 0 != 1  # type: ignore[comparison-overlap]
    assert 0 < 1
    assert 0 <= 1
    assert not (0 > 1)
    assert not (0 >= 1)

    one = UInt64(1)
    assert not (0 == one)
    assert 0 != one
    assert 0 < one
    assert 0 <= one
    assert not (0 > one)
    assert not (0 >= one)

@subroutine
def unary_bool() -> None:
    assert not False
    assert not (not True)
    assert -True == -1
    assert +False == 0
    assert ~True == -2

@subroutine
def tuples() -> None:
    assert (97, UInt64(98), 99) == tuple(b"abc")  # type: ignore[comparison-overlap]
    assert ("a", "b", "c") == tuple("abc")
    assert (97, UInt64(98), 99) == tuple(
        arc4.StaticArray(arc4.UInt64(97), arc4.UInt64(98), arc4.UInt64(99))
    )  # type: ignore[comparison-overlap]
    assert (1, 2) == tuple((1, 2))

class LiteralFolding(Contract):
    def approval_program(self) -> bool:
        unary_str()
        compare_str()
        binary_op_str()
        unary_bytes()
        unary_int()
        compare_int()
        unary_bool()
        tuples()
        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import BigUInt, Bytes, Contract, log, op

class MyContract(Contract):
    def approval_program(self) -> bool:
        log(0)
        log(b"1")
        log("2")
        log(op.Txn.num_app_args + 3)
        log(Bytes(b"4") if op.Txn.num_app_args else Bytes())
        log(
            b"5",
            6,
            op.Txn.num_app_args + 7,
            BigUInt(8),
            Bytes(b"9") if op.Txn.num_app_args else Bytes(),
        )
        log(
            b"5",
            6,
            op.Txn.num_app_args + 7,
            BigUInt(8),
            Bytes(b"9") if op.Txn.num_app_args else Bytes(),
            sep=b"_",
        )
        log(
            b"5",
            6,
            op.Txn.num_app_args + 7,
            BigUInt(8),
            Bytes(b"9") if op.Txn.num_app_args else Bytes(),
            sep="_",
        )
        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import logicsig

@logicsig(name="always_allow")
def some_sig() -> bool:
    return True


from algopy import Account, Asset, TemplateVar, UInt64, gtxn, logicsig, subroutine
from algopy.op import Global

@logicsig
def pre_approved_sale() -> bool:
    """
    Allows for pre-authorising the sale of an asset for a pre-determined price, but to an
    undetermined buyer.

    The checks here are not meant to be exhaustive
    """
    pay_txn = gtxn.PaymentTransaction(0)
    asset_txn = gtxn.AssetTransferTransaction(1)
    assert_correct_payment(pay_txn)
    assert_correct_asset(asset_txn)
    assert pay_txn.sender == asset_txn.asset_receiver
    assert Global.group_size == 2
    return True

@subroutine
def assert_correct_payment(txn: gtxn.PaymentTransaction) -> None:
    assert txn.receiver == TemplateVar[Account]("SELLER") and (
        txn.amount == TemplateVar[UInt64]("PRICE")
    )

@subroutine
def assert_correct_asset(txn: gtxn.AssetTransferTransaction) -> None:
    assert (
        txn.asset_amount == 1
        and txn.sender == TemplateVar[Account]("SELLER")
        and txn.xfer_asset == TemplateVar[Asset]("ASSET_ID")
        and txn.asset_close_to == Global.zero_address
        and txn.rekey_to == Global.zero_address
    )


# ruff: noqa: F403, F405
from algopy import *

class LoopElseContract(Contract):
    def approval_program(self) -> bool:
        test_empty_loop(UInt64(0))

        arg_idx = UInt64(0)
        while arg_idx < Txn.num_app_args:
            for i in urange(10):
                if i == 0:
                    break
                assert False, "unreachable"
            if Txn.application_args(arg_idx) == b"while_secret":
                secret_index = arg_idx
                for account_index in urange(Txn.num_accounts):
                    account = Txn.accounts(account_index)
                    if account == Global.zero_address:
                        break
                else:
                    assert False, "access denied, missing secret account"
                break
            arg_idx += 1
        else:
            assert False, "access denied, missing secret argument"
        log(
            "found secret argument at idx=",
            op.itob(secret_index + 48)[-1],
            " and secret account at idx=",
            op.itob(account_index + 48)[-1],
        )
        return True

    def clear_state_program(self) -> bool:
        return True

@subroutine
def test_empty_loop(count: UInt64) -> None:
    assert count == 0
    result = UInt64(0)
    for i in reversed(urange(count)):
        if i == 0:
            break
    else:
        result += 1
    assert result == 1


import algopy

class MyContract(algopy.Contract):
    def approval_program(self) -> bool:
        self.case_one = algopy.UInt64(1)
        self.case_two = algopy.UInt64(2)
        self.match_uint64()
        self.match_biguint()
        self.match_bytes()
        self.match_address()
        self.match_attributes()
        self.match_bools()
        return True

    @algopy.subroutine
    def match_uint64(self) -> None:
        n = algopy.op.Txn.num_app_args
        match n:
            case 0:
                hello = algopy.Bytes(b"Hello")
                algopy.log(hello)
            case algopy.UInt64(10):
                hello = algopy.Bytes(b"Hello There")
                algopy.log(hello)

    @algopy.subroutine
    def match_bytes(self) -> None:
        n = algopy.op.Txn.application_args(0)
        match n:
            case algopy.Bytes(b""):
                hello = algopy.Bytes(b"Hello bytes")
                algopy.log(hello)
            case algopy.Bytes(b"10"):
                hello = algopy.Bytes(b"Hello There bytes")
                algopy.log(hello)

    @algopy.subroutine
    def match_biguint(self) -> None:
        n = algopy.op.Txn.num_app_args * algopy.BigUInt(10)
        match n:
            case algopy.BigUInt(0):
                hello = algopy.Bytes(b"Hello biguint")
                algopy.log(hello)
            case algopy.BigUInt(10):
                hello = algopy.Bytes(b"Hello There biguint")
                algopy.log(hello)

    @algopy.subroutine
    def match_address(self) -> None:
        n = algopy.op.Txn.sender
        match n:
            case algopy.Account("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ"):
                hello = algopy.Bytes(b"Hello address")
                algopy.log(hello)
            case algopy.Account("VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA"):
                hello = algopy.Bytes(b"Hello There address")
                algopy.log(hello)

    @algopy.subroutine
    def match_attributes(self) -> None:
        n = algopy.op.Txn.num_app_args
        match n:
            case self.case_one:
                hello = algopy.Bytes(b"Hello one")
                algopy.log(hello)
            case self.case_two:
                hello = algopy.Bytes(b"Hello two")
                algopy.log(hello)
            case _:
                hello = algopy.Bytes(b"Hello default")
                algopy.log(hello)

    @algopy.subroutine
    def match_bools(self) -> None:
        n = algopy.op.Txn.num_app_args > 0
        match n:
            case True:
                hello = algopy.Bytes(b"Hello True")
                algopy.log(hello)
            case False:
                hello = algopy.Bytes(b"Hello False")
                algopy.log(hello)

    def clear_state_program(self) -> bool:
        return True


import algopy

class Counter(algopy.Contract):
    def __init__(self) -> None:
        self.counter = algopy.UInt64(0)

    def approval_program(self) -> bool:
        match algopy.Txn.on_completion:
            case algopy.OnCompleteAction.NoOp:
                self.increment_counter()
                return True
            case _:
                # reject all OnCompletionAction's other than NoOp
                return False

    def clear_state_program(self) -> bool:
        return True

    @algopy.subroutine
    def increment_counter(self) -> None:
        self.counter += 1


import typing as t

__all__ = [
    "BANNED",
]
__all__ += [
    "EXT_ZERO",
    "EXT_ONE",
]

BANNED = HACKER = "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA"
EXT_ZERO: t.Final = 0
EXT_ONE = 1


USE_CONSTANTS2 = "USE_CONSTANTS2"
UNUSED_CONSTANT2 = "UNUSED"


__all__ = [
    "USED_CONSTANTS3",
]

USED_CONSTANTS3 = "USED_CONSTANTS3"
UNUSED_CONSTANT3 = "UNUSED"
USED_UNLISTED_CONSTANT3 = "USED_UNLISTED_CONSTANT3"


from test_cases.module_consts import constants3 as constants3  # noqa: PLC0414


# ruff: noqa: T201, F403, F405, PLR0133

import typing

from algopy import Contract, Txn

import test_cases.module_consts.constants as consts
from test_cases.module_consts import constants, constants4
from test_cases.module_consts.constants import BANNED, EXT_ONE, EXT_ZERO
from test_cases.module_consts.constants2 import *
from test_cases.module_consts.constants3 import *

T = True and (1 == 1)

if typing.TYPE_CHECKING:
    TruthyType = bool | typing.Literal[0, 1]
    _T = typing.TypeVar("_T")

    def identity(x: _T) -> _T:
        return x

elif False:
    print("HOW DO I GET HERE")
elif 0 > 1:
    print("please sir can I have some more consistency")
else:
    SNEAKY_CONST = "so sneak"

NO = b'"no'
NOO = b"no'"
ZERO = ZER0 = 0  # lol
ZEROS = f"{ZERO:.3f}"
ONE = ZERO + (ZER0 * 2) + (2 - 1) // EXT_ONE
YES = "y" + "es"
AAAAAAAAAA = EXT_ZERO or "a" * 48
MAYBE = f"""{YES}
    or
        nooo
"""
BANNED_F = f"{BANNED!r}"
BANNED_F2 = f"{BANNED:2s}"
F_CODE = f"{'lol' if EXT_ONE else 'no'}"
MAYBE1 = f"{MAYBE}"
MAYBE2 = f'{MAYBE}"'
MAYBE3 = f"""{MAYBE}"""
MAYBE4 = f'''{MAYBE}"'''
MAYBE6 = rf"{MAYBE}"
MAYBE8 = rf'{MAYBE}"'
# fmt: off
MAYBE5 = fr"{MAYBE}"
MAYBE7 = fr'{MAYBE}"'
# fmt: on
MAYBE_MORE = f"{MAYBE} \
 maybe not"
TWO = consts.EXT_ONE + constants.EXT_ONE + consts.EXT_ZERO
EXT_NAME_REF_F_STR = f"{consts.BANNED}"
YES_TWICE_AND_NO = 2 * f"2{YES}" + f"1{NO!r}"
SHOULD_BE_1 = EXT_ONE if not typing.TYPE_CHECKING else EXT_ZERO
SHOULD_BE_0 = EXT_ONE if False else EXT_ZERO

STAR1 = USE_CONSTANTS2
STAR2 = USED_CONSTANTS3
# STAR3: str = USED_UNLISTED_CONSTANT3  # type: ignore[name-defined]
FOOOO = constants4.constants3.USED_CONSTANTS3

JOINED = ", ".join(["1", ZEROS])

yes_votes = 42_572_654
no_votes = 43_132_495
percentage = (100 * yes_votes) // (yes_votes + no_votes)
FORMATTED = f"{yes_votes:-9} YES votes  {percentage:2.2%}"

class MyContract(Contract):
    def approval_program(self) -> bool:
        assert Txn.num_app_args == 0, MAYBE_MORE
        assert Txn.sender != consts.HACKER, consts.HACKER
        return True

    def clear_state_program(self) -> bool:
        return True


from algopy import Bytes, UInt64, op, subroutine, urange

ONE = 1
HELLO = "👋".encode()

@subroutine
def three() -> UInt64:
    a = UInt64(1) + ONE
    b = a + 1
    return b

@subroutine
def hello_world() -> Bytes:
    hello = Bytes(HELLO)
    comma = Bytes.from_base64("4aCI")
    world = Bytes(b" world")
    return hello + comma + world

@subroutine
def safe_add(x: UInt64, y: UInt64) -> tuple[UInt64, bool]:
    """Add two UInt64 and return the result as well as whether it overflowed or not"""
    hi, lo = op.addw(x, y)
    did_overflow = hi > 0
    return lo, did_overflow

@subroutine
def safe_six() -> tuple[UInt64, bool]:
    """lollll"""
    return safe_add(three(), three())

@subroutine
def itoa(i: UInt64) -> Bytes:
    """Itoa converts an integer to the ascii byte string it represents"""
    digits = Bytes(b"0123456789")
    radix = digits.length
    if i < radix:
        return digits[i]
    return itoa(i // radix) + digits[i % radix]

@subroutine
def itoa_loop(num: UInt64) -> Bytes:
    """Itoa converts an integer to the ascii byte string it represents"""
    digits = Bytes(b"0123456789")
    result = Bytes(b"")
    while num >= 10:
        result = digits[num % 10] + result
        num //= 10
    result = digits[num] + result
    return result

@subroutine
def inefficient_multiply(a: UInt64, b: UInt64) -> UInt64:
    if a == 0 or b == 0:
        return a
    if a < b:
        smaller = a
        bigger = b
    else:
        smaller = b
        bigger = a
    result = UInt64(0)
    for _i in urange(smaller):
        result += bigger
    return result

@subroutine
def test_and_uint64() -> UInt64:
    return UInt64(1) and UInt64(2)


import typing

from algopy import BigUInt, Bytes, String, Txn, UInt64, arc4, subroutine

class TestTuple(typing.NamedTuple):
    """This is a test tuple"""

    a: UInt64
    b: BigUInt
    c: String
    d: Bytes

class NamedTuplesContract(arc4.ARC4Contract):
    @arc4.abimethod()
    def build_tuple(self, a: UInt64, b: BigUInt, c: String, d: Bytes) -> TestTuple:
        t1 = self.build_tuple_by_name(a, b, c, d)
        t2 = self.build_tuple_by_position(a, b, c, d)
        assert t1 == t2
        return t1

    @subroutine
    def build_tuple_by_name(self, a: UInt64, b: BigUInt, c: String, d: Bytes) -> TestTuple:
        return TestTuple(a=a, b=b, c=c, d=d)

    @subroutine
    def build_tuple_by_position(self, a: UInt64, b: BigUInt, c: String, d: Bytes) -> TestTuple:
        return TestTuple(a, b, c, d)

    @arc4.abimethod()
    def test_tuple(self, value: TestTuple) -> None:
        assert value.a < 1000
        assert value.b < 2**65
        assert value.c.bytes.length > 1
        assert value.d == Txn.sender.bytes


# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import algopy

class TestTuple(algopy.arc4.Struct):
    a: algopy.arc4.UIntN[typing.Literal[64]]
    b: algopy.arc4.BigUIntN[typing.Literal[512]]
    c: algopy.arc4.String
    d: algopy.arc4.DynamicBytes

class NamedTuplesContract(algopy.arc4.ARC4Client, typing.Protocol):
    @algopy.arc4.abimethod
    def build_tuple(
        self,
        a: algopy.arc4.UIntN[typing.Literal[64]],
        b: algopy.arc4.BigUIntN[typing.Literal[512]],
        c: algopy.arc4.String,
        d: algopy.arc4.DynamicBytes,
    ) -> TestTuple: ...

    @algopy.arc4.abimethod
    def test_tuple(
        self,
        value: TestTuple,
    ) -> None: ...