Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions tests/test_control_transfer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ControllerInfo,
ControlTransferContext,
format_control_transfer_prompt,
format_control_transfer_report,
resolve_control_transfer_context,
)

Expand Down Expand Up @@ -271,13 +270,6 @@ def test_prompt(self) -> None:
self.assertIn("Two-step", prompt)
self.assertIn("a LOWER signing threshold. Effective once accepted.", prompt)

def test_report_links_every_controller(self) -> None:
report = format_control_transfer_report([self.CONTEXT], 1, {})
for address in (TARGET, YCHAD, EXECUTOR, EXEC_SAFE):
self.assertIn(f"https://etherscan.io/address/{address}", report)
self.assertIn("**2-of-4**", report)
self.assertIn("- **Two-step:** this call only nominates", report)

def test_labels_and_addresses_include_the_hop(self) -> None:
self.assertEqual(self.CONTEXT.labels, {YCHAD: "Safe 6-of-9", EXEC_SAFE: "Safe 2-of-4"})
self.assertEqual(self.CONTEXT.addresses, [TARGET, YCHAD, EXECUTOR, EXEC_SAFE])
Expand Down
24 changes: 0 additions & 24 deletions tests/test_infinifi_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
_resolve_whitelist,
_TokenCandidate,
format_infinifi_prompt,
format_infinifi_report,
resolve_infinifi_context,
)

Expand Down Expand Up @@ -185,15 +184,6 @@ def test_prompt_names_farm_and_drop_token(self) -> None:
self.assertIn("3,003,294.554623 USDC", result)
self.assertIn("Whitelisted ERC20 call target", result)

def test_report_links_all_context_addresses(self) -> None:
context = _resolved_context()
report = format_infinifi_report([context], 1, context.labels)
self.assertIn("**Farm:** New Silver 2 Senior", report)
self.assertIn(f"https://etherscan.io/address/{FARM}", report)
self.assertIn(f"https://etherscan.io/address/{DROP}", report)
self.assertIn("New Silver Series 2 DROP", report)
self.assertIn("Whitelisted call targets", report)


class TestReadToken(unittest.TestCase):
@patch.object(infinifi_context.ChainManager, "get_client")
Expand Down Expand Up @@ -262,20 +252,6 @@ def test_fetch_farm_records_empty_on_bad_response(self, _mock_fetch: MagicMock)


class TestFormattingEdgeCases(unittest.TestCase):
def test_report_omits_configured_tokens_section_when_empty(self) -> None:
context = InfinifiEscrowContext(
escrow_address=ESCROW,
farm_address=FARM,
farm_name="New Silver 2 Senior",
farm_slug="new-silver-senior",
accounting_asset=TokenContext(USDC, "USD Coin", "USDC", 6),
total_assets_raw=3_003_294_554_623,
configured_tokens=(),
)
report = format_infinifi_report([context], 1, context.labels)
self.assertIn("**Farm:** New Silver 2 Senior", report)
self.assertNotIn("Configured non-accounting ERC-20 targets", report)

@patch.object(infinifi_context, "_fetch_farm_records")
@patch.object(infinifi_context, "_read_token", return_value=None)
@patch.object(infinifi_context, "_read_escrow_state", return_value=_EscrowState(ESCROW, FARM, USDC, 1))
Expand Down
7 changes: 0 additions & 7 deletions tests/test_infinifi_farm_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
PendleDiscountContext,
SwapPairContext,
format_infinifi_farm_prompt,
format_infinifi_farm_report,
resolve_infinifi_farm_context,
)

Expand Down Expand Up @@ -205,11 +204,6 @@ def test_already_supported_asset_reverts(self) -> None:
(enable,) = _resolve([(SWAP_FARM, ENABLE_REUSD)], reusd_supported=True, reusd_oracle=ORACLE)
self.assertIn("is already supported, so the call reverts (InvalidAsset)", format_infinifi_farm_prompt([enable]))

def test_report_flags_the_missing_oracle(self) -> None:
enable, _pair = _resolve(BATCH)
report = format_infinifi_farm_report([enable], 1, {})
self.assertIn("**no Accounting oracle — reverts until one is set**", report)


class TestPendleDiscount(unittest.TestCase):
def test_no_pts_held_means_no_immediate_change(self) -> None:
Expand All @@ -227,7 +221,6 @@ def test_held_pts_change_reported_assets(self) -> None:
prompt = format_infinifi_farm_prompt([context])
self.assertIn("reported assets change immediately by 1,500 USDC", prompt)
self.assertIn("the farm is registered in FarmRegistry", prompt)
self.assertIn("assets() changes by `1,500 USDC`", format_infinifi_farm_report([context], 1, {}))

def test_add_farms_earlier_in_the_batch_registers_it(self) -> None:
(context,) = _resolve([(REGISTRY, ADD_FARM), (PENDLE_FARM, DISCOUNT)])
Expand Down
9 changes: 1 addition & 8 deletions tests/test_infinifi_oracle_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
FeedDetails,
OracleAssignmentContext,
format_infinifi_oracle_prompt,
format_infinifi_oracle_report,
resolve_infinifi_oracle_context,
)

Expand Down Expand Up @@ -87,12 +86,6 @@ def test_feed_identity_and_freshness_rule_are_stated(self) -> None:
self.assertIn("price() reverts (StalePrice) once the feed is older than the heartbeat of 48h", prompt)
self.assertIn("The wrapper's name refers to the AggregatorV3 interface it reads", prompt)

def test_report_lists_the_feed(self) -> None:
(context,) = _resolve()
report = format_infinifi_oracle_report([context], 1, {})
self.assertIn("= `1.1053024341839888` reference units", report)
self.assertIn('"reUSD NAV / USD"; heartbeat `48h`, updated 12.4h before this alert', report)

def test_oracle_without_a_feed_still_renders_its_price(self) -> None:
(context,) = _resolve(with_feed=False)
self.assertIsNone(context.feed)
Expand All @@ -101,7 +94,7 @@ def test_oracle_without_a_feed_still_renders_its_price(self) -> None:
def test_usdc_scale_reads_as_parity(self) -> None:
# IOracle convention: a 6-decimal stable at parity is quoted at 1e30.
context = OracleAssignmentContext(ACCOUNTING, USDC, "USDC", 6, ORACLE, 10**30)
self.assertIn("= `1` reference units", format_infinifi_oracle_report([context], 1, {}))
self.assertEqual(context.unit_price_text, "1")

def test_removing_an_oracle_is_not_priced(self) -> None:
call = _call("setOracle", ("address", REUSD), ("address", ZERO_ADDRESS))
Expand Down
6 changes: 0 additions & 6 deletions tests/test_infinifi_outland_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
OutlandMessageContext,
RouteConfig,
format_outland_prompt,
format_outland_report,
resolve_outland_context,
)

Expand Down Expand Up @@ -138,7 +137,6 @@ def test_unconfigured_route_is_not_live(self) -> None:
prompt = format_outland_prompt(contexts)
self.assertIn("NOT configured", prompt)
self.assertIn("route is not live after this batch", prompt)
self.assertIn("**not configured**", format_outland_report(contexts, 1, {}))

def test_configured_route_names_the_peer(self) -> None:
contexts = self._resolve([_call("setCctpDomain", ("uint256", 143), ("uint32", 15))], (PEER, 200_000, 99))
Expand Down Expand Up @@ -171,15 +169,11 @@ def test_reconfiguring_a_live_route_reports_the_new_peer_not_the_old(self) -> No
self.assertIn(f"to peer {NEW_PEER}, gas limit 300,000", prompt)
self.assertIn(f"Before the batch: peer {PEER}", prompt)
self.assertNotIn("unchanged", prompt)
report = format_outland_report(contexts, 1, {})
self.assertIn(f"set by this batch — peer [`{NEW_PEER}`]", report)
self.assertIn(f"(was peer [`{PEER}`]", report)
self.assertEqual(contexts[0].addresses, [CONNECTOR, PEER, NEW_PEER])

def test_clearing_a_live_route_is_flagged(self) -> None:
contexts = self._resolve([self._set_configuration(ZERO_ADDRESS, 0, 0)], (PEER, 200_000, 99))
self.assertIn("this batch CLEARS the route", format_outland_prompt(contexts))
self.assertIn("**cleared** by this batch", format_outland_report(contexts, 1, {}))

def test_last_configuration_for_a_chain_wins(self) -> None:
calls = [self._set_configuration(PEER, 99, 200_000), self._set_configuration(NEW_PEER, 99, 300_000)]
Expand Down
8 changes: 0 additions & 8 deletions tests/test_llm_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,6 @@ def test_sections_in_order(self) -> None:
self.assertLess(report.index("## Analysis"), report.index("## Call Flow"))
self.assertLess(report.index("## Call Flow"), report.index("## Reference"))

def test_protocol_context_is_deterministic_section_after_call_flow(self) -> None:
ctx = _add_farms_ctx(protocol_context="- **Farm:** New Silver 2 Senior", related_addresses=[DROP])
report = build_report("Updates the rate.", "Long analysis.", ctx, "LOW")
self.assertIn("## Protocol Context\n\n- **Farm:** New Silver 2 Senior", report)
self.assertLess(report.index("## Analysis"), report.index("## Call Flow"))
self.assertLess(report.index("## Call Flow"), report.index("## Protocol Context"))
self.assertLess(report.index("## Protocol Context"), report.index("## Reference"))

def test_metadata_header(self) -> None:
report = build_report("Summary.", "Analysis.", _add_farms_ctx(label_address=TIMELOCK), "HIGH")
self.assertIn("- **Protocol:** INFINIFI", report)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_pendle_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ def test_upgrade_includes_scope_controls_and_route_semantics(boundaries: Boundar
assert "SwapType.ODOS" not in after
assert "assert(false)" in after
assert "_transferOut(tokenOut, msg.sender, netOut)" in after
explorer = "etherscan.io" if chain_id == 1 else "arbiscan.io"
for address in (PENDLE_SWAP, OLD, NEW, OWNER):
assert address in resolved.addresses
assert f"https://{explorer}/address/{address}" in resolved.report
assert resolved.labels[PENDLE_SWAP] == "PendleSwap"
contract_call = boundaries[2].return_value.eth.contract.call_args
assert contract_call.kwargs["address"] == PENDLE_SWAP
Expand Down
13 changes: 0 additions & 13 deletions tests/test_permission_grant_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from utils.llm.control_transfer_context import ControllerInfo
from utils.llm.permission_grant_context import (
format_permission_grant_prompt,
format_permission_grant_report,
resolve_permission_grant_context,
)
from utils.verified_contract import VerifiedContract
Expand Down Expand Up @@ -254,9 +253,6 @@ def test_keeper_grant_lists_scope_and_holder_forwarders(self, mock_client: Magic
self.assertIn("forwardCall(address,bytes) [onlyKeepers]", prompt)
mock_client.return_value.get_contract.assert_not_called() # a mapping has no member getter

report = format_permission_grant_report([context], 1, {})
self.assertIn("`forwardCall(address,bytes)` (modifier onlyKeepers) — **arbitrary call**", report)

def test_restricted_forward_is_not_reported_as_arbitrary(self, mock_client: MagicMock, *_mocks: MagicMock) -> None:
call = DecodedCall("setKeeper", "setKeeper(address,bool)", [("address", OPS_EOA), ("bool", True)])
(context,) = resolve_permission_grant_context("YEARN_MS", 1, [(HARVESTER, call)])
Expand All @@ -265,19 +261,13 @@ def test_restricted_forward_is_not_reported_as_arbitrary(self, mock_client: Magi
self.assertIn("RESTRICTED FORWARD: forward(address,bytes) checks", prompt)
self.assertIn('`require(_target == strategy, "!strategy")`', prompt)
self.assertIn("`require(bytes4(_data) == IStrategy.report.selector", prompt)
report = format_permission_grant_report([context], 1, {})
self.assertNotIn("every permission", report)
self.assertIn("forwards calls, restricted by", report)

def test_denylist_entry_blocks_instead_of_granting(self, mock_client: MagicMock, *_mocks: MagicMock) -> None:
call = DecodedCall("setBlocked", "setBlocked(address,bool)", [("address", OPS_EOA), ("bool", True)])
(context,) = resolve_permission_grant_context("YEARN_MS", 1, [(DENY_VAULT, call)])
self.assertIn(f"BLOCKS {OPS_EOA}", context.lines()[0])
self.assertIn("gates withdraw(uint256)", context.lines()[1])
self.assertIn("a denylist: listed callers are refused", context.lines()[1])
report = format_permission_grant_report([context], 1, {})
self.assertIn("**Entry points it closes:**", report)
self.assertNotIn("opens", report)

def test_executor_removals_carry_membership_through_the_batch(
self, mock_client: MagicMock, *_mocks: MagicMock
Expand Down Expand Up @@ -319,9 +309,6 @@ def test_a_batch_states_scope_and_members_once(self, mock_client: MagicMock, *_m
self.assertIn(f" 10. removeExecutor(address) REVOKES {executors[-1]}.", prompt)
# Each change adds a line, not another copy of the scope and membership: linear, not quadratic.
self.assertLess(len(prompt), 2_800)
report = format_permission_grant_report(contexts, 1, {})
self.assertEqual(report.count("**Entry points it closes:**"), 1)
self.assertEqual(report.count("**Members after:**"), 1)

def test_ignores_non_setters_without_source_lookups(self, mock_client: MagicMock, *_mocks: MagicMock) -> None:
call = DecodedCall("transfer", "transfer(address,uint256)", [("address", OPS_EOA), ("uint256", 1)])
Expand Down
23 changes: 3 additions & 20 deletions tests/test_protocol_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def _adapter(name: str, contexts: list[_FakeContext]) -> _Adapter:
name=name,
resolve=lambda protocol, chain_id, calls: contexts,
format_prompt=lambda ctxs: f"{name} prompt",
format_report=lambda ctxs, chain_id, labels: f"{name} report",
)


Expand All @@ -43,7 +42,6 @@ def test_adapters_are_combined(self) -> None:
resolved = resolve_protocol_context("3JANE", 1, [(TARGET, _call())])

self.assertEqual(resolved.prompt, "alpha prompt\n\nbeta prompt")
self.assertEqual(resolved.report, "alpha report\n\nbeta report")
self.assertEqual(resolved.addresses, [TARGET, TOKEN])
self.assertEqual(resolved.labels, {TARGET: "Config", TOKEN: "Token"})

Expand All @@ -52,14 +50,13 @@ def test_empty_adapter_contributes_nothing(self) -> None:
resolved = resolve_protocol_context("3JANE", 1, [(TARGET, _call())])

self.assertEqual(resolved.prompt, "")
self.assertEqual(resolved.report, "")
self.assertEqual(resolved.addresses, [])

def test_failing_adapter_does_not_block_the_others(self) -> None:
def explode(protocol: str, chain_id: int, calls: list) -> list:
raise RuntimeError("etherscan down")

broken = _Adapter("broken", explode, lambda c: "x", lambda contexts, chain_id, labels: "x")
broken = _Adapter("broken", explode, lambda c: "x")
adapters = (broken, _adapter("beta", [_FakeContext([TOKEN], {})]))
with patch.object(protocol_context, "_ADAPTERS", adapters):
resolved = resolve_protocol_context("3JANE", 1, [(TARGET, _call())])
Expand All @@ -74,28 +71,14 @@ def explode(contexts: object) -> str:
"broken",
lambda p, c, t: [_FakeContext([TOKEN], {TOKEN: "Broken"})],
explode,
lambda contexts, chain_id, labels: "x",
)
adapters = (broken, _adapter("alpha", [_FakeContext([TARGET], {TARGET: "Timelock"})]))
with patch.object(protocol_context, "_ADAPTERS", adapters):
resolved = resolve_protocol_context("x", 1, [(TARGET, _call())])
self.assertEqual((resolved.prompt, resolved.report), ("alpha prompt", "alpha report"))
# Nothing from the adapter that failed to render reaches the report.
self.assertEqual(resolved.prompt, "alpha prompt")
# Nothing from the adapter that failed to render is kept.
self.assertEqual((resolved.addresses, resolved.labels), ([TARGET], {TARGET: "Timelock"}))

def test_existing_labels_reach_the_report_renderer(self) -> None:
seen: dict[str, str] = {}

def capture(contexts: list, chain_id: int, labels: dict[str, str]) -> str:
seen.update(labels)
return "report"

adapter = _Adapter("alpha", lambda p, c, t: [_FakeContext([TOKEN], {TOKEN: "Token"})], lambda c: "p", capture)
with patch.object(protocol_context, "_ADAPTERS", (adapter,)):
resolve_protocol_context("3JANE", 1, [(TARGET, _call())], {TARGET: "Timelock"})

self.assertEqual(seen, {TARGET: "Timelock", TOKEN: "Token"})

def test_registered_adapters_cover_the_known_protocols(self) -> None:
self.assertEqual(
{adapter.name for adapter in protocol_context._ADAPTERS},
Expand Down
29 changes: 0 additions & 29 deletions tests/test_threejane_account_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
SupplyCapExemptContext,
TokenUnit,
format_account_prompt,
format_account_report,
resolve_account_contexts,
)

Expand Down Expand Up @@ -176,12 +175,6 @@ def test_prompt_states_units_and_raw_value(self) -> None:
self.assertIn("Commitment to remove: 499,999.999986 USDC (raw 499999999986)", prompt)
self.assertIn("State is read at scheduling time", prompt)

def test_report_links_vault_user_and_assets(self) -> None:
report = format_account_report(_bounce(), 1, {VAULT: "LCCVault"})
for address in (VAULT, USER, USDC.address, WAEUSDC.address):
self.assertIn(f"https://etherscan.io/address/{address}", report)
self.assertIn("`499,999.999986 USDC`", report)

def test_phase_blockers_come_first(self) -> None:
"""bounceCommitment reverts InvalidPhase during a pending auction or an unsettled call."""
self.assertIn("shortfall auction is pending", _bounce(auction_pending=True).blocker())
Expand Down Expand Up @@ -289,7 +282,6 @@ def test_purpose_line_states_the_documented_intent(self) -> None:
self.assertIn("per-wallet right to grow USD3 past the cap", line)
self.assertIn("adds no credit exposure", line)
self.assertEqual(format_account_prompt(_exemption()).count("Why it matters"), 1)
self.assertEqual(format_account_report(_exemption(), 1, {}).count("Why it matters"), 1)

def test_supply_line_above_cap_blocks_non_exempt(self) -> None:
line = _exemption().supply_line()
Expand Down Expand Up @@ -317,23 +309,6 @@ def test_prompt_states_shared_facts_once_and_lists_every_account(self) -> None:
self.assertIn(f"- {SAFE} (contract): true → false; ringFenceConduit false; holds 85,185.325821 USD3", prompt)
self.assertEqual(sum(1 for line in prompt.splitlines() if line.startswith("- 0x")), 4)

def test_report_tabulates_accounts_with_links(self) -> None:
report = format_account_report(self._revocation(), 1, {USD3_ADDRESS: "USD3"})
self.assertEqual(report.count("What the flag does"), 1)
self.assertIn("| # | Account | Type | supplyCapExempt | ringFenceConduit | USD3 balance |", report)
self.assertIn(f"EOA, EIP-7702 → [`{DELEGATE}`](https://etherscan.io/address/{DELEGATE})", report)
for address in (OTHER, DELEGATED, SAFE, USER):
self.assertIn(f"https://etherscan.io/address/{address}", report)
self.assertIn("`1,271,316.91341 USD3`", report)

def test_report_flags_out_of_step_accounts(self) -> None:
conduit_revoke = _account(proposed_exempt=False, current_exempt=True, ring_fence_conduit=True)
self.assertIn(
"⚠️ exemption revoked while ringFenceConduit stays true",
format_account_report(_exemption(conduit_revoke), 1, {}),
)
self.assertNotIn("⚠️", format_account_report(_exemption(), 1, {}))

def test_history_appears_only_when_read(self) -> None:
account = _account(address=REGRANTED, last_change=ExemptionChange(26091398, False, REVOKE_TX))
context = _exemption(account, history_read=True, exempt_before=5, exempt_conduits_before=2)
Expand All @@ -342,13 +317,9 @@ def test_history_appears_only_when_read(self) -> None:
"Exempt before this transaction (replayed from SupplyCapExemptUpdated): 5 account(s), 2 of them", prompt
)
self.assertIn(f"re-grants an exemption revoked at block 26091398 (tx {REVOKE_TX})", prompt)
report = format_account_report(context, 1, {})
self.assertIn("| USD3 balance | Last change |", report)
self.assertIn(f"set false at [block 26091398](https://etherscan.io/tx/{REVOKE_TX})", report)

unread = _exemption(account)
self.assertNotIn("re-grants", format_account_prompt(unread))
self.assertNotIn("Last change", format_account_report(unread, 1, {}))

def test_addresses_include_every_account(self) -> None:
self.assertEqual(self._revocation().addresses, [USD3_ADDRESS, OTHER, DELEGATED, SAFE, USER])
Expand Down
Loading
Loading