Skip to content

Commit cb00544

Browse files
authored
Revert Box Application Pagination support. (#572)
1 parent 49677b5 commit cb00544

File tree

2 files changed

+9
-100
lines changed

2 files changed

+9
-100
lines changed

algosdk/v2client/algod.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -194,41 +194,21 @@ def application_box_by_name(
194194
return self.algod_request("GET", req, params=params, **kwargs)
195195

196196
def application_boxes(
197-
self,
198-
application_id: int,
199-
limit: int = 0,
200-
prefix: Optional[str] = None,
201-
next: Optional[str] = None,
202-
values: Optional[bool] = False,
203-
**kwargs: Any,
197+
self, application_id: int, limit: int = 0, **kwargs: Any
204198
) -> AlgodResponseType:
205199
"""
206-
Given an application ID, return boxes in lexographical order by name. If the results must be truncated, a next-token is supplied to continue the request.
200+
Given an application ID, return all Box names. No particular ordering is guaranteed. Request fails when client or server-side configured limits prevent returning all Box names.
201+
207202
NOTE: box names are returned as base64-encoded strings.
208203
209204
Args:
210205
application_id (int): The ID of the application to look up.
211206
limit (int, optional): Max number of box names to return.
212207
If max is not set, or max == 0, returns all box-names up to the maximum configured by the algod server being queried.
213-
prefix (str, optional): A box name prefix, in the goal app
214-
call arg form 'encoding:value'. For ints, use the form 'int:1234'. For raw bytes, use the form 'b64:A=='.
215-
For printable strings, use the form 'str:hello'. For addresses, use the form 'addr:XYZ...'.
216-
next (str, optional): A box name, in the goal app call arg
217-
form 'encoding:value'. When provided, the returned boxes begin (lexographically) with the supplied name. Callers may
218-
implement pagination by reinvoking the endpoint with the token from a previous call's next-token.
219-
values (bool, optional): If true, box values will be returned.
220-
"""
221-
query: Dict[str, Union[int, str]] = {}
222-
if limit:
223-
query["max"] = limit
224-
if prefix:
225-
query["prefix"] = prefix
226-
if next:
227-
query["next"] = next
228-
if values:
229-
query["values"] = "true"
208+
"""
230209
req = "/applications/" + str(application_id) + "/boxes"
231-
return self.algod_request("GET", req, params=query, **kwargs)
210+
params = {"max": limit} if limit else {}
211+
return self.algod_request("GET", req, params=params, **kwargs)
232212

233213
def account_asset_info(
234214
self, address: str, asset_id: int, **kwargs: Any

tests/steps/application_v2_steps.py

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ def application_box_by_name(context, app_id, box_name):
181181

182182

183183
@when(
184-
'we make a GetApplicationBoxes call for applicationID {app_id} with max {max_results} prefix "{prefix:MaybeString}" next "{next:MaybeString}" values "{values:MaybeBool}"'
184+
"we make a GetApplicationBoxes call for applicationID {app_id} with max {max_results}"
185185
)
186-
def application_boxes(context, app_id, max_results, prefix, next, values):
186+
def application_boxes(context, app_id, max_results):
187187
context.response = context.acl.application_boxes(
188-
app_id, limit=int(max_results), prefix=prefix, next=next, values=values
188+
app_id, limit=int(max_results)
189189
)
190190

191191

@@ -1243,10 +1243,7 @@ def check_all_boxes(context, from_client: str, box_names: str = None):
12431243
base64.b64decode(box_encoded)
12441244
for box_encoded in box_names.split(":")
12451245
]
1246-
expected_num_boxes = len(expected_box_names)
1247-
12481246
if from_client == "algod":
1249-
advance_chain_wait_for_box(context, expected_num_boxes)
12501247
box_response = context.app_acl.application_boxes(
12511248
context.current_application_id
12521249
)
@@ -1270,74 +1267,6 @@ def check_all_boxes(context, from_client: str, box_names: str = None):
12701267
), f"Expected box names array does not match actual array {expected_box_names} != {actual_box_names}"
12711268

12721269

1273-
def advance_chain_wait_for_box(
1274-
context,
1275-
expected_num_boxes: int,
1276-
wait_rounds: int = 5,
1277-
max_attempts: int = 50,
1278-
):
1279-
"""
1280-
Advance the blockchain and wait for application boxes to persist in Algod.
1281-
1282-
Args:
1283-
context: Behave context containing necessary information like app_acl, current_application_id, sender, etc.
1284-
wait_rounds (int): The number of rounds to wait for persistence.
1285-
max_attempts (int): Maximum number of attempts to check for persistence.
1286-
1287-
Raises:
1288-
Exception: If the boxes do not persist within the specified number of attempts.
1289-
"""
1290-
algod_client = context.app_acl
1291-
app_id = context.current_application_id
1292-
sender = context.transient_pk
1293-
sender_private_key = context.transient_sk
1294-
1295-
# Get the current round
1296-
status = algod_client.status()
1297-
current_round = status.get("last-round", 0)
1298-
target_round = current_round + wait_rounds
1299-
1300-
attempts = 0
1301-
while attempts < max_attempts:
1302-
# Submit a 0-pay transaction to advance the blockchain state
1303-
params = algod_client.suggested_params()
1304-
txn = transaction.PaymentTxn(
1305-
sender,
1306-
params,
1307-
sender,
1308-
0,
1309-
note=b"Advance round for box persistence",
1310-
)
1311-
signed_txn = txn.sign(sender_private_key)
1312-
tx_id = algod_client.send_transaction(signed_txn)
1313-
1314-
# Wait for transaction confirmation
1315-
transaction.wait_for_confirmation(algod_client, tx_id, 1)
1316-
1317-
# Wait for a second before checking again
1318-
time.sleep(1)
1319-
attempts += 1
1320-
1321-
# Get the latest status
1322-
status = algod_client.status()
1323-
current_round = status.get("last-round", 0)
1324-
1325-
if current_round >= target_round:
1326-
# Check if boxes are available
1327-
try:
1328-
box_response = algod_client.application_boxes(app_id)
1329-
actual_num_boxes = len(box_response.get("boxes", []))
1330-
1331-
if actual_num_boxes == expected_num_boxes:
1332-
return # Exit once the condition is met
1333-
except Exception as e:
1334-
print(f"Error retrieving boxes: {e}")
1335-
1336-
raise Exception(
1337-
f"Timeout waiting for boxes to persist for application {app_id}. Current round: {current_round}"
1338-
)
1339-
1340-
13411270
@then(
13421271
'according to indexer, with {limit} being the parameter that limits results, and "{next_page:MaybeString}" being the parameter that sets the next result, the current application should have the following boxes "{box_names:MaybeString}".'
13431272
)

0 commit comments

Comments
 (0)