uagent-testkit 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. uagent_testkit-0.1.2/.github/workflows/ci.yml +33 -0
  2. uagent_testkit-0.1.2/CHANGELOG.md +89 -0
  3. uagent_testkit-0.1.2/LICENSE +202 -0
  4. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/PKG-INFO +58 -18
  5. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/README.md +52 -15
  6. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/pyproject.toml +8 -2
  7. uagent_testkit-0.1.2/tests/test_chain.py +673 -0
  8. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/test_harness.py +130 -4
  9. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/test_network.py +28 -0
  10. uagent_testkit-0.1.2/tests/test_plugin.py +127 -0
  11. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/uagent_testkit/__init__.py +1 -1
  12. uagent_testkit-0.1.2/uagent_testkit/_loop.py +83 -0
  13. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/uagent_testkit/_recording.py +21 -3
  14. uagent_testkit-0.1.2/uagent_testkit/_refusals.py +79 -0
  15. uagent_testkit-0.1.2/uagent_testkit/chain.py +495 -0
  16. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/uagent_testkit/harness.py +25 -10
  17. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/uagent_testkit/network.py +21 -12
  18. uagent_testkit-0.1.2/uagent_testkit/plugin.py +107 -0
  19. uagent_testkit-0.1.1/.github/workflows/ci.yml +0 -21
  20. uagent_testkit-0.1.1/LICENSE +0 -15
  21. uagent_testkit-0.1.1/tests/test_chain.py +0 -227
  22. uagent_testkit-0.1.1/uagent_testkit/_loop.py +0 -30
  23. uagent_testkit-0.1.1/uagent_testkit/chain.py +0 -383
  24. uagent_testkit-0.1.1/uagent_testkit/plugin.py +0 -71
  25. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/.gitignore +0 -0
  26. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/examples/__init__.py +0 -0
  27. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/examples/quote_agents.py +0 -0
  28. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/examples/test_quote_agents.py +0 -0
  29. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/__init__.py +0 -0
  30. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/conftest.py +0 -0
  31. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/test_chat_protocol.py +0 -0
  32. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/test_no_network.py +0 -0
  33. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/tests/test_verification.py +0 -0
  34. {uagent_testkit-0.1.1 → uagent_testkit-0.1.2}/uagent_testkit/_storage.py +0 -0
@@ -0,0 +1,33 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: pip install -e ".[test]"
21
+ - run: pytest -q
22
+
23
+ oldest-uagents:
24
+ # The floor pyproject.toml declares, so a wrong floor fails here rather than
25
+ # for a user pinned to it. uagents 0.23.0 requires uagents-core>=0.4.0.
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: actions/setup-python@v5
30
+ with:
31
+ python-version: "3.12"
32
+ - run: pip install -e ".[test]" "uagents==0.23.0" "uagents-core==0.4.0"
33
+ - run: pytest -q
@@ -0,0 +1,89 @@
1
+ # Changelog
2
+
3
+ ## 0.1.2 (unreleased)
4
+
5
+ Fixes from a bug hunt on 2026-10-05, run against uagents 0.26.0 (released 2026-10-02)
6
+ and web3 7.16 and 8.0. Each code fix comes with a test that fails on 0.1.1.
7
+
8
+ - **ChainDouble works with web3.py.** 0.1.x said it did and never had: every
9
+ `Web3.HTTPProvider` call failed with `TypeError: '_Response' object does not support
10
+ the context manager protocol`, every `AsyncHTTPProvider` call with
11
+ `AttributeError: '_Response' object has no attribute 'read'`, and httpx's
12
+ `raise_for_status()` raised `RuntimeError`. The double now answers with real
13
+ `requests` and `httpx` responses and a complete aiohttp one, and the suite drives both
14
+ web3.py providers.
15
+ - **No unclosed event loops.** The pytest plugin loads into every suite in an
16
+ environment where the package is installed. It made a new event loop for every test
17
+ and closed none, so any suite with async tests run under `-W error` failed on
18
+ `ResourceWarning: unclosed event loop`, even one that never imports uAgents. It now
19
+ keeps one loop for the session and closes it at the end.
20
+ - **Agents build in any fixture.** A module- or session-scoped fixture that builds an
21
+ `Agent` failed with `RuntimeError: There is no current event loop` when it was set up
22
+ after an async test (pytest-asyncio 1.x unsets its loop after each one), and an agent
23
+ built at import time in a `conftest.py` warned, which `-W error` turns into a failed
24
+ conftest. The plugin now puts a loop in place before every test's fixtures and before
25
+ conftests load.
26
+ - **A refusal the handler catches still fails the delivery.** Agents wrap RPC reads in
27
+ `try/except`, which turned a missing stub back into a silent pass. `deliver()`,
28
+ `tick()`, `startup()` and `shutdown()` now re-raise any refusal the handler's own work
29
+ made, in the handler, in tasks it starts or in a thread; `chain.refusals` lists them
30
+ all. A refusal is matched to its delivery by context, so the agent's own manifest
31
+ upload and a delivery running alongside are not blamed on the handler.
32
+ - **ChainDouble blocks what it says it blocks.** Eight request paths reached the
33
+ network: requests' `Session.send()` and adapters, httpx's `Client.stream()`,
34
+ `Client.send()` and `AsyncClient.send()`, and urllib. requests, httpx, aiohttp and
35
+ urllib are now patched where every request through them passes. A JSON body that is
36
+ not JSON-RPC, such as an LLM or webhook call, raised
37
+ `UnstubbedCall: handler called None` instead of `NetworkCallBlocked`. `http.client`,
38
+ `urllib3` used directly and raw sockets are not covered, and the README says so.
39
+ - **Dependency floor.** `uagents>=0.22` was wrong: on every 0.22.x the first
40
+ `deliver()` raises `TypeError`, because `AgentRepresentation` takes no `prefix` before
41
+ 0.23. The floor is now `uagents>=0.23`, and CI tests it.
42
+ - **Reply contracts match the framework.** An `ErrorMessage` answer honours any
43
+ `replies=` declaration, as the framework's `validate_replies()` allows; the harness
44
+ used to fail it. And the harness now runs `validate_replies()` after each handler, as
45
+ `Agent._handle_message` does, so a missing reply logs the same error as in production
46
+ and `assert_no_errors()` fails on it.
47
+ - **AgentNetwork keeps one session per conversation.** Each hop got a fresh
48
+ `ctx.session`; in production a reply carries the session of the message it answers.
49
+ `send()` also takes `session=`.
50
+ - **Sending to an agent outside the network raises `KeyError`.** It returned an empty
51
+ transcript that passed `assert_all_delivered()`.
52
+ - **Checksummed calldata.** A mixed-case holder or selector in `eth_call` data raised
53
+ `UnstubbedCall` ("which the test never set") for a balance the test had set.
54
+ - **`raise_errors=False` no longer swallows cancellation.** A timeout around
55
+ `deliver()` returned a `Delivery` holding `CancelledError` instead of timing out.
56
+ - **`ctx.send_and_receive()` fails loudly.** It returned `None` after no wait at all;
57
+ it now raises `NotImplementedError` and says why, and fails the delivery even when the
58
+ handler catches it.
59
+ - **Docs.** The README's "Asserting on failure" example raised `IndexError`.
60
+ `h.tick()` also runs `@on_schedule` handlers on uagents 0.26+. `include(proto,
61
+ publish_manifest=True)` uploads a manifest to Agentverse whenever the agent's loop
62
+ runs, harness or not. `test_storage_does_not_touch_disk` could not see the file it
63
+ guards against.
64
+ - `LICENSE` holds the full Apache-2.0 text. It held only the short notice, and GitHub
65
+ listed the licence as "Other".
66
+
67
+ ### Behaviour changes that can fail a test that passed on 0.1.1
68
+
69
+ In each case the old pass was hiding something:
70
+
71
+ - A handler that catches an `UnstubbedCall` or `NetworkCallBlocked` now fails its
72
+ delivery. It passed on data the test never set up.
73
+ - `assert_no_errors()` fails when a handler sends none of its declared replies, which
74
+ production logs as an error.
75
+ - `AgentNetwork.send()` to an agent never added raises `KeyError`. Nothing was
76
+ delivered, and the empty transcript passed `assert_all_delivered()`.
77
+ - `ctx.send_and_receive()` raises `NotImplementedError`, caught or not. The handler got
78
+ `None` even when the peer answered, so only its no-reply path ever ran.
79
+ - Requests through urllib, httpx's `stream()`/`send()` and requests' `Session.send()`
80
+ are answered or refused under `ChainDouble.install()`. They reached the network.
81
+
82
+ ## 0.1.1 (2026-07-28)
83
+
84
+ - `ChainDouble`, for agents that read BNB Chain.
85
+
86
+ ## 0.1.0 (2026-07-28)
87
+
88
+ - First release: the single-agent harness, `AgentNetwork`, Protocol-based agents and
89
+ the shared chat protocol, and the pytest fixtures.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,10 +1,11 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: uagent-testkit
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Test Fetch.ai uAgents offline — handlers, agent-to-agent flows, and BNB Chain reads.
5
5
  Project-URL: Homepage, https://github.com/pgalyen1987/uagent-testkit
6
6
  Project-URL: Repository, https://github.com/pgalyen1987/uagent-testkit
7
7
  Project-URL: Issues, https://github.com/pgalyen1987/uagent-testkit/issues
8
+ Project-URL: Changelog, https://github.com/pgalyen1987/uagent-testkit/blob/main/CHANGELOG.md
8
9
  Author-email: Patrick Galyen <pgalyen87@gmail.com>
9
10
  License-Expression: Apache-2.0
10
11
  License-File: LICENSE
@@ -19,12 +20,14 @@ Classifier: Programming Language :: Python :: 3.12
19
20
  Classifier: Programming Language :: Python :: 3.13
20
21
  Classifier: Topic :: Software Development :: Testing
21
22
  Requires-Python: >=3.10
22
- Requires-Dist: uagents>=0.22
23
+ Requires-Dist: uagents>=0.23
23
24
  Provides-Extra: test
24
25
  Requires-Dist: aiohttp>=3.9; extra == 'test'
26
+ Requires-Dist: httpx>=0.27; extra == 'test'
25
27
  Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
26
28
  Requires-Dist: pytest>=8.0; extra == 'test'
27
29
  Requires-Dist: requests>=2.31; extra == 'test'
30
+ Requires-Dist: web3>=7; extra == 'test'
28
31
  Description-Content-Type: text/markdown
29
32
 
30
33
  # uagent-testkit
@@ -66,14 +69,16 @@ records instead of transmitting. No sockets, no registration, no waiting.
66
69
  - **Handler exceptions are raised** rather than contained into a log.
67
70
  - **Storage is in-memory**, so state doesn't leak between tests via the JSON file the
68
71
  stock `KeyValueStore` writes to your working directory.
69
- - **Reply contracts are enforced** — if `@on_message(replies=Pong)` doesn't send a
70
- `Pong`, that's an assertion failure instead of a log line nobody reads.
72
+ - **Reply contracts are checked** — if `@on_message(replies=Pong)` sends neither a
73
+ `Pong` nor an `ErrorMessage`, `assert_reply_contract()` fails, and the error the
74
+ framework would log lands in `result.logs`, where `assert_no_errors()` sees it.
71
75
  - **Interval and lifecycle handlers run on demand**, so an `@on_interval(period=3600)`
72
76
  is testable without waiting an hour.
73
77
  - **Multi-agent conversations replay deterministically**, with a loop guard instead of
74
78
  a hung test.
75
79
  - **Agents that read BNB Chain are testable offline** — `ChainDouble` answers BEP-20
76
- and balance queries from state your test sets, and blocks any other outbound HTTP.
80
+ and balance queries from state your test sets, and blocks any other request made
81
+ through requests, httpx, aiohttp or urllib.
77
82
 
78
83
  ## Install
79
84
 
@@ -81,7 +86,7 @@ records instead of transmitting. No sockets, no registration, no waiting.
81
86
  pip install uagent-testkit
82
87
  ```
83
88
 
84
- Requires Python 3.10+ and `uagents>=0.22`. The pytest fixtures register automatically.
89
+ Requires Python 3.10+ and `uagents>=0.23`. The pytest fixtures register automatically.
85
90
 
86
91
  ## Testing one agent
87
92
 
@@ -121,11 +126,12 @@ async def test_ping():
121
126
  async def test_bad_input_is_handled():
122
127
  result = await h.deliver(Ping(text=""), raise_errors=False)
123
128
  assert isinstance(result.error, ValueError)
124
- assert "empty" in result.logs.errors[0]
129
+ assert "empty" in str(result.error)
125
130
  ```
126
131
 
127
132
  By default `deliver()` re-raises whatever the handler raised, so a broken handler fails
128
133
  the test loudly. Pass `raise_errors=False` when the failure is the thing under test.
134
+ Cancellation and `KeyboardInterrupt` are not handler failures, so they always propagate.
129
135
 
130
136
  ### Sender verification
131
137
 
@@ -146,6 +152,7 @@ async def test_strict_handler_refuses_users():
146
152
  ```python
147
153
  await h.startup() # runs @on_event("startup") handlers
148
154
  result = await h.tick() # runs @on_interval handlers once, ignoring period
155
+ # (and @on_schedule ones, on uagents 0.26+)
149
156
  result = await h.tick(only="heartbeat") # just one, by function name
150
157
  await h.shutdown()
151
158
  ```
@@ -165,8 +172,11 @@ async def test_conversation():
165
172
  ```
166
173
 
167
174
  Every reply addressed to another agent in the network is delivered in turn until the
168
- conversation goes quiet. Messages sent to addresses outside the network are collected on
169
- `transcript.undelivered` rather than silently dropped:
175
+ conversation goes quiet. As on a live network, a reply carries the session of the message
176
+ it answers, so the whole conversation runs in one `ctx.session` (pass `session=` to choose
177
+ it). Sending to an agent you never added raises `KeyError`. Messages a handler sends to
178
+ addresses outside the network are collected on `transcript.undelivered` rather than
179
+ silently dropped:
170
180
 
171
181
  ```python
172
182
  transcript.assert_all_delivered() # fails if anything went to an unknown address
@@ -237,12 +247,18 @@ async def test_treasury_agent():
237
247
  chain.assert_called("eth_call")
238
248
  ```
239
249
 
240
- It patches whichever of `requests`, `httpx` and `aiohttp` are importable, so it works
241
- whether the agent uses web3.py or raw async HTTP, and it understands web3.py's
242
- JSON-encoded `data=` body as well as `json=`.
250
+ It patches `requests`, `httpx` and `aiohttp` where they are importable, plus `urllib`,
251
+ at the call every request through them passes, so it works whether the agent uses
252
+ web3.py or raw HTTP; the test suite drives web3.py's `HTTPProvider` and
253
+ `AsyncHTTPProvider` through it. It understands web3.py's JSON-encoded `data=` body as
254
+ well as `json=`. It does not cover `http.client` or `urllib3` used directly, or sockets
255
+ a handler opens itself.
243
256
 
244
257
  Supported: `eth_call` (BEP-20 `balanceOf`, `symbol`, `name`, `decimals`, `totalSupply`),
245
- `eth_getBalance`, `eth_getCode`, `eth_blockNumber`, `eth_chainId`, batched requests.
258
+ `eth_getBalance`, `eth_getCode`, `eth_blockNumber`, `eth_chainId`, `net_version`,
259
+ `eth_getTransactionCount`, batched requests. Two of these answer without being told:
260
+ `eth_getCode` returns `0x` (no code) for any address not registered with `add_token()`,
261
+ and `eth_getTransactionCount` always returns 0.
246
262
 
247
263
  Two deliberate refusals, both of which turn a silent pass into a loud failure:
248
264
 
@@ -251,11 +267,21 @@ Two deliberate refusals, both of which turn a silent pass into a loud failure:
251
267
  with pytest.raises(UnstubbedCall):
252
268
  ... # rather than quietly returning zero
253
269
 
254
- # any non-JSON-RPC HTTP from inside a handler
270
+ # any other HTTP from inside a handler: a price API, an LLM, a webhook
255
271
  with pytest.raises(NetworkCallBlocked):
256
272
  ... # rather than hitting a real API in CI
257
273
  ```
258
274
 
275
+ Agents wrap RPC reads in `try/except` so one bad call can't crash them, and that habit
276
+ would swallow a refusal and turn it back into a silent pass. So `deliver()` (and
277
+ `tick()`, `startup()`, `shutdown()`) re-raises any refusal the handler's own work made,
278
+ caught or not: in the handler, in the tasks it starts, and in `asyncio.to_thread()`.
279
+ Work the handler did not start is not charged to it, such as a delivery running
280
+ alongside it or the manifest upload that `include(proto, publish_manifest=True)` queues.
281
+ A refusal from a thread that carries no context (`loop.run_in_executor()`, a plain
282
+ `Thread`) fails every delivery running at that moment. `chain.refusals` keeps every
283
+ refusal either way.
284
+
259
285
  There's also a `bsc` fixture that gives you an installed double directly.
260
286
 
261
287
  ## pytest fixtures
@@ -274,7 +300,7 @@ def test_with_fixture(agent_harness, agent_network):
274
300
  |---|---|
275
301
  | `harness(agent)` | Wrap an agent. Swaps in in-memory storage and merges the internal protocol. |
276
302
  | `h.deliver(msg, sender=…, raise_errors=True)` | Route a message to its handler. Returns `Delivery`. |
277
- | `h.tick(only=None)` | Run `@on_interval` handlers once. |
303
+ | `h.tick(only=None)` | Run `@on_interval` (and `@on_schedule`) handlers once. |
278
304
  | `h.startup()` / `h.shutdown()` | Run `@on_event` handlers. |
279
305
  | `h.storage` | In-memory store, subscriptable. |
280
306
  | `h.handles(Model)` | Whether a handler is registered for a type. |
@@ -282,10 +308,10 @@ def test_with_fixture(agent_harness, agent_network):
282
308
  | `Delivery.reply(Model)` | The single reply of that type; raises otherwise. |
283
309
  | `Delivery.replies(Model, to=…)` | Replies of that type to the sender; `to=ANY` for any destination. |
284
310
  | `user_sender()` | A user (non-agent) address, for `allow_unverified` paths. |
285
- | `Delivery.error` / `.logs` | Handler exception and captured log records. |
311
+ | `Delivery.error` / `.logs` | Handler exception (or a refusal it caught) and captured log records. |
286
312
  | `Delivery.assert_replied_with` / `assert_silent` / `assert_no_errors` / `assert_reply_contract` | Chainable assertions. |
287
313
  | `AgentNetwork(*agents)` | Multi-agent network. |
288
- | `net.send(msg, to=…, sender=…, max_rounds=20)` | Play out a conversation. Returns `Transcript`. |
314
+ | `net.send(msg, to=…, sender=…, max_rounds=20, session=None)` | Play out a conversation in one session. Returns `Transcript`. |
289
315
  | `Transcript.of(Model)` / `.to(addr)` / `.undelivered` | Inspect what was exchanged. |
290
316
 
291
317
  ## Scope
@@ -296,6 +322,20 @@ signing, or on-chain settlement — those are integration concerns and mocking t
296
322
  give you false confidence. Keep a thin integration test on a real testnet for those, and
297
323
  use this for everything else.
298
324
 
325
+ `ctx.send_and_receive()` is not supported. Sends are recorded rather than delivered, so
326
+ no answer can reach the handler that is waiting for one; the harness raises
327
+ `NotImplementedError` rather than hand it `None`, and a handler that catches it still
328
+ fails its delivery.
329
+
330
+ The harness can't stop work an agent schedules on its own event loop.
331
+ `include(proto, publish_manifest=True)` queues an upload of the protocol's manifest to
332
+ Agentverse, and it runs whenever that loop runs, with or without the harness: for an
333
+ agent built inside an async test, as soon as the test yields to the loop. Pass
334
+ `publish_manifest=False` when you build agents for tests.
335
+
336
+ The [changelog](https://github.com/pgalyen1987/uagent-testkit/blob/main/CHANGELOG.md)
337
+ lists what each release fixed, and which fixes can fail a test that used to pass.
338
+
299
339
  ## Running the tests
300
340
 
301
341
  ```bash
@@ -37,14 +37,16 @@ records instead of transmitting. No sockets, no registration, no waiting.
37
37
  - **Handler exceptions are raised** rather than contained into a log.
38
38
  - **Storage is in-memory**, so state doesn't leak between tests via the JSON file the
39
39
  stock `KeyValueStore` writes to your working directory.
40
- - **Reply contracts are enforced** — if `@on_message(replies=Pong)` doesn't send a
41
- `Pong`, that's an assertion failure instead of a log line nobody reads.
40
+ - **Reply contracts are checked** — if `@on_message(replies=Pong)` sends neither a
41
+ `Pong` nor an `ErrorMessage`, `assert_reply_contract()` fails, and the error the
42
+ framework would log lands in `result.logs`, where `assert_no_errors()` sees it.
42
43
  - **Interval and lifecycle handlers run on demand**, so an `@on_interval(period=3600)`
43
44
  is testable without waiting an hour.
44
45
  - **Multi-agent conversations replay deterministically**, with a loop guard instead of
45
46
  a hung test.
46
47
  - **Agents that read BNB Chain are testable offline** — `ChainDouble` answers BEP-20
47
- and balance queries from state your test sets, and blocks any other outbound HTTP.
48
+ and balance queries from state your test sets, and blocks any other request made
49
+ through requests, httpx, aiohttp or urllib.
48
50
 
49
51
  ## Install
50
52
 
@@ -52,7 +54,7 @@ records instead of transmitting. No sockets, no registration, no waiting.
52
54
  pip install uagent-testkit
53
55
  ```
54
56
 
55
- Requires Python 3.10+ and `uagents>=0.22`. The pytest fixtures register automatically.
57
+ Requires Python 3.10+ and `uagents>=0.23`. The pytest fixtures register automatically.
56
58
 
57
59
  ## Testing one agent
58
60
 
@@ -92,11 +94,12 @@ async def test_ping():
92
94
  async def test_bad_input_is_handled():
93
95
  result = await h.deliver(Ping(text=""), raise_errors=False)
94
96
  assert isinstance(result.error, ValueError)
95
- assert "empty" in result.logs.errors[0]
97
+ assert "empty" in str(result.error)
96
98
  ```
97
99
 
98
100
  By default `deliver()` re-raises whatever the handler raised, so a broken handler fails
99
101
  the test loudly. Pass `raise_errors=False` when the failure is the thing under test.
102
+ Cancellation and `KeyboardInterrupt` are not handler failures, so they always propagate.
100
103
 
101
104
  ### Sender verification
102
105
 
@@ -117,6 +120,7 @@ async def test_strict_handler_refuses_users():
117
120
  ```python
118
121
  await h.startup() # runs @on_event("startup") handlers
119
122
  result = await h.tick() # runs @on_interval handlers once, ignoring period
123
+ # (and @on_schedule ones, on uagents 0.26+)
120
124
  result = await h.tick(only="heartbeat") # just one, by function name
121
125
  await h.shutdown()
122
126
  ```
@@ -136,8 +140,11 @@ async def test_conversation():
136
140
  ```
137
141
 
138
142
  Every reply addressed to another agent in the network is delivered in turn until the
139
- conversation goes quiet. Messages sent to addresses outside the network are collected on
140
- `transcript.undelivered` rather than silently dropped:
143
+ conversation goes quiet. As on a live network, a reply carries the session of the message
144
+ it answers, so the whole conversation runs in one `ctx.session` (pass `session=` to choose
145
+ it). Sending to an agent you never added raises `KeyError`. Messages a handler sends to
146
+ addresses outside the network are collected on `transcript.undelivered` rather than
147
+ silently dropped:
141
148
 
142
149
  ```python
143
150
  transcript.assert_all_delivered() # fails if anything went to an unknown address
@@ -208,12 +215,18 @@ async def test_treasury_agent():
208
215
  chain.assert_called("eth_call")
209
216
  ```
210
217
 
211
- It patches whichever of `requests`, `httpx` and `aiohttp` are importable, so it works
212
- whether the agent uses web3.py or raw async HTTP, and it understands web3.py's
213
- JSON-encoded `data=` body as well as `json=`.
218
+ It patches `requests`, `httpx` and `aiohttp` where they are importable, plus `urllib`,
219
+ at the call every request through them passes, so it works whether the agent uses
220
+ web3.py or raw HTTP; the test suite drives web3.py's `HTTPProvider` and
221
+ `AsyncHTTPProvider` through it. It understands web3.py's JSON-encoded `data=` body as
222
+ well as `json=`. It does not cover `http.client` or `urllib3` used directly, or sockets
223
+ a handler opens itself.
214
224
 
215
225
  Supported: `eth_call` (BEP-20 `balanceOf`, `symbol`, `name`, `decimals`, `totalSupply`),
216
- `eth_getBalance`, `eth_getCode`, `eth_blockNumber`, `eth_chainId`, batched requests.
226
+ `eth_getBalance`, `eth_getCode`, `eth_blockNumber`, `eth_chainId`, `net_version`,
227
+ `eth_getTransactionCount`, batched requests. Two of these answer without being told:
228
+ `eth_getCode` returns `0x` (no code) for any address not registered with `add_token()`,
229
+ and `eth_getTransactionCount` always returns 0.
217
230
 
218
231
  Two deliberate refusals, both of which turn a silent pass into a loud failure:
219
232
 
@@ -222,11 +235,21 @@ Two deliberate refusals, both of which turn a silent pass into a loud failure:
222
235
  with pytest.raises(UnstubbedCall):
223
236
  ... # rather than quietly returning zero
224
237
 
225
- # any non-JSON-RPC HTTP from inside a handler
238
+ # any other HTTP from inside a handler: a price API, an LLM, a webhook
226
239
  with pytest.raises(NetworkCallBlocked):
227
240
  ... # rather than hitting a real API in CI
228
241
  ```
229
242
 
243
+ Agents wrap RPC reads in `try/except` so one bad call can't crash them, and that habit
244
+ would swallow a refusal and turn it back into a silent pass. So `deliver()` (and
245
+ `tick()`, `startup()`, `shutdown()`) re-raises any refusal the handler's own work made,
246
+ caught or not: in the handler, in the tasks it starts, and in `asyncio.to_thread()`.
247
+ Work the handler did not start is not charged to it, such as a delivery running
248
+ alongside it or the manifest upload that `include(proto, publish_manifest=True)` queues.
249
+ A refusal from a thread that carries no context (`loop.run_in_executor()`, a plain
250
+ `Thread`) fails every delivery running at that moment. `chain.refusals` keeps every
251
+ refusal either way.
252
+
230
253
  There's also a `bsc` fixture that gives you an installed double directly.
231
254
 
232
255
  ## pytest fixtures
@@ -245,7 +268,7 @@ def test_with_fixture(agent_harness, agent_network):
245
268
  |---|---|
246
269
  | `harness(agent)` | Wrap an agent. Swaps in in-memory storage and merges the internal protocol. |
247
270
  | `h.deliver(msg, sender=…, raise_errors=True)` | Route a message to its handler. Returns `Delivery`. |
248
- | `h.tick(only=None)` | Run `@on_interval` handlers once. |
271
+ | `h.tick(only=None)` | Run `@on_interval` (and `@on_schedule`) handlers once. |
249
272
  | `h.startup()` / `h.shutdown()` | Run `@on_event` handlers. |
250
273
  | `h.storage` | In-memory store, subscriptable. |
251
274
  | `h.handles(Model)` | Whether a handler is registered for a type. |
@@ -253,10 +276,10 @@ def test_with_fixture(agent_harness, agent_network):
253
276
  | `Delivery.reply(Model)` | The single reply of that type; raises otherwise. |
254
277
  | `Delivery.replies(Model, to=…)` | Replies of that type to the sender; `to=ANY` for any destination. |
255
278
  | `user_sender()` | A user (non-agent) address, for `allow_unverified` paths. |
256
- | `Delivery.error` / `.logs` | Handler exception and captured log records. |
279
+ | `Delivery.error` / `.logs` | Handler exception (or a refusal it caught) and captured log records. |
257
280
  | `Delivery.assert_replied_with` / `assert_silent` / `assert_no_errors` / `assert_reply_contract` | Chainable assertions. |
258
281
  | `AgentNetwork(*agents)` | Multi-agent network. |
259
- | `net.send(msg, to=…, sender=…, max_rounds=20)` | Play out a conversation. Returns `Transcript`. |
282
+ | `net.send(msg, to=…, sender=…, max_rounds=20, session=None)` | Play out a conversation in one session. Returns `Transcript`. |
260
283
  | `Transcript.of(Model)` / `.to(addr)` / `.undelivered` | Inspect what was exchanged. |
261
284
 
262
285
  ## Scope
@@ -267,6 +290,20 @@ signing, or on-chain settlement — those are integration concerns and mocking t
267
290
  give you false confidence. Keep a thin integration test on a real testnet for those, and
268
291
  use this for everything else.
269
292
 
293
+ `ctx.send_and_receive()` is not supported. Sends are recorded rather than delivered, so
294
+ no answer can reach the handler that is waiting for one; the harness raises
295
+ `NotImplementedError` rather than hand it `None`, and a handler that catches it still
296
+ fails its delivery.
297
+
298
+ The harness can't stop work an agent schedules on its own event loop.
299
+ `include(proto, publish_manifest=True)` queues an upload of the protocol's manifest to
300
+ Agentverse, and it runs whenever that loop runs, with or without the harness: for an
301
+ agent built inside an async test, as soon as the test yields to the loop. Pass
302
+ `publish_manifest=False` when you build agents for tests.
303
+
304
+ The [changelog](https://github.com/pgalyen1987/uagent-testkit/blob/main/CHANGELOG.md)
305
+ lists what each release fixed, and which fixes can fail a test that used to pass.
306
+
270
307
  ## Running the tests
271
308
 
272
309
  ```bash