Skip to content

Commit e6c21b4

Browse files
authored
Merge pull request #183 from algorandfoundation/chore/ts-sync
chore: add test to confirm fix in ts wasn't applicable
2 parents 5494da9 + 300e9c5 commit e6c21b4

File tree

3 files changed

+954
-0
lines changed

3 files changed

+954
-0
lines changed

tests/applications/test_app_client.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
AppClientParams,
1818
FundAppAccountParams,
1919
)
20+
from algokit_utils.applications.app_factory import AppFactoryCreateMethodCallParams
2021
from algokit_utils.applications.app_manager import AppManager
2122
from algokit_utils.applications.app_spec.arc56 import Arc56Contract, Network
2223
from algokit_utils.errors.logic_error import LogicError
@@ -756,3 +757,51 @@ def test_exposing_logic_error(test_app_client_with_sourcemaps: AppClient) -> Non
756757
assert "assert failed pc=885" in str(error)
757758
assert len(error.transaction_id) == 52
758759
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"}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Contract } from '@algorandfoundation/tealscript'
2+
3+
type Struct1 = { a: string }
4+
type Struct2 = { x: Struct1 }
5+
6+
export class NestedStruct extends Contract {
7+
createApplication() {}
8+
9+
state = GlobalStateMap<uint64, Struct2>({ prefix: '', maxKeys: 10 })
10+
11+
setValue(key: uint64, value: string): void {
12+
this.state(key).value = { x: { a: value } }
13+
}
14+
15+
getValue(key: uint64): Struct2 {
16+
return this.state(key).value
17+
}
18+
}

0 commit comments

Comments
 (0)