lighter.testing

Documentation for eth_defi.lighter.testing Python module.

Anvil-fork test helpers for the Lighter guard integration.

This module holds only the test-specific deployment helper; the library deployment and whitelisting come from eth_defi.lighter.deployment so production and tests share one code path.

See eth_defi/lighter/README-lighter-guard.md and tests/guard/test_guard_lighter_lagoon.py.

Functions

deploy_lighter_simple_vault(web3, deployer, ...)

Deploy SimpleVaultV0 with LighterLib linked (other libs zeroed).

register_lighter_account_on_anvil(web3, ...)

Anvil override: forge an L1 Lighter account registration for owner.

deploy_lighter_simple_vault(web3, deployer, asset_manager, owner, lighter_lib)

Deploy SimpleVaultV0 with LighterLib linked (other libs zeroed).

Mirrors the Hypercore test fixture: only the library under test gets a real address, the rest stay ZERO_ADDRESS from GUARD_LIBRARIES. The library itself is deployed via deploy_lighter_lib().

Parameters
Returns

The deployed SimpleVaultV0 contract.

Return type

web3.contract.contract.Contract

register_lighter_account_on_anvil(web3, owner, account_index, zk_lighter='0x3B4D794a66304F130a4Db8F2551B0070dfCf5ca7')

Anvil override: forge an L1 Lighter account registration for owner.

Calls bound to the caller’s registered account — withdraw and changePubKey — read masterAccountIndex = validateAndGetAccountIndexFromAddress(msg.sender) and revert AccountIsNotRegistered if the caller has no account. Registration normally happens off-chain (a Safe signature) plus an L2 state update, which cannot be reproduced on a fork. This writes ZkLighter’s addressToAccountIndex[owner] = account_index mapping slot directly with anvil_setStorageAt so those calls can be exercised end-to-end.

Parameters
  • web3 (web3.main.Web3) – Web3 connection (Anvil fork).

  • owner (Union[eth_typing.evm.HexAddress, str]) – Address to register (e.g. the vault’s Safe).

  • account_index (int) – Lighter account index to assign (must be non-zero and below MAX_ACCOUNT_INDEX).

  • zk_lighter (Union[eth_typing.evm.HexAddress, str]) – The ZkLighter L1 contract address.

Return type

None