|
17 | 17 | AppClientParams, |
18 | 18 | FundAppAccountParams, |
19 | 19 | ) |
| 20 | +from algokit_utils.applications.app_factory import AppFactoryCreateMethodCallParams |
20 | 21 | from algokit_utils.applications.app_manager import AppManager |
21 | 22 | from algokit_utils.applications.app_spec.arc56 import Arc56Contract, Network |
22 | 23 | from algokit_utils.errors.logic_error import LogicError |
@@ -756,3 +757,51 @@ def test_exposing_logic_error(test_app_client_with_sourcemaps: AppClient) -> Non |
756 | 757 | assert "assert failed pc=885" in str(error) |
757 | 758 | assert len(error.transaction_id) == 52 |
758 | 759 | assert error.line_no == 469 |
| 760 | + |
| 761 | + |
| 762 | +@pytest.fixture |
| 763 | +def nested_struct_app_spec() -> Arc56Contract: |
| 764 | + raw_json_spec = Path(__file__).parent.parent / "artifacts" / "nested_struct" / "nested_struct.arc56.json" |
| 765 | + return Arc56Contract.from_json(raw_json_spec.read_text()) |
| 766 | + |
| 767 | + |
| 768 | +def test_nested_structs_described_by_structure( |
| 769 | + algorand: AlgorandClient, funded_account: SigningAccount, nested_struct_app_spec: Arc56Contract |
| 770 | +) -> None: |
| 771 | + """Test nested struct when described by structure.""" |
| 772 | + factory = algorand.client.get_app_factory(app_spec=nested_struct_app_spec, default_sender=funded_account.address) |
| 773 | + app_client, _ = factory.send.create(AppFactoryCreateMethodCallParams(method="createApplication", args=[])) |
| 774 | + app_client.send.call(AppClientMethodCallParams(method="setValue", args=[1, "hello"])) |
| 775 | + |
| 776 | + result = app_client.send.call(AppClientMethodCallParams(method="getValue", args=[1])) |
| 777 | + |
| 778 | + assert result.abi_return == {"x": {"a": "hello"}} |
| 779 | + |
| 780 | + |
| 781 | +def test_nested_structs_referenced_by_name( |
| 782 | + algorand: AlgorandClient, funded_account: SigningAccount, nested_struct_app_spec: Arc56Contract |
| 783 | +) -> None: |
| 784 | + """Test nested struct when referenced by name.""" |
| 785 | + edited_spec_dict = nested_struct_app_spec.dictify() |
| 786 | + edited_spec_dict["structs"] = { |
| 787 | + "Struct1": [ |
| 788 | + { |
| 789 | + "name": "a", |
| 790 | + "type": "string", |
| 791 | + } |
| 792 | + ], |
| 793 | + "Struct2": [ |
| 794 | + { |
| 795 | + "name": "x", |
| 796 | + "type": "Struct1", |
| 797 | + } |
| 798 | + ], |
| 799 | + } |
| 800 | + edited_spec = Arc56Contract.from_json(json.dumps(edited_spec_dict)) |
| 801 | + factory = algorand.client.get_app_factory(app_spec=edited_spec, default_sender=funded_account.address) |
| 802 | + app_client, _ = factory.send.create(AppFactoryCreateMethodCallParams(method="createApplication", args=[])) |
| 803 | + app_client.send.call(AppClientMethodCallParams(method="setValue", args=[1, "hello"])) |
| 804 | + |
| 805 | + result = app_client.send.call(AppClientMethodCallParams(method="getValue", args=[1])) |
| 806 | + |
| 807 | + assert result.abi_return == {"x": {"a": "hello"}} |
0 commit comments