Skip to content

Commit 5d18c02

Browse files
author
Matthias Zimmermann
committed
feat: switch to extend_by for extend_entity
1 parent cbcb6d4 commit 5d18c02

16 files changed

+80
-75
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,3 @@ Pre-commit hooks run automatically on `git commit` and will:
528528
function gl { git log --format="%C(green)%ad%C(reset) %C(yellow)%h%C(reset)%C(auto)%d%C(reset) %s" --date=format:"%Y-%m-%d_%H:%M:%S" -n ${1:-10}; }
529529
alias gs='git status'
530530
```
531-
532-

src/arkiv/module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ def update_entity(
125125
def extend_entity(
126126
self,
127127
entity_key: EntityKey,
128-
number_of_blocks: int,
128+
extend_by: int,
129129
tx_params: TxParams | None = None,
130130
) -> TransactionReceipt:
131131
# Docstring inherited from ArkivModuleBase.extend_entity
132132
# Create the extend operation and execute TX
133-
extend_op = ExtendOp(key=entity_key, number_of_blocks=number_of_blocks)
133+
extend_op = ExtendOp(key=entity_key, extend_by=extend_by)
134134
operations = Operations(extensions=[extend_op])
135135
receipt = self.execute(operations, tx_params)
136136

src/arkiv/module_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ async def update_entity( # type: ignore[override]
124124
async def extend_entity( # type: ignore[override]
125125
self,
126126
entity_key: EntityKey,
127-
number_of_blocks: int,
127+
extend_by: int,
128128
tx_params: TxParams | None = None,
129129
) -> TransactionReceipt:
130130
# Docstring inherited from ArkivModuleBase.extend_entity
131131
# Create the extend operation and execute TX
132-
extend_op = ExtendOp(key=entity_key, number_of_blocks=number_of_blocks)
132+
extend_op = ExtendOp(key=entity_key, extend_by=extend_by)
133133
operations = Operations(extensions=[extend_op])
134134
receipt = await self.execute(operations, tx_params)
135135

src/arkiv/module_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def change_owner(
289289
def extend_entity(
290290
self,
291291
entity_key: EntityKey,
292-
number_of_blocks: int,
292+
extend_by: int,
293293
tx_params: TxParams | None = None,
294294
) -> TransactionReceipt:
295295
"""

src/arkiv/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class ExtendOp:
234234
"""Class to represent a entity lifetime extend operation."""
235235

236236
key: EntityKey
237-
number_of_blocks: int
237+
extend_by: int
238238

239239

240240
@dataclass(frozen=True)

src/arkiv/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def rlp_encode_transaction(tx: Operations) -> bytes:
779779
[
780780
[
781781
entity_key_to_bytes(element.key),
782-
element.number_of_blocks,
782+
to_blocks(seconds=element.extend_by),
783783
]
784784
for element in tx.extensions
785785
],

tests/test_async_entity_extend.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ async def test_async_extend_entity_basic(
3636
initial_expiration = entity_before.expires_at_block
3737
assert initial_expiration is not None, "Entity should have expiration block"
3838

39-
# Extend the entity by 50 blocks
40-
number_of_blocks = 50
39+
# Extend the entity by 50 seconds
40+
seconds = 50
41+
number_of_blocks = async_arkiv_client_http.arkiv.to_blocks(seconds=seconds)
4142
receipt = await async_arkiv_client_http.arkiv.extend_entity(
42-
entity_key, number_of_blocks
43+
entity_key, extend_by=seconds
4344
)
4445

4546
check_tx_hash("test_async_extend_entity_basic_extend", receipt)
46-
logger.info(f"Extended entity {entity_key} by {number_of_blocks} blocks")
47+
logger.info(f"Extended entity {entity_key} by {seconds} seconds")
4748

4849
# Verify expiration increased
4950
entity_after = await async_arkiv_client_http.arkiv.get_entity(entity_key)
@@ -76,10 +77,11 @@ async def test_async_extend_entities_sequentially(
7677
assert expiration is not None, f"Entity {i} should have an expiration block"
7778

7879
# Extend all entities sequentially
79-
number_of_blocks = 50
80+
seconds = 50
81+
number_of_blocks = async_arkiv_client_http.arkiv.to_blocks(seconds=seconds)
8082
for i, entity_key in enumerate(entity_keys):
8183
receipt = await async_arkiv_client_http.arkiv.extend_entity(
82-
entity_key, number_of_blocks
84+
entity_key, extend_by=seconds
8385
)
8486
check_entity_key(entity_key, f"test_async_extend_entities_sequentially_{i}")
8587
check_tx_hash(f"test_async_extend_entities_sequentially_{i}", receipt)

tests/test_async_watch_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def on_extended(event: ExtendEvent, tx_hash: TxHash) -> None:
140140
)
141141

142142
receipt = await async_arkiv_client_http.arkiv.extend_entity(
143-
entity_key, number_of_blocks=100
143+
entity_key, extend_by=100
144144
)
145145

146146
# Wait for event

tests/test_entity_create_parallel.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ def client_creation_task(
101101
entity_index = tx_no * batch_size + entity_no
102102
payload = random_payload()
103103
attributes = random_attributes(client_idx, entity_index)
104-
btl = random_expires_in()
105-
entities_in_batch.append((payload, attributes, btl))
104+
expires_in = random_expires_in()
105+
entities_in_batch.append((payload, attributes, expires_in))
106106

107107
# Create entity/entities based on batch_size
108108
try:
109109
if batch_size == 1:
110110
# Single entity creation
111-
payload, attributes, btl = entities_in_batch[0]
111+
payload, attributes, expires_in = entities_in_batch[0]
112112
try:
113113
entity_key, tx_hash = client.arkiv.create_entity(
114-
payload=payload, attributes=attributes, expires_in=btl
114+
payload=payload, attributes=attributes, expires_in=expires_in
115115
)
116116
logger.info(
117117
f"Entity creation TX[{client_idx}][{tx_no}]: {tx_hash} (1 entity)"
@@ -135,7 +135,7 @@ def client_creation_task(
135135
)
136136
# Store all created entities with their expected data
137137
for i, entity_key in enumerate(entity_keys):
138-
payload, attributes, btl = entities_in_batch[i]
138+
payload, attributes, expires_in = entities_in_batch[i]
139139
created_entities.append((entity_key, payload, attributes))
140140
except HTTPError as e:
141141
logger.error(f"Error creating entities[{client_idx}][{tx_no}]: {e}")

tests/test_entity_extend.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,24 @@ def test_extend_entity_simple(self, arkiv_client_http: Arkiv) -> None:
4242
logger.info(f"Initial expiration block: {initial_expiration}")
4343

4444
# Extend the entity by 50 blocks
45-
number_of_blocks = 50
45+
seconds = 50
4646
extend_tx_hash = arkiv_client_http.arkiv.extend_entity(
47-
entity_key, number_of_blocks
47+
entity_key, extend_by=seconds
4848
)
4949

5050
label = "extend_entity"
5151
check_tx_hash(label, extend_tx_hash)
5252
logger.info(
53-
f"{label}: Extended entity {entity_key} by {number_of_blocks} blocks, tx_hash: {extend_tx_hash}"
53+
f"{label}: Extended entity {entity_key} by {seconds} seconds, tx_hash: {extend_tx_hash}"
5454
)
5555

5656
# Verify the entity still exists and expiration increased
5757
entity_after = arkiv_client_http.arkiv.get_entity(entity_key)
5858
logger.info(f"Entity after extension: {entity_after}")
59-
assert entity_after.expires_at_block == initial_expiration + number_of_blocks, (
60-
f"Expiration should increase by {number_of_blocks} blocks"
61-
)
59+
assert (
60+
entity_after.expires_at_block
61+
== initial_expiration + arkiv_client_http.arkiv.to_blocks(seconds)
62+
), f"Expiration should increase by {seconds} seconds"
6263

6364
logger.info(
6465
f"{label}: Entity expiration increased from {initial_expiration} to {entity_after.expires_at_block}"
@@ -85,7 +86,9 @@ def test_extend_entity_multiple_times(self, arkiv_client_http: Arkiv) -> None:
8586

8687
# Verify final expiration
8788
entity_final = arkiv_client_http.arkiv.get_entity(entity_key)
88-
expected_expiration = initial_expiration + sum(extensions)
89+
expected_expiration = initial_expiration + arkiv_client_http.arkiv.to_blocks(
90+
sum(extensions)
91+
)
8992
assert entity_final.expires_at_block == expected_expiration, (
9093
f"Expiration should be {expected_expiration}"
9194
)
@@ -121,10 +124,8 @@ def test_extend_entity_execute_bulk(self, arkiv_client_http: Arkiv) -> None:
121124
initial_expirations[entity_key] = expires_at
122125

123126
# Bulk extend
124-
number_of_blocks = 200
125-
extend_ops = [
126-
ExtendOp(key=key, number_of_blocks=number_of_blocks) for key in entity_keys
127-
]
127+
seconds = 200
128+
extend_ops = [ExtendOp(key=key, extend_by=seconds) for key in entity_keys]
128129
operations = Operations(extensions=extend_ops)
129130
receipt = arkiv_client_http.arkiv.execute(operations)
130131

@@ -140,7 +141,11 @@ def test_extend_entity_execute_bulk(self, arkiv_client_http: Arkiv) -> None:
140141
# Verify all expirations increased
141142
for entity_key in entity_keys:
142143
entity = arkiv_client_http.arkiv.get_entity(entity_key)
143-
expected_expiration = initial_expirations[entity_key] + number_of_blocks
144+
expected_expiration = (
145+
initial_expirations[entity_key]
146+
+ arkiv_client_http.arkiv.to_blocks(seconds)
147+
# + seconds / ArkivModuleBase.BLOCK_TIME_SECONDS
148+
)
144149
assert entity.expires_at_block == expected_expiration, (
145150
f"Entity {entity_key} expiration should be {expected_expiration}"
146151
)
@@ -222,7 +227,7 @@ def test_extend_entity_minimal_blocks(self, arkiv_client_http: Arkiv) -> None:
222227
)
223228

224229
# Extend by just 1 block
225-
extend_tx_hash = arkiv_client_http.arkiv.extend_entity(entity_key, 1)
230+
extend_tx_hash = arkiv_client_http.arkiv.extend_entity(entity_key, extend_by=2)
226231
check_tx_hash("extend_minimal", extend_tx_hash)
227232

228233
# Verify expiration increased by 1

0 commit comments

Comments
 (0)