def test_and_invalid(): with pytest.raises(pt.TealInputError): pt.And() with pytest.raises(pt.TealTypeError): pt.And(pt.Int(1), pt.Txn.receiver()) with pytest.raises(pt.TealTypeError): pt.And(pt.Txn.receiver(), pt.Int(1)) with pytest.raises(pt.TealTypeError): pt.And(pt.Txn.receiver(), pt.Txn.receiver())
def test_and_one(): arg = pt.Int(1) expr = pt.And(arg) assert expr.type_of() == pt.TealType.uint64 expected = pt.TealSimpleBlock([pt.TealOp(arg, pt.Op.int, 1)]) actual, _ = expr.__teal__(options) assert actual == expected
def test_and_two(): args = [pt.Int(1), pt.Int(2)] expr = pt.And(args[0], args[1]) assert expr.type_of() == pt.TealType.uint64 expected = pt.TealSimpleBlock([ pt.TealOp(args[0], pt.Op.int, 1), pt.TealOp(args[1], pt.Op.int, 2), pt.TealOp(expr, pt.Op.logic_and), ]) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) assert actual == expected
def test_method_config(): never_mc = pt.MethodConfig(no_op=pt.CallConfig.NEVER) assert never_mc.is_never() assert never_mc.approval_cond() == 0 assert never_mc.clear_state_cond() == 0 on_complete_pow_set = power_set(ON_COMPLETE_CASES) approval_check_names_n_ocs = [ (camel_to_snake(oc.name), oc) for oc in ON_COMPLETE_CASES if str(oc) != str(pt.OnComplete.ClearState) ] for on_complete_set in on_complete_pow_set: oc_names = [camel_to_snake(oc.name) for oc in on_complete_set] ordered_call_configs = full_ordered_combination_gen( list(pt.CallConfig), len(on_complete_set) ) for call_configs in ordered_call_configs: mc = pt.MethodConfig(**dict(zip(oc_names, call_configs))) match mc.clear_state: case pt.CallConfig.NEVER: assert mc.clear_state_cond() == 0 case pt.CallConfig.CALL: assert mc.clear_state_cond() == 1 case pt.CallConfig.CREATE | pt.CallConfig.ALL: with pytest.raises( pt.TealInputError, match=r"Only CallConfig.CALL or CallConfig.NEVER are valid for a clear state CallConfig, since clear state can never be invoked during creation$", ): mc.clear_state_cond() if mc.is_never() or all( getattr(mc, i) == pt.CallConfig.NEVER for i, _ in approval_check_names_n_ocs ): assert mc.approval_cond() == 0 continue elif all( getattr(mc, i) == pt.CallConfig.ALL for i, _ in approval_check_names_n_ocs ): assert mc.approval_cond() == 1 continue list_of_cc = [ ( typing.cast( pt.CallConfig, getattr(mc, i) ).approval_condition_under_config(), oc, ) for i, oc in approval_check_names_n_ocs ] list_of_expressions = [] for expr_or_int, oc in list_of_cc: match expr_or_int: case pt.Expr(): list_of_expressions.append( pt.And(pt.Txn.on_completion() == oc, expr_or_int) ) case 0: continue case 1: list_of_expressions.append(pt.Txn.on_completion() == oc) with pt.TealComponent.Context.ignoreExprEquality(): assert assemble_helper(mc.approval_cond()) == assemble_helper( pt.Or(*list_of_expressions) )