testing.gmx_lagoon
Documentation for eth_defi.testing.gmx_lagoon Python module.
Reusable Lagoon/Safe deployment baselines for fixed-block GMX tests.
The deployment factories retain the original oracle-first ordering and real contract interactions. Callers own fork lifetime and EVM snapshot isolation.
Module Attributes
Token addresses on Arbitrum. |
|
Impersonated token holders used to fund the Safe. |
Functions
Reuse a deployed baseline only for the exact live fork generation. |
|
|
Initialise a Lagoon GMX test environment on a fixed-block fork. |
Read positions from the actual fork instead of public-chain indexers. |
|
Reuse one actual token-list response per chain during a fork test. |
|
|
Restore a deployed GMX baseline with fresh Python adapters per test. |
Classes
Components for real Lagoon/Safe and GMX fork integration checks. |
- WETH_ARBITRUM = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1'
Token addresses on Arbitrum.
- USDC_WHALE = '0xEe7aE85f2Fe2239E27D9c1E23fFFe168D63b4055'
Impersonated token holders used to fund the Safe.
- class LagoonGMXForkEnv
Bases:
objectComponents for real Lagoon/Safe and GMX fork integration checks.
Hold deployed addresses and fresh Python adapters together. Callers own process lifetime and must isolate EVM mutations between trading checks.
- web3: web3.main.Web3
Fresh chain connection.
- vault: eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault
Deployed Lagoon vault adapter.
- lagoon_wallet: eth_defi.gmx.lagoon.wallet.LagoonGMXTradingWallet
Wallet wrapping Safe transactions.
- asset_manager_wallet: eth_defi.hotwallet.HotWallet
Signer with a synchronised nonce.
- gmx_config: eth_defi.gmx.config.GMXConfig
Configuration pointing at the Safe.
- trading: eth_defi.gmx.trading.GMXTrading
Order construction and execution adapter.
- positions: eth_defi.gmx.core.open_positions.GetOpenPositions
Position reader.
- anvil_launch: eth_defi.provider.anvil.AnvilLaunch
Fork process owned by the caller.
- deploy_info: eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment
Result of the underlying deployment.
- __init__(web3, vault, lagoon_wallet, asset_manager_wallet, gmx_config, trading, positions, anvil_launch, deploy_info)
- Parameters
web3 (web3.main.Web3) –
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) –
lagoon_wallet (eth_defi.gmx.lagoon.wallet.LagoonGMXTradingWallet) –
asset_manager_wallet (eth_defi.hotwallet.HotWallet) –
gmx_config (eth_defi.gmx.config.GMXConfig) –
trading (eth_defi.gmx.trading.GMXTrading) –
positions (eth_defi.gmx.core.open_positions.GetOpenPositions) –
anvil_launch (eth_defi.provider.anvil.AnvilLaunch) –
deploy_info (eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment) –
- Return type
None
- create_lagoon_gmx_fork_env(anvil_launch, *, forward_eth=False)
Initialise a Lagoon GMX test environment on a fixed-block fork.
Configure the mock oracle before deployment, then fund the Safe and create fresh Python adapters. Deployment installs the GMX collateral approvals. Fee-forwarding variants leave the Safe without native ETH so the manager must fund execution fees.
- Parameters
anvil_launch (eth_defi.provider.anvil.AnvilLaunch) – Live fixed-block Anvil process with the token whales unlocked.
forward_eth (bool) – Enable manager-funded execution fees and leave the Safe at zero ETH.
- Returns
Deployed environment. Caller must restore EVM state between sharers.
- Return type
- create_cached_lagoon_gmx_fork_env(anvil_launch, baselines)
Reuse a deployed baseline only for the exact live fork generation.
Check deployed code on hits in case another snapshot removed the baseline. A recycled fork can reuse its URL and eventually even its PID. Include the process creation time so stale contract addresses cannot survive a restart. Callers must snapshot EVM state and reset Python-side state for each test.
- Parameters
anvil_launch (eth_defi.provider.anvil.AnvilLaunch) – Liveness-checked pooled fork process.
baselines (dict[tuple[int, float], eth_defi.testing.gmx_lagoon.LagoonGMXForkEnv]) – Per-worker deployment cache, retaining only the current generation.
- Returns
Existing or newly deployed baseline for this fork.
- Return type
- gmx_fork_token_metadata()
Reuse one actual token-list response per chain during a fork test.
Token symbols and decimals do not change when local orders execute. Fetch from the real endpoint once in this context and return independent copies to callers. Exceptions are not cached; leaving the context restores normal provider behaviour. Provider-specific tests use the unchanged live path.
- Returns
Context retaining metadata only until this fork test finishes.
- Return type
collections.abc.Iterator[None]
- gmx_fork_position_reads()
Read positions from the actual fork instead of public-chain indexers.
Public REST/GraphQL services cannot index transactions on a private Anvil fork. Return empty results from those two tiers so the unchanged production reader takes its real RPC fallback. Market/oracle APIs and onchain contract calls remain live. Provider integration tests separately exercise the tiers.
- Returns
Context with restored reader methods on exit.
- Return type
collections.abc.Iterator[None]
- isolated_lagoon_gmx_fork_env(launch, baselines)
Restore a deployed GMX baseline with fresh Python adapters per test.
Snapshot after deployment, then discard the process/cache if strict restore fails. Callers obtain the current launch from the pool and co-locate sharers using a matching isolation group. Use real RPC position reads because public indexers cannot observe private-fork transactions.
- Parameters
launch (eth_defi.provider.anvil.AnvilLaunch) – Liveness-checked pooled process for this mutation group.
baselines (dict[tuple[int, float], eth_defi.testing.gmx_lagoon.LagoonGMXForkEnv]) – Per-group deployment cache keyed by actual process generation.
- Returns
Fresh environment isolated from earlier EVM and Python mutations.
- Return type
collections.abc.Iterator[eth_defi.testing.gmx_lagoon.LagoonGMXForkEnv]
See Anvil documentation.