-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnever_submit.py
More file actions
53 lines (38 loc) · 1.54 KB
/
never_submit.py
File metadata and controls
53 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Flow D — provider never submits, client reclaims via expiry.
createJob → register → setBudget → fund → (provider silent) → wait past
``expiredAt`` → ``claimRefund`` → EXPIRED.
Wall-clock wait scales with the contract's ``disputeWindow`` because
``expiredAt`` must be at least ``disputeWindow`` in the future for
Commerce to accept the job.
"""
from __future__ import annotations
import time
from _helpers import banner, expiry_for, load_settings, make_client
from bnbagent.erc8183 import JobStatus
def main() -> None:
s = load_settings()
client = make_client(s.client_pk, s.network)
banner("NEVER SUBMIT — provider silent, refund at expiry")
decimals = client.token_decimals()
budget = 1 * (10 ** decimals)
expired_at = expiry_for(client, slack_minutes=1)
res = client.create_job(
provider=s.provider_address,
expired_at=expired_at,
description="ERC-8183 demo: never-submit",
)
job_id = res["jobId"]
print(f"[client] createJob jobId={job_id} expiredAt={expired_at}")
client.register_job(job_id)
client.set_budget(job_id, budget)
client.fund(job_id, budget)
wait = expired_at - int(time.time()) + 3
print(f"[client] waiting {wait}s for expiry (provider is silent)...")
if wait > 0:
time.sleep(wait)
client.claim_refund(job_id)
job = client.get_job(job_id)
assert job.status == JobStatus.EXPIRED, f"expected EXPIRED, got {job.status.name}"
print(f"[client] claimRefund OK -> {job.status.name}")
if __name__ == "__main__":
main()