Repository: algorand/pyteal (language: python)

Issue:
Add overriding name to method spec so it comes through in contract json
Sometimes we want to have the same named method with different arguments, this should be present in the contract spec not just the handler method signature.

Its already the case that the method signature will get its name overridden but if we don't pass through the overriding name to the `contract.json` output, calls to the contract will fail with an invalid signature since they don't match.


Discussion / hints:

Fix patch:
diff --git a/docs/abi.rst b/docs/abi.rst
index fed0509ff..63d65147c 100644
--- a/docs/abi.rst
+++ b/docs/abi.rst
@@ -682,6 +682,21 @@ Notice that even though the original :code:`get_account_status` function returns
 
 The only exception to this transformation is if the subroutine has no return value. Without a return value, a :code:`ComputedValue` is unnecessary and the subroutine will still return an :code:`Expr` to the caller. In this case, the :code:`@ABIReturnSubroutine` decorator acts identically the :code:`@Subroutine` decorator.
 
+The name of the subroutine constructed by the :code:`@ABIReturnSubroutine` decorator is by default the function name. In order to override the default subroutine name, the decorator :any:`ABIReturnSubroutine.name_override <ABIReturnSubroutine.name_override>` is introduced to construct a subroutine with its name overridden. An example is below:
+
+.. code-block:: python
+
+    from pyteal import *
+
+    @ABIReturnSubroutine.name_override("increment")
+    def add_by_one(prev: abi.Uint32, *, output: abi.Uint32) -> Expr:
+        return output.set(prev.get() + Int(1))
+
+    # NOTE! In this case, the `ABIReturnSubroutine` is initialized with a name "increment"
+    #       overriding its original name "add_by_one"
+    assert add_by_one.method_spec().dictify()["name"] == "increment"
+
+
 Creating an ARC-4 Program
 ----------------------------------------------------
 


Test patch:
diff --git a/pyteal/ast/subroutine_test.py b/pyteal/ast/subroutine_test.py
index 70fd9ccd3..28b0f0aa9 100644
--- a/pyteal/ast/subroutine_test.py
+++ b/pyteal/ast/subroutine_test.py
@@ -1475,3 +1475,10 @@ def abi_meth(a: pt.abi.Uint64, b: pt.abi.Uint64, *, output: pt.abi.Uint64):
 
     mspec = ABIReturnSubroutine(abi_meth, overriding_name="add").method_spec().dictify()
     assert mspec["name"] == "add"
+
+    @ABIReturnSubroutine.name_override("overriden_add")
+    def abi_meth_2(a: pt.abi.Uint64, b: pt.abi.Uint64, *, output: pt.abi.Uint64):
+        return output.set(a.get() + b.get())
+
+    mspec = abi_meth_2.method_spec().dictify()
+    assert mspec["name"] == "overriden_add"