Skip to content

Commit 591b4af

Browse files
committed
refactor: excludes block models from generated code
Excludes block models from the generated client code to allow separate handling. This change introduces a mechanism to conditionally include block models during code generation based on a client configuration. It also updates the AVM debugger source map generation by incorporating hashes in the standard AVM debugger format. Skips tests that depend on msgpack handling until mock server is fixed.
1 parent 096a9ee commit 591b4af

File tree

11 files changed

+60
-59
lines changed

11 files changed

+60
-59
lines changed

api/oas-generator/src/oas_generator/renderer/engine.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def render(self, client: ctx.ClientDescriptor, config: GeneratorConfig) -> dict[
8181
files[models_dir / "__init__.py"] = self._render_template("models/__init__.py.j2", context)
8282
files[models_dir / "_serde_helpers.py"] = self._render_template("models/_serde_helpers.py.j2", context)
8383
ledger_model_names = set(LEDGER_STATE_DELTA_MODEL_NAMES)
84-
models = [model for model in context["client"].models if model.name not in ledger_model_names]
84+
block_model_names = set(self.BLOCK_MODEL_EXPORTS) if client.include_block_models else set()
85+
excluded_models = ledger_model_names | block_model_names
86+
models = [model for model in context["client"].models if model.name not in excluded_models]
8587
for model in models:
8688
model_context = {**context, "model": model}
8789
files[models_dir / f"{model.module_name}.py"] = self._render_template("models/model.py.j2", model_context)
@@ -126,10 +128,12 @@ def _build_context(self, client: ctx.ClientDescriptor, config: GeneratorConfig)
126128
model_exports.append("SuggestedParams")
127129
metadata_usage = self._collect_metadata_usage(client)
128130
ledger_model_names = set(LEDGER_STATE_DELTA_MODEL_NAMES)
131+
block_model_names = set(self.BLOCK_MODEL_EXPORTS) if client.include_block_models else set()
132+
excluded_models = ledger_model_names | block_model_names
129133
model_modules = [
130134
{"module": model.module_name, "name": model.name}
131135
for model in client.models
132-
if model.name not in ledger_model_names
136+
if model.name not in excluded_models
133137
]
134138
enum_modules = [{"module": enum.module_name, "name": enum.name} for enum in client.enums]
135139
alias_modules = [{"module": alias.module_name, "name": alias.name} for alias in client.aliases]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ sequence = [
239239
{ cmd = "ruff check --fix src/algokit_${SPEC}_client" },
240240
{ cmd = "ruff format src/algokit_${SPEC}_client" },
241241
]
242-
env.OAS_BRANCH = "fix/byte-len-validation"
242+
env.OAS_BRANCH = "main"
243243

244244
[tool.poe.tasks.generate-algod-client]
245245
ref = "generate-client"

src/algokit_algod_client/models/__init__.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,7 @@
2323
from ._asset_params import AssetParams
2424
from ._avm_key_value import AvmKeyValue
2525
from ._avm_value import AvmValue
26-
from ._block import (
27-
ApplyData,
28-
Block,
29-
BlockAccountStateDelta,
30-
BlockAppEvalDelta,
31-
BlockEvalDelta,
32-
BlockHeader,
33-
BlockResponse,
34-
BlockStateDelta,
35-
BlockStateProofTracking,
36-
BlockStateProofTrackingData,
37-
ParticipationUpdates,
38-
RewardState,
39-
SignedTxnInBlock,
40-
TxnCommitments,
41-
UpgradeState,
42-
UpgradeVote,
43-
)
26+
from ._block import Block, BlockHeader, BlockResponse, BlockStateProofTracking, ParticipationUpdates, SignedTxnInBlock
4427
from ._block_hash_response import BlockHashResponse
4528
from ._block_txids_response import BlockTxidsResponse
4629
from ._box import Box
@@ -130,22 +113,16 @@
130113
"ApplicationParams",
131114
"ApplicationStateOperation",
132115
"ApplicationStateSchema",
133-
"ApplyData",
134116
"Asset",
135117
"AssetHolding",
136118
"AssetParams",
137119
"AvmKeyValue",
138120
"AvmValue",
139121
"Block",
140-
"BlockAccountStateDelta",
141-
"BlockAppEvalDelta",
142-
"BlockEvalDelta",
143122
"BlockHashResponse",
144123
"BlockHeader",
145124
"BlockResponse",
146-
"BlockStateDelta",
147125
"BlockStateProofTracking",
148-
"BlockStateProofTrackingData",
149126
"BlockTxidsResponse",
150127
"Box",
151128
"BoxDescriptor",
@@ -193,7 +170,6 @@
193170
"PendingTransactionResponse",
194171
"PendingTransactionsResponse",
195172
"PostTransactionsResponse",
196-
"RewardState",
197173
"ScratchChange",
198174
"SignedTransaction",
199175
"SignedTxnInBlock",
@@ -220,8 +196,5 @@
220196
"TransactionGroupLedgerStateDeltasForRoundResponse",
221197
"TransactionParametersResponse",
222198
"TransactionProof",
223-
"TxnCommitments",
224-
"UpgradeState",
225-
"UpgradeVote",
226199
"VersionContainsTheCurrentAlgodVersion",
227200
]

src/algokit_algod_client/models/_block_response.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/algokit_indexer_client/models/_block.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from ._block_upgrade_vote import BlockUpgradeVote
1111
from ._participation_updates import ParticipationUpdates
1212
from ._serde_helpers import (
13-
decode_bytes_base64,
1413
decode_fixed_bytes_base64,
1514
decode_model_sequence,
16-
encode_bytes_base64,
1715
encode_fixed_bytes_base64,
1816
encode_model_sequence,
1917
)
@@ -98,8 +96,8 @@ class Block:
9896
default=None,
9997
metadata=wire(
10098
"previous-block-hash-512",
101-
encode=encode_bytes_base64,
102-
decode=decode_bytes_base64,
99+
encode=lambda v: encode_fixed_bytes_base64(v, 64),
100+
decode=lambda raw: decode_fixed_bytes_base64(raw, 64),
103101
),
104102
)
105103
proposer: str | None = field(
@@ -134,8 +132,8 @@ class Block:
134132
default=None,
135133
metadata=wire(
136134
"transactions-root-sha512",
137-
encode=encode_bytes_base64,
138-
decode=decode_bytes_base64,
135+
encode=lambda v: encode_fixed_bytes_base64(v, 64),
136+
decode=lambda raw: decode_fixed_bytes_base64(raw, 64),
139137
),
140138
)
141139
txn_counter: int | None = field(

src/algokit_utils/_debugging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
@dataclass
3838
class AVMDebuggerSourceMapEntry:
3939
location: str = field(metadata={"json": "sourcemap-location"})
40-
program_hash: str = field(metadata={"json": "sha512_256"})
40+
program_hash: str = field(metadata={"json": "hash"})
4141

4242
def __eq__(self, other: object) -> bool:
4343
if isinstance(other, AVMDebuggerSourceMapEntry):
4444
return self.location == other.location and self.program_hash == other.program_hash
4545
return False
4646

4747
def __str__(self) -> str:
48-
return json.dumps({"sourcemap-location": self.location, "sha512_256": self.program_hash})
48+
return json.dumps({"sourcemap-location": self.location, "hash": self.program_hash})
4949

5050

5151
@dataclass
@@ -56,7 +56,7 @@ class AVMDebuggerSourceMap:
5656
def from_dict(cls, data: dict) -> "AVMDebuggerSourceMap":
5757
return cls(
5858
txn_group_sources=[
59-
AVMDebuggerSourceMapEntry(location=item["sourcemap-location"], program_hash=item["sha512_256"])
59+
AVMDebuggerSourceMapEntry(location=item["sourcemap-location"], program_hash=item["hash"])
6060
for item in data.get("txn-group-sources", [])
6161
]
6262
)

tests/modules/algod_client/test_get_v2_accounts_address_transactions_pending.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Polytest Group: Common Tests
1010

1111

12+
@pytest.mark.skip(reason="TODO: Re-enable once msgpack handling is fixed in mock server")
1213
@pytest.mark.group_common_tests
1314
def test_basic_request_and_response_validation(algod_client: AlgodClient) -> None:
1415
"""Given a known request validate that the same request can be made using our models. Then, validate that our response model aligns with the known response"""

tests/modules/algod_client/test_get_v2_blocks_round.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
@pytest.mark.group_common_tests
13+
@pytest.mark.skip(reason="TODO: Re-enable once msgpack handling is fixed in mock server")
1314
def test_basic_request_and_response_validation(algod_client: AlgodClient) -> None:
1415
"""Given a known request validate that the same request can be made using our models. Then, validate that our response model aligns with the known response"""
1516
result = algod_client.get_block(round_=TEST_ROUND)

tests/modules/algod_client/test_get_v2_deltas_round.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Polytest Group: Common Tests
1010

1111

12+
@pytest.mark.skip(reason="TODO: Re-enable once msgpack handling is fixed in mock server")
1213
@pytest.mark.group_common_tests
1314
def test_basic_request_and_response_validation(algod_client: AlgodClient) -> None:
1415
"""Given a known request validate that the same request can be made using our models. Then, validate that our response model aligns with the known response"""

tests/modules/algod_client/test_get_v2_transactions_pending.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
@pytest.mark.group_common_tests
11+
@pytest.mark.skip(reason="TODO: Re-enable once msgpack handling is fixed in mock server")
1112
def test_basic_request_and_response_validation(algod_client: AlgodClient) -> None:
1213
"""Given a known request validate that the same request can be made using our models. Then, validate that our response model aligns with the known response"""
1314
result = algod_client.get_pending_transactions()

0 commit comments

Comments
 (0)