Skip to content

Commit

Permalink
ExecuteMethodCall typecheck (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Oct 14, 2022
1 parent d738ceb commit 1a1c93f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

## Changed
* Subroutines that take ABI type of Transaction now allow any Transaction type to be passed. ([#531](https://github.com/algorand/pyteal/pull/531))
* Relaxing exact type check in `InnerTxnFieldExpr.MethodCall` by applying `abi.type_spec_is_assignable_to`. ([#561](https://github.com/algorand/pyteal/pull/561))

# 0.18.1

Expand Down
2 changes: 2 additions & 0 deletions pyteal/ast/abi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
make,
size_of,
type_spec_from_annotation,
type_spec_from_algosdk,
type_specs_from_signature,
contains_type_spec,
type_spec_is_assignable_to,
Expand Down Expand Up @@ -162,6 +163,7 @@
"KeyRegisterTransactionTypeSpec",
"TransactionTypeSpecs",
"type_spec_from_annotation",
"type_spec_from_algosdk",
"type_specs_from_signature",
"make",
"size_of",
Expand Down
11 changes: 7 additions & 4 deletions pyteal/ast/itxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ def MethodCall(

txntype = cast(EnumInt, arg[TxnField.type_enum]).name
# If the arg is an unspecified transaction, no need to check the type_enum
if not type(
method_arg_ts
) is abi.TransactionTypeSpec and txntype != str(method_arg_ts):

if not abi.type_spec_is_assignable_to(
abi.type_spec_from_algosdk(txntype), method_arg_ts
):
raise TealInputError(
f"Expected Transaction at arg {idx} to be {method_arg_ts}, got {txntype}"
)
Expand Down Expand Up @@ -459,7 +460,9 @@ def MethodCall(
require_type(arg, TealType.bytes)
app_args.append(arg)
elif isinstance(arg, abi.BaseType):
if arg.type_spec() != method_arg_ts:
if not abi.type_spec_is_assignable_to(
arg.type_spec(), method_arg_ts
):
raise TealTypeError(arg.type_spec(), method_arg_ts)
app_args.append(arg.encode())
else:
Expand Down
21 changes: 21 additions & 0 deletions pyteal/ast/itxn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ def test_InnerTxnBuilder_Execute():
),
None,
),
(
pt.Int(1),
"query(byte[],uint64)void",
[t6_1 := pt.abi.DynamicBytes(), t6_2 := pt.abi.Uint64()],
{TxnField.fee: pt.Int(0)},
pt.Seq(
pt.InnerTxnBuilder.SetFields(
{
pt.TxnField.type_enum: TxnType.ApplicationCall,
pt.TxnField.application_id: pt.Int(1),
pt.TxnField.application_args: [
pt.MethodSignature("query(byte[],uint64)void"),
t6_1.encode(),
t6_2.encode(),
],
pt.TxnField.fee: pt.Int(0),
}
),
),
None,
),
# Error cases
(
pt.Int(1),
Expand Down

0 comments on commit 1a1c93f

Please sign in to comment.