@morpho-org/morpho-test 4.0.5 → 4.1.0-next.0

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.
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  ## Overview
25
25
 
26
- Framework-agnostic extension of [`@morpho-org/blue-sdk`](../blue-sdk/) that exports test fixtures useful for E2E tests on forks.
26
+ Framework-agnostic extension of [`@morpho-org/blue-sdk`](../blue-sdk/) that exports test fixtures useful for E2E tests on forks, and registry-driven helpers (`getE2eRuns`, `getE2eMatrix`) that decide which chains an E2E scenario runs on from the deployments it requires.
27
27
 
28
28
  ## Installation
29
29
 
@@ -0,0 +1,31 @@
1
+ import type { Address, Hex } from "viem";
2
+ /** Fork-only ERC-20 address used when a chain has no registered wNative. */
3
+ export declare const E2E_ASSET: Address;
4
+ /** Canonical mainnet WETH9 runtime bytecode, without constructor arguments. */
5
+ export declare const E2E_ASSET_BYTECODE: Hex;
6
+ /**
7
+ * WETH9 constructor storage for the fallback token's name, symbol, and decimals.
8
+ */
9
+ export declare const E2E_ASSET_STORAGE: readonly {
10
+ readonly slot: Hex;
11
+ readonly value: Hex;
12
+ }[];
13
+ /**
14
+ * Returns a chain's registered wNative or the fallback token and whether callers must install code.
15
+ *
16
+ * @param chainId - Chain to select the asset for.
17
+ * @returns The token address and whether the caller must install its code, as `requiresInstall`.
18
+ * @throws {UnsupportedChainIdError} When `chainId` has no address registry in
19
+ * `@morpho-org/morpho-ts`.
20
+ * @example
21
+ * ```ts
22
+ * import { ChainId } from "@morpho-org/morpho-ts";
23
+ * import { E2E_ASSET, getE2eAsset } from "@morpho-org/morpho-test";
24
+ *
25
+ * getE2eAsset(ChainId.ArcMainnet); // { address: E2E_ASSET, requiresInstall: true }
26
+ * ```
27
+ */
28
+ export declare const getE2eAsset: (chainId: number) => {
29
+ readonly address: Address;
30
+ readonly requiresInstall: boolean;
31
+ };
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getE2eAsset = exports.E2E_ASSET_STORAGE = exports.E2E_ASSET_BYTECODE = exports.E2E_ASSET = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ /** Fork-only ERC-20 address used when a chain has no registered wNative. */
6
+ exports.E2E_ASSET = "0xE2E0000000000000000000000000000000000003";
7
+ /** Canonical mainnet WETH9 runtime bytecode, without constructor arguments. */
8
+ exports.E2E_ASSET_BYTECODE = `0x${[
9
+ "6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ff",
10
+ "ffffff16806306fdde03146100b9578063095ea7b31461014757806318160ddd146101a157806323b872dd146101ca578063",
11
+ "2e1a7d4d14610243578063313ce5671461026657806370a082311461029557806395d89b41146102e2578063a9059cbb1461",
12
+ "0370578063d0e30db0146103ca578063dd62ed3e146103d4575b6100b7610440565b005b34156100c457600080fd5b6100cc",
13
+ "6104dd565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561010c57",
14
+ "80820151818401526020810190506100f1565b50505050905090810190601f16801561013957808203805160018360200361",
15
+ "01000a031916815260200191505b509250505060405180910390f35b341561015257600080fd5b610187600480803573ffff",
16
+ "ffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061057b565b6040518082151515",
17
+ "15815260200191505060405180910390f35b34156101ac57600080fd5b6101b461066d565b60405180828152602001915050",
18
+ "60405180910390f35b34156101d557600080fd5b610229600480803573ffffffffffffffffffffffffffffffffffffffff16",
19
+ "90602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061",
20
+ "068c565b604051808215151515815260200191505060405180910390f35b341561024e57600080fd5b610264600480803590",
21
+ "60200190919050506109d9565b005b341561027157600080fd5b610279610b05565b604051808260ff1660ff168152602001",
22
+ "91505060405180910390f35b34156102a057600080fd5b6102cc600480803573ffffffffffffffffffffffffffffffffffff",
23
+ "ffff16906020019091905050610b18565b6040518082815260200191505060405180910390f35b34156102ed57600080fd5b",
24
+ "6102f5610b30565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561",
25
+ "033557808201518184015260208101905061031a565b50505050905090810190601f16801561036257808203805160018360",
26
+ "20036101000a031916815260200191505b509250505060405180910390f35b341561037b57600080fd5b6103b06004808035",
27
+ "73ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610bce565b6040518082",
28
+ "15151515815260200191505060405180910390f35b6103d2610440565b005b34156103df57600080fd5b61042a6004808035",
29
+ "73ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffff",
30
+ "ffff16906020019091905050610be3565b6040518082815260200191505060405180910390f35b34600360003373ffffffff",
31
+ "ffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001",
32
+ "600020600082825401925050819055503373ffffffffffffffffffffffffffffffffffffffff167fe1fffcc4923d04b559f4",
33
+ "d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c346040518082815260200191505060405180910390a2565b60008054",
34
+ "600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182",
35
+ "8054600181600116156101000203166002900480156105735780601f10610548576101008083540402835291602001916105",
36
+ "73565b820191906000526020600020905b81548152906001019060200180831161055657829003601f168201915b50505050",
37
+ "5081565b600081600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffff",
38
+ "ffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffff",
39
+ "ffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffff",
40
+ "ffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd03",
41
+ "14c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60003073",
42
+ "ffffffffffffffffffffffffffffffffffffffff1631905090565b600081600360008673ffffffffffffffffffffffffffff",
43
+ "ffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515156106",
44
+ "dc57600080fd5b3373ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffff",
45
+ "ffff16141580156107b457507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6004600086",
46
+ "73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190",
47
+ "815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffff",
48
+ "ffffffff1681526020019081526020016000205414155b156108cf5781600460008673ffffffffffffffffffffffffffffff",
49
+ "ffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffff",
50
+ "ffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001",
51
+ "600020541015151561084457600080fd5b81600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffff",
52
+ "ffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffff",
53
+ "ffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250",
54
+ "50819055505b81600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffff",
55
+ "ffffffffff1681526020019081526020016000206000828254039250508190555081600360008573ffffffffffffffffffff",
56
+ "ffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082",
57
+ "825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffff",
58
+ "ffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405180828152602001",
59
+ "91505060405180910390a3600190509392505050565b80600360003373ffffffffffffffffffffffffffffffffffffffff16",
60
+ "73ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610a2757600080fd5b",
61
+ "80600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16",
62
+ "8152602001908152602001600020600082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff16",
63
+ "6108fc829081150290604051600060405180830381858888f193505050501515610ab457600080fd5b3373ffffffffffffff",
64
+ "ffffffffffffffffffffffffff167f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65826040",
65
+ "518082815260200191505060405180910390a250565b600260009054906101000a900460ff1681565b600360205280600052",
66
+ "60406000206000915090505481565b60018054600181600116156101000203166002900480601f0160208091040260200160",
67
+ "40519081016040528092919081815260200182805460018160011615610100020316600290048015610bc65780601f10610b",
68
+ "9b57610100808354040283529160200191610bc6565b820191906000526020600020905b8154815290600101906020018083",
69
+ "11610ba957829003601f168201915b505050505081565b6000610bdb33848461068c565b905092915050565b600460205281",
70
+ "60005260406000206020528060005260406000206000915091505054815600a165627a7a72305820deb4c2ccab3c2fdca32a",
71
+ "b3f46728389c2fe2c165d5fafa07661e4e004f6c344a0029",
72
+ ].join("")}`;
73
+ /**
74
+ * WETH9 constructor storage for the fallback token's name, symbol, and decimals.
75
+ */
76
+ exports.E2E_ASSET_STORAGE = [
77
+ {
78
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000000",
79
+ value: "0x577261707065642045746865720000000000000000000000000000000000001a",
80
+ },
81
+ {
82
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000001",
83
+ value: "0x5745544800000000000000000000000000000000000000000000000000000008",
84
+ },
85
+ {
86
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000002",
87
+ value: "0x0000000000000000000000000000000000000000000000000000000000000012",
88
+ },
89
+ ];
90
+ /**
91
+ * Returns a chain's registered wNative or the fallback token and whether callers must install code.
92
+ *
93
+ * @param chainId - Chain to select the asset for.
94
+ * @returns The token address and whether the caller must install its code, as `requiresInstall`.
95
+ * @throws {UnsupportedChainIdError} When `chainId` has no address registry in
96
+ * `@morpho-org/morpho-ts`.
97
+ * @example
98
+ * ```ts
99
+ * import { ChainId } from "@morpho-org/morpho-ts";
100
+ * import { E2E_ASSET, getE2eAsset } from "@morpho-org/morpho-test";
101
+ *
102
+ * getE2eAsset(ChainId.ArcMainnet); // { address: E2E_ASSET, requiresInstall: true }
103
+ * ```
104
+ */
105
+ const getE2eAsset = (chainId) => {
106
+ const { wNative } = (0, blue_sdk_1.getChainAddresses)(chainId);
107
+ return wNative == null
108
+ ? { address: exports.E2E_ASSET, requiresInstall: true }
109
+ : { address: wNative, requiresInstall: false };
110
+ };
111
+ exports.getE2eAsset = getE2eAsset;
@@ -0,0 +1,2 @@
1
+ export * from "./asset.js";
2
+ export * from "./registryMatrix.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./asset.js"), exports);
18
+ __exportStar(require("./registryMatrix.js"), exports);
@@ -0,0 +1,173 @@
1
+ import { type AddressLabel, type AddressRegistry, type DeploymentRegistry } from "@morpho-org/morpho-ts";
2
+ import type { Address } from "viem";
3
+ /** An E2E scenario family and the registry labels it needs on a chain. */
4
+ export interface E2eScenario {
5
+ /** Family name used in test titles and filters, e.g. `"vaultV2"`. */
6
+ readonly name: string;
7
+ /** Registry labels that must all be registered on a chain for the family to run there. */
8
+ readonly requires: readonly AddressLabel[];
9
+ }
10
+ /**
11
+ * Minimum fork block per chain. A scenario forks at the highest of this block and the registered
12
+ * deployment blocks of its required labels, so a deployment with a registered block never forks
13
+ * before it exists. Required deployments without a registered block are listed in
14
+ * `E2eTarget.undatedDeployments` for the harness to check onchain. A chain without an entry here
15
+ * can still run when every required label has a registered deployment block.
16
+ */
17
+ export declare const E2E_FORK_BLOCKS: {
18
+ readonly [chainId: number]: bigint;
19
+ };
20
+ /** A required deployment and its registered address. */
21
+ export interface E2eDeployment {
22
+ readonly label: AddressLabel;
23
+ readonly address: Address;
24
+ }
25
+ /** Where an eligible scenario runs on one chain. */
26
+ export interface E2eTarget {
27
+ readonly chainId: number;
28
+ /** `ChainId` enum key, e.g. `"BaseMainnet"`, or `Chain<id>` for an unnamed chain. */
29
+ readonly chainName: string;
30
+ readonly forkBlockNumber: bigint;
31
+ /**
32
+ * Required deployments with no registered deployment block. The fork block does not account for
33
+ * them, so the harness must check they have code at `forkBlockNumber`.
34
+ */
35
+ readonly undatedDeployments: readonly E2eDeployment[];
36
+ }
37
+ /** Whether a scenario can run on a chain, and why not when it can't. */
38
+ export type E2eEligibility = {
39
+ readonly status: "eligible";
40
+ readonly target: E2eTarget;
41
+ } | {
42
+ readonly status: "missingDeployments";
43
+ readonly chainId: number;
44
+ readonly missing: readonly AddressLabel[];
45
+ } | {
46
+ readonly status: "missingForkBlock";
47
+ readonly chainId: number;
48
+ };
49
+ /** Registries an eligibility check reads; defaults to the canonical ones. */
50
+ export interface E2eRegistries {
51
+ readonly addresses?: AddressRegistry;
52
+ readonly deployments?: DeploymentRegistry;
53
+ readonly forkBlocks?: {
54
+ readonly [chainId: number]: bigint;
55
+ };
56
+ }
57
+ /**
58
+ * Thrown by `getE2eRuns` when `E2E_CHAINS` selects an eligible chain but `ERPC_SECRET` is unset.
59
+ */
60
+ export declare class E2eErpcSecretUnsetError extends Error {
61
+ readonly chainName: string;
62
+ /** @param chainName - Selected chain, e.g. `"BaseMainnet"`. */
63
+ constructor(chainName: string);
64
+ }
65
+ /** Thrown by `getE2eRuns` when an `E2E_CHAINS` entry names no known chain. */
66
+ export declare class E2eUnknownChainError extends Error {
67
+ readonly entry: string;
68
+ /** @param entry - The unmatched `E2E_CHAINS` entry. */
69
+ constructor(entry: string);
70
+ }
71
+ /**
72
+ * Thrown by `getE2eRuns` when a chain registers every deployment a scenario needs but no fork block
73
+ * can be derived for it.
74
+ */
75
+ export declare class E2eForkBlockMissingError extends Error {
76
+ readonly scenario: string;
77
+ readonly chainId: number;
78
+ /**
79
+ * @param scenario - Scenario name, e.g. `"vaultV2"`.
80
+ * @param chainId - Chain without a fork block.
81
+ */
82
+ constructor(scenario: string, chainId: number);
83
+ }
84
+ /**
85
+ * Decides whether a scenario can run on a chain from the address and deployment registries alone.
86
+ *
87
+ * @param params.scenario - Scenario whose `requires` labels are checked.
88
+ * @param params.chainId - Chain to check.
89
+ * @param params.registries - Registries to read instead of the canonical ones.
90
+ * @returns The target to fork, or the reason the chain is ineligible.
91
+ * @example
92
+ * ```ts
93
+ * import { ChainId } from "@morpho-org/blue-sdk";
94
+ * import { getE2eEligibility } from "@morpho-org/morpho-test";
95
+ *
96
+ * const eligibility = getE2eEligibility({
97
+ * scenario: { name: "midnight", requires: ["midnight", "midnightBundlesV2"] },
98
+ * chainId: ChainId.PolygonMainnet,
99
+ * });
100
+ * // { status: "missingDeployments", chainId: 137, missing: ["midnight", "midnightBundlesV2"] }
101
+ * ```
102
+ */
103
+ export declare const getE2eEligibility: ({ scenario, chainId, registries, }: {
104
+ readonly scenario: E2eScenario;
105
+ readonly chainId: number;
106
+ readonly registries?: E2eRegistries;
107
+ }) => E2eEligibility;
108
+ /**
109
+ * Evaluates a scenario on every chain of the address registry.
110
+ *
111
+ * @param scenario - Scenario whose `requires` labels are checked.
112
+ * @param registries - Registries to read instead of the canonical ones.
113
+ * @returns One eligibility result per registered chain, in ascending chain-id order.
114
+ * @example
115
+ * ```ts
116
+ * import { getE2eMatrix } from "@morpho-org/morpho-test";
117
+ *
118
+ * const chainIds = getE2eMatrix({
119
+ * name: "vaultV2",
120
+ * requires: ["bundles.vaultBundlesV1", "vaultV2Factory"],
121
+ * }).flatMap((entry) => (entry.status === "eligible" ? [entry.target.chainId] : []));
122
+ * ```
123
+ */
124
+ export declare const getE2eMatrix: (scenario: E2eScenario, registries?: E2eRegistries) => readonly E2eEligibility[];
125
+ /** A target selected to run, or skipped with the reason why. */
126
+ export type E2eRun = {
127
+ readonly status: "run";
128
+ readonly target: E2eTarget;
129
+ readonly forkUrl: string;
130
+ } | {
131
+ readonly status: "skip";
132
+ readonly target: E2eTarget;
133
+ readonly reason: string;
134
+ };
135
+ /**
136
+ * Selects which eligible targets of a scenario run in the given environment.
137
+ *
138
+ * `E2E_CHAINS` (comma-separated chain ids or `ChainId` keys) restricts the chains; each entry must
139
+ * name a known chain. Every eligible chain forks through the Morpho eRPC when `ERPC_SECRET` is set
140
+ * (see `getErpcForkUrl` from `@morpho-org/test`). A selected chain where the scenario is not
141
+ * deployed is left out.
142
+ * Without `E2E_CHAINS` (or when it is blank), chains are skipped when `ERPC_SECRET` is unset.
143
+ *
144
+ * The fork URL embeds the secret, so runners must not put `forkUrl` in test names or logs.
145
+ *
146
+ * @param params.scenario - Scenario to select targets for.
147
+ * @param params.env - Environment to read `ERPC_SECRET` and `E2E_CHAINS` from.
148
+ * @param params.registries - Registries to read instead of the canonical ones.
149
+ * @returns The runs, and the skips when ERPC_SECRET is unset, for eligible chains matching the
150
+ * environment selection.
151
+ * @throws {E2eUnknownChainError} When an `E2E_CHAINS` entry names no known chain.
152
+ * @throws {E2eErpcSecretUnsetError} When `E2E_CHAINS` names an eligible chain and `ERPC_SECRET` is
153
+ * unset.
154
+ * @throws {E2eForkBlockMissingError} When an included chain registers the scenario but has no fork
155
+ * block.
156
+ * @example
157
+ * ```ts
158
+ * import { getE2eRuns } from "@morpho-org/morpho-test";
159
+ *
160
+ * const runs = getE2eRuns({
161
+ * scenario: { name: "vaultV2", requires: ["bundles.vaultBundlesV1", "vaultV2Factory"] },
162
+ * env: { E2E_CHAINS: "8453", ERPC_SECRET: "key" },
163
+ * });
164
+ * // [{ status: "run", forkUrl: "https://rpc.morpho.dev/cache/evm/8453?secret=key", target: { chainId: 8453, ... } }]
165
+ * ```
166
+ */
167
+ export declare const getE2eRuns: ({ scenario, env, registries, }: {
168
+ readonly scenario: E2eScenario;
169
+ readonly env: {
170
+ readonly [name: string]: string | undefined;
171
+ };
172
+ readonly registries?: E2eRegistries;
173
+ }) => readonly E2eRun[];
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getE2eRuns = exports.getE2eMatrix = exports.getE2eEligibility = exports.E2eForkBlockMissingError = exports.E2eUnknownChainError = exports.E2eErpcSecretUnsetError = exports.E2E_FORK_BLOCKS = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const test_1 = require("@morpho-org/test");
6
+ /**
7
+ * Minimum fork block per chain. A scenario forks at the highest of this block and the registered
8
+ * deployment blocks of its required labels, so a deployment with a registered block never forks
9
+ * before it exists. Required deployments without a registered block are listed in
10
+ * `E2eTarget.undatedDeployments` for the harness to check onchain. A chain without an entry here
11
+ * can still run when every required label has a registered deployment block.
12
+ */
13
+ exports.E2E_FORK_BLOCKS = {
14
+ [morpho_ts_1.ChainId.EthMainnet]: 26140000n,
15
+ [morpho_ts_1.ChainId.OptimismMainnet]: 157880000n,
16
+ [morpho_ts_1.ChainId.Unichain]: 60620000n,
17
+ [morpho_ts_1.ChainId.PolygonMainnet]: 95110000n,
18
+ [morpho_ts_1.ChainId.MonadMainnet]: 111305000n,
19
+ [morpho_ts_1.ChainId.WorldChainMainnet]: 36017000n,
20
+ [morpho_ts_1.ChainId.StableMainnet]: 42151000n,
21
+ [morpho_ts_1.ChainId.HyperliquidMainnet]: 47899000n,
22
+ [morpho_ts_1.ChainId.TempoMainnet]: 43016000n,
23
+ [morpho_ts_1.ChainId.RobinhoodMainnet]: 82418000n,
24
+ [morpho_ts_1.ChainId.ArcMainnet]: 24719000n,
25
+ [morpho_ts_1.ChainId.BaseMainnet]: 52290000n,
26
+ [morpho_ts_1.ChainId.ArbitrumMainnet]: 512540000n,
27
+ [morpho_ts_1.ChainId.KatanaMainnet]: 44627000n,
28
+ };
29
+ /**
30
+ * Thrown by `getE2eRuns` when `E2E_CHAINS` selects an eligible chain but `ERPC_SECRET` is unset.
31
+ */
32
+ class E2eErpcSecretUnsetError extends Error {
33
+ chainName;
34
+ /** @param chainName - Selected chain, e.g. `"BaseMainnet"`. */
35
+ constructor(chainName) {
36
+ super(`E2E_CHAINS selects "${chainName}" but ERPC_SECRET is unset. Set it or drop the chain from E2E_CHAINS.`);
37
+ this.chainName = chainName;
38
+ this.name = "E2eErpcSecretUnsetError";
39
+ }
40
+ }
41
+ exports.E2eErpcSecretUnsetError = E2eErpcSecretUnsetError;
42
+ /** Thrown by `getE2eRuns` when an `E2E_CHAINS` entry names no known chain. */
43
+ class E2eUnknownChainError extends Error {
44
+ entry;
45
+ /** @param entry - The unmatched `E2E_CHAINS` entry. */
46
+ constructor(entry) {
47
+ super(`E2E_CHAINS entry "${entry}" matches no chain. Use a chain id (e.g. "8453") or a ChainId key (e.g. "BaseMainnet").`);
48
+ this.entry = entry;
49
+ this.name = "E2eUnknownChainError";
50
+ }
51
+ }
52
+ exports.E2eUnknownChainError = E2eUnknownChainError;
53
+ /**
54
+ * Thrown by `getE2eRuns` when a chain registers every deployment a scenario needs but no fork block
55
+ * can be derived for it.
56
+ */
57
+ class E2eForkBlockMissingError extends Error {
58
+ scenario;
59
+ chainId;
60
+ /**
61
+ * @param scenario - Scenario name, e.g. `"vaultV2"`.
62
+ * @param chainId - Chain without a fork block.
63
+ */
64
+ constructor(scenario, chainId) {
65
+ super(`Scenario "${scenario}" is registered on chain "${chainId}" but has no fork block. Add E2E_FORK_BLOCKS[${chainId}] or the deployment blocks of its required labels.`);
66
+ this.scenario = scenario;
67
+ this.chainId = chainId;
68
+ this.name = "E2eForkBlockMissingError";
69
+ }
70
+ }
71
+ exports.E2eForkBlockMissingError = E2eForkBlockMissingError;
72
+ /**
73
+ * Decides whether a scenario can run on a chain from the address and deployment registries alone.
74
+ *
75
+ * @param params.scenario - Scenario whose `requires` labels are checked.
76
+ * @param params.chainId - Chain to check.
77
+ * @param params.registries - Registries to read instead of the canonical ones.
78
+ * @returns The target to fork, or the reason the chain is ineligible.
79
+ * @example
80
+ * ```ts
81
+ * import { ChainId } from "@morpho-org/blue-sdk";
82
+ * import { getE2eEligibility } from "@morpho-org/morpho-test";
83
+ *
84
+ * const eligibility = getE2eEligibility({
85
+ * scenario: { name: "midnight", requires: ["midnight", "midnightBundlesV2"] },
86
+ * chainId: ChainId.PolygonMainnet,
87
+ * });
88
+ * // { status: "missingDeployments", chainId: 137, missing: ["midnight", "midnightBundlesV2"] }
89
+ * ```
90
+ */
91
+ const getE2eEligibility = ({ scenario, chainId, registries = {}, }) => {
92
+ const lookup = (root, label) => label
93
+ .split(".")
94
+ .reduce((node, key) => node != null && typeof node === "object"
95
+ ? node[key]
96
+ : undefined, root);
97
+ const chainAddresses = (registries.addresses ?? morpho_ts_1.addressesRegistry)[chainId];
98
+ const missing = scenario.requires.filter((label) => typeof lookup(chainAddresses, label) !== "string");
99
+ if (missing.length > 0)
100
+ return { status: "missingDeployments", chainId, missing };
101
+ const chainDeployments = (registries.deployments ?? morpho_ts_1.deployments)[chainId];
102
+ const pinned = (registries.forkBlocks ?? exports.E2E_FORK_BLOCKS)[chainId];
103
+ const known = [];
104
+ const undatedDeployments = [];
105
+ for (const label of scenario.requires) {
106
+ const block = lookup(chainDeployments, label);
107
+ if (typeof block === "bigint")
108
+ known.push(block);
109
+ else
110
+ undatedDeployments.push({
111
+ label,
112
+ address: lookup(chainAddresses, label),
113
+ });
114
+ }
115
+ if (pinned == null && (undatedDeployments.length > 0 || known.length === 0))
116
+ return { status: "missingForkBlock", chainId };
117
+ const forkBlockNumber = known.reduce((max, block) => (block > max ? block : max), pinned ?? 0n);
118
+ return {
119
+ status: "eligible",
120
+ target: {
121
+ chainId,
122
+ chainName: morpho_ts_1.ChainId[chainId] ?? `Chain${chainId}`,
123
+ forkBlockNumber,
124
+ undatedDeployments,
125
+ },
126
+ };
127
+ };
128
+ exports.getE2eEligibility = getE2eEligibility;
129
+ /**
130
+ * Evaluates a scenario on every chain of the address registry.
131
+ *
132
+ * @param scenario - Scenario whose `requires` labels are checked.
133
+ * @param registries - Registries to read instead of the canonical ones.
134
+ * @returns One eligibility result per registered chain, in ascending chain-id order.
135
+ * @example
136
+ * ```ts
137
+ * import { getE2eMatrix } from "@morpho-org/morpho-test";
138
+ *
139
+ * const chainIds = getE2eMatrix({
140
+ * name: "vaultV2",
141
+ * requires: ["bundles.vaultBundlesV1", "vaultV2Factory"],
142
+ * }).flatMap((entry) => (entry.status === "eligible" ? [entry.target.chainId] : []));
143
+ * ```
144
+ */
145
+ const getE2eMatrix = (scenario, registries = {}) => Object.keys(registries.addresses ?? morpho_ts_1.addressesRegistry)
146
+ .map(Number)
147
+ .map((chainId) => (0, exports.getE2eEligibility)({ scenario, chainId, registries }));
148
+ exports.getE2eMatrix = getE2eMatrix;
149
+ /**
150
+ * Selects which eligible targets of a scenario run in the given environment.
151
+ *
152
+ * `E2E_CHAINS` (comma-separated chain ids or `ChainId` keys) restricts the chains; each entry must
153
+ * name a known chain. Every eligible chain forks through the Morpho eRPC when `ERPC_SECRET` is set
154
+ * (see `getErpcForkUrl` from `@morpho-org/test`). A selected chain where the scenario is not
155
+ * deployed is left out.
156
+ * Without `E2E_CHAINS` (or when it is blank), chains are skipped when `ERPC_SECRET` is unset.
157
+ *
158
+ * The fork URL embeds the secret, so runners must not put `forkUrl` in test names or logs.
159
+ *
160
+ * @param params.scenario - Scenario to select targets for.
161
+ * @param params.env - Environment to read `ERPC_SECRET` and `E2E_CHAINS` from.
162
+ * @param params.registries - Registries to read instead of the canonical ones.
163
+ * @returns The runs, and the skips when ERPC_SECRET is unset, for eligible chains matching the
164
+ * environment selection.
165
+ * @throws {E2eUnknownChainError} When an `E2E_CHAINS` entry names no known chain.
166
+ * @throws {E2eErpcSecretUnsetError} When `E2E_CHAINS` names an eligible chain and `ERPC_SECRET` is
167
+ * unset.
168
+ * @throws {E2eForkBlockMissingError} When an included chain registers the scenario but has no fork
169
+ * block.
170
+ * @example
171
+ * ```ts
172
+ * import { getE2eRuns } from "@morpho-org/morpho-test";
173
+ *
174
+ * const runs = getE2eRuns({
175
+ * scenario: { name: "vaultV2", requires: ["bundles.vaultBundlesV1", "vaultV2Factory"] },
176
+ * env: { E2E_CHAINS: "8453", ERPC_SECRET: "key" },
177
+ * });
178
+ * // [{ status: "run", forkUrl: "https://rpc.morpho.dev/cache/evm/8453?secret=key", target: { chainId: 8453, ... } }]
179
+ * ```
180
+ */
181
+ const getE2eRuns = ({ scenario, env, registries = {}, }) => {
182
+ const selected = (env.E2E_CHAINS ?? "")
183
+ .split(",")
184
+ .map((chain) => chain.trim())
185
+ .filter((chain) => chain !== "");
186
+ const matrix = (0, exports.getE2eMatrix)(scenario, registries);
187
+ const knownChainIds = new Set([
188
+ ...Object.values(morpho_ts_1.ChainId).filter((id) => typeof id === "number"),
189
+ ...matrix.map((entry) => entry.status === "eligible" ? entry.target.chainId : entry.chainId),
190
+ ]);
191
+ const selectedIds = selected.map((entry) => {
192
+ const chainId = /^\d+$/.test(entry)
193
+ ? Number(entry)
194
+ : morpho_ts_1.ChainId[entry];
195
+ if (typeof chainId !== "number" || !knownChainIds.has(chainId))
196
+ throw new E2eUnknownChainError(entry);
197
+ return chainId;
198
+ });
199
+ return matrix.flatMap((entry) => {
200
+ if (entry.status === "missingDeployments")
201
+ return [];
202
+ const chainId = entry.status === "eligible" ? entry.target.chainId : entry.chainId;
203
+ if (selectedIds.length > 0 && !selectedIds.includes(chainId))
204
+ return [];
205
+ if (entry.status === "missingForkBlock")
206
+ throw new E2eForkBlockMissingError(scenario.name, chainId);
207
+ const { target } = entry;
208
+ const forkUrl = (0, test_1.getErpcForkUrl)(target.chainId, env.ERPC_SECRET);
209
+ if (forkUrl !== undefined)
210
+ return [{ status: "run", target, forkUrl }];
211
+ if (selectedIds.length > 0)
212
+ throw new E2eErpcSecretUnsetError(target.chainName);
213
+ return [
214
+ {
215
+ status: "skip",
216
+ target,
217
+ reason: "ERPC_SECRET is unset",
218
+ },
219
+ ];
220
+ });
221
+ };
222
+ exports.getE2eRuns = getE2eRuns;
@@ -1 +1,2 @@
1
+ export * from "./e2e/index.js";
1
2
  export * from "./fixtures/index.js";
package/lib/cjs/index.js CHANGED
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./e2e/index.js"), exports);
17
18
  __exportStar(require("./fixtures/index.js"), exports);
@@ -0,0 +1,31 @@
1
+ import type { Address, Hex } from "viem";
2
+ /** Fork-only ERC-20 address used when a chain has no registered wNative. */
3
+ export declare const E2E_ASSET: Address;
4
+ /** Canonical mainnet WETH9 runtime bytecode, without constructor arguments. */
5
+ export declare const E2E_ASSET_BYTECODE: Hex;
6
+ /**
7
+ * WETH9 constructor storage for the fallback token's name, symbol, and decimals.
8
+ */
9
+ export declare const E2E_ASSET_STORAGE: readonly {
10
+ readonly slot: Hex;
11
+ readonly value: Hex;
12
+ }[];
13
+ /**
14
+ * Returns a chain's registered wNative or the fallback token and whether callers must install code.
15
+ *
16
+ * @param chainId - Chain to select the asset for.
17
+ * @returns The token address and whether the caller must install its code, as `requiresInstall`.
18
+ * @throws {UnsupportedChainIdError} When `chainId` has no address registry in
19
+ * `@morpho-org/morpho-ts`.
20
+ * @example
21
+ * ```ts
22
+ * import { ChainId } from "@morpho-org/morpho-ts";
23
+ * import { E2E_ASSET, getE2eAsset } from "@morpho-org/morpho-test";
24
+ *
25
+ * getE2eAsset(ChainId.ArcMainnet); // { address: E2E_ASSET, requiresInstall: true }
26
+ * ```
27
+ */
28
+ export declare const getE2eAsset: (chainId: number) => {
29
+ readonly address: Address;
30
+ readonly requiresInstall: boolean;
31
+ };
@@ -0,0 +1,107 @@
1
+ import { getChainAddresses } from "@morpho-org/blue-sdk";
2
+ /** Fork-only ERC-20 address used when a chain has no registered wNative. */
3
+ export const E2E_ASSET = "0xE2E0000000000000000000000000000000000003";
4
+ /** Canonical mainnet WETH9 runtime bytecode, without constructor arguments. */
5
+ export const E2E_ASSET_BYTECODE = `0x${[
6
+ "6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ff",
7
+ "ffffff16806306fdde03146100b9578063095ea7b31461014757806318160ddd146101a157806323b872dd146101ca578063",
8
+ "2e1a7d4d14610243578063313ce5671461026657806370a082311461029557806395d89b41146102e2578063a9059cbb1461",
9
+ "0370578063d0e30db0146103ca578063dd62ed3e146103d4575b6100b7610440565b005b34156100c457600080fd5b6100cc",
10
+ "6104dd565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561010c57",
11
+ "80820151818401526020810190506100f1565b50505050905090810190601f16801561013957808203805160018360200361",
12
+ "01000a031916815260200191505b509250505060405180910390f35b341561015257600080fd5b610187600480803573ffff",
13
+ "ffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061057b565b6040518082151515",
14
+ "15815260200191505060405180910390f35b34156101ac57600080fd5b6101b461066d565b60405180828152602001915050",
15
+ "60405180910390f35b34156101d557600080fd5b610229600480803573ffffffffffffffffffffffffffffffffffffffff16",
16
+ "90602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061",
17
+ "068c565b604051808215151515815260200191505060405180910390f35b341561024e57600080fd5b610264600480803590",
18
+ "60200190919050506109d9565b005b341561027157600080fd5b610279610b05565b604051808260ff1660ff168152602001",
19
+ "91505060405180910390f35b34156102a057600080fd5b6102cc600480803573ffffffffffffffffffffffffffffffffffff",
20
+ "ffff16906020019091905050610b18565b6040518082815260200191505060405180910390f35b34156102ed57600080fd5b",
21
+ "6102f5610b30565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561",
22
+ "033557808201518184015260208101905061031a565b50505050905090810190601f16801561036257808203805160018360",
23
+ "20036101000a031916815260200191505b509250505060405180910390f35b341561037b57600080fd5b6103b06004808035",
24
+ "73ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610bce565b6040518082",
25
+ "15151515815260200191505060405180910390f35b6103d2610440565b005b34156103df57600080fd5b61042a6004808035",
26
+ "73ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffff",
27
+ "ffff16906020019091905050610be3565b6040518082815260200191505060405180910390f35b34600360003373ffffffff",
28
+ "ffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001",
29
+ "600020600082825401925050819055503373ffffffffffffffffffffffffffffffffffffffff167fe1fffcc4923d04b559f4",
30
+ "d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c346040518082815260200191505060405180910390a2565b60008054",
31
+ "600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182",
32
+ "8054600181600116156101000203166002900480156105735780601f10610548576101008083540402835291602001916105",
33
+ "73565b820191906000526020600020905b81548152906001019060200180831161055657829003601f168201915b50505050",
34
+ "5081565b600081600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffff",
35
+ "ffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffff",
36
+ "ffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffff",
37
+ "ffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd03",
38
+ "14c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60003073",
39
+ "ffffffffffffffffffffffffffffffffffffffff1631905090565b600081600360008673ffffffffffffffffffffffffffff",
40
+ "ffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515156106",
41
+ "dc57600080fd5b3373ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffff",
42
+ "ffff16141580156107b457507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6004600086",
43
+ "73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190",
44
+ "815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffff",
45
+ "ffffffff1681526020019081526020016000205414155b156108cf5781600460008673ffffffffffffffffffffffffffffff",
46
+ "ffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffff",
47
+ "ffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001",
48
+ "600020541015151561084457600080fd5b81600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffff",
49
+ "ffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffff",
50
+ "ffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250",
51
+ "50819055505b81600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffff",
52
+ "ffffffffff1681526020019081526020016000206000828254039250508190555081600360008573ffffffffffffffffffff",
53
+ "ffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082",
54
+ "825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffff",
55
+ "ffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405180828152602001",
56
+ "91505060405180910390a3600190509392505050565b80600360003373ffffffffffffffffffffffffffffffffffffffff16",
57
+ "73ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610a2757600080fd5b",
58
+ "80600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16",
59
+ "8152602001908152602001600020600082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff16",
60
+ "6108fc829081150290604051600060405180830381858888f193505050501515610ab457600080fd5b3373ffffffffffffff",
61
+ "ffffffffffffffffffffffffff167f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65826040",
62
+ "518082815260200191505060405180910390a250565b600260009054906101000a900460ff1681565b600360205280600052",
63
+ "60406000206000915090505481565b60018054600181600116156101000203166002900480601f0160208091040260200160",
64
+ "40519081016040528092919081815260200182805460018160011615610100020316600290048015610bc65780601f10610b",
65
+ "9b57610100808354040283529160200191610bc6565b820191906000526020600020905b8154815290600101906020018083",
66
+ "11610ba957829003601f168201915b505050505081565b6000610bdb33848461068c565b905092915050565b600460205281",
67
+ "60005260406000206020528060005260406000206000915091505054815600a165627a7a72305820deb4c2ccab3c2fdca32a",
68
+ "b3f46728389c2fe2c165d5fafa07661e4e004f6c344a0029",
69
+ ].join("")}`;
70
+ /**
71
+ * WETH9 constructor storage for the fallback token's name, symbol, and decimals.
72
+ */
73
+ export const E2E_ASSET_STORAGE = [
74
+ {
75
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000000",
76
+ value: "0x577261707065642045746865720000000000000000000000000000000000001a",
77
+ },
78
+ {
79
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000001",
80
+ value: "0x5745544800000000000000000000000000000000000000000000000000000008",
81
+ },
82
+ {
83
+ slot: "0x0000000000000000000000000000000000000000000000000000000000000002",
84
+ value: "0x0000000000000000000000000000000000000000000000000000000000000012",
85
+ },
86
+ ];
87
+ /**
88
+ * Returns a chain's registered wNative or the fallback token and whether callers must install code.
89
+ *
90
+ * @param chainId - Chain to select the asset for.
91
+ * @returns The token address and whether the caller must install its code, as `requiresInstall`.
92
+ * @throws {UnsupportedChainIdError} When `chainId` has no address registry in
93
+ * `@morpho-org/morpho-ts`.
94
+ * @example
95
+ * ```ts
96
+ * import { ChainId } from "@morpho-org/morpho-ts";
97
+ * import { E2E_ASSET, getE2eAsset } from "@morpho-org/morpho-test";
98
+ *
99
+ * getE2eAsset(ChainId.ArcMainnet); // { address: E2E_ASSET, requiresInstall: true }
100
+ * ```
101
+ */
102
+ export const getE2eAsset = (chainId) => {
103
+ const { wNative } = getChainAddresses(chainId);
104
+ return wNative == null
105
+ ? { address: E2E_ASSET, requiresInstall: true }
106
+ : { address: wNative, requiresInstall: false };
107
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./asset.js";
2
+ export * from "./registryMatrix.js";
@@ -0,0 +1,2 @@
1
+ export * from "./asset.js";
2
+ export * from "./registryMatrix.js";
@@ -0,0 +1,173 @@
1
+ import { type AddressLabel, type AddressRegistry, type DeploymentRegistry } from "@morpho-org/morpho-ts";
2
+ import type { Address } from "viem";
3
+ /** An E2E scenario family and the registry labels it needs on a chain. */
4
+ export interface E2eScenario {
5
+ /** Family name used in test titles and filters, e.g. `"vaultV2"`. */
6
+ readonly name: string;
7
+ /** Registry labels that must all be registered on a chain for the family to run there. */
8
+ readonly requires: readonly AddressLabel[];
9
+ }
10
+ /**
11
+ * Minimum fork block per chain. A scenario forks at the highest of this block and the registered
12
+ * deployment blocks of its required labels, so a deployment with a registered block never forks
13
+ * before it exists. Required deployments without a registered block are listed in
14
+ * `E2eTarget.undatedDeployments` for the harness to check onchain. A chain without an entry here
15
+ * can still run when every required label has a registered deployment block.
16
+ */
17
+ export declare const E2E_FORK_BLOCKS: {
18
+ readonly [chainId: number]: bigint;
19
+ };
20
+ /** A required deployment and its registered address. */
21
+ export interface E2eDeployment {
22
+ readonly label: AddressLabel;
23
+ readonly address: Address;
24
+ }
25
+ /** Where an eligible scenario runs on one chain. */
26
+ export interface E2eTarget {
27
+ readonly chainId: number;
28
+ /** `ChainId` enum key, e.g. `"BaseMainnet"`, or `Chain<id>` for an unnamed chain. */
29
+ readonly chainName: string;
30
+ readonly forkBlockNumber: bigint;
31
+ /**
32
+ * Required deployments with no registered deployment block. The fork block does not account for
33
+ * them, so the harness must check they have code at `forkBlockNumber`.
34
+ */
35
+ readonly undatedDeployments: readonly E2eDeployment[];
36
+ }
37
+ /** Whether a scenario can run on a chain, and why not when it can't. */
38
+ export type E2eEligibility = {
39
+ readonly status: "eligible";
40
+ readonly target: E2eTarget;
41
+ } | {
42
+ readonly status: "missingDeployments";
43
+ readonly chainId: number;
44
+ readonly missing: readonly AddressLabel[];
45
+ } | {
46
+ readonly status: "missingForkBlock";
47
+ readonly chainId: number;
48
+ };
49
+ /** Registries an eligibility check reads; defaults to the canonical ones. */
50
+ export interface E2eRegistries {
51
+ readonly addresses?: AddressRegistry;
52
+ readonly deployments?: DeploymentRegistry;
53
+ readonly forkBlocks?: {
54
+ readonly [chainId: number]: bigint;
55
+ };
56
+ }
57
+ /**
58
+ * Thrown by `getE2eRuns` when `E2E_CHAINS` selects an eligible chain but `ERPC_SECRET` is unset.
59
+ */
60
+ export declare class E2eErpcSecretUnsetError extends Error {
61
+ readonly chainName: string;
62
+ /** @param chainName - Selected chain, e.g. `"BaseMainnet"`. */
63
+ constructor(chainName: string);
64
+ }
65
+ /** Thrown by `getE2eRuns` when an `E2E_CHAINS` entry names no known chain. */
66
+ export declare class E2eUnknownChainError extends Error {
67
+ readonly entry: string;
68
+ /** @param entry - The unmatched `E2E_CHAINS` entry. */
69
+ constructor(entry: string);
70
+ }
71
+ /**
72
+ * Thrown by `getE2eRuns` when a chain registers every deployment a scenario needs but no fork block
73
+ * can be derived for it.
74
+ */
75
+ export declare class E2eForkBlockMissingError extends Error {
76
+ readonly scenario: string;
77
+ readonly chainId: number;
78
+ /**
79
+ * @param scenario - Scenario name, e.g. `"vaultV2"`.
80
+ * @param chainId - Chain without a fork block.
81
+ */
82
+ constructor(scenario: string, chainId: number);
83
+ }
84
+ /**
85
+ * Decides whether a scenario can run on a chain from the address and deployment registries alone.
86
+ *
87
+ * @param params.scenario - Scenario whose `requires` labels are checked.
88
+ * @param params.chainId - Chain to check.
89
+ * @param params.registries - Registries to read instead of the canonical ones.
90
+ * @returns The target to fork, or the reason the chain is ineligible.
91
+ * @example
92
+ * ```ts
93
+ * import { ChainId } from "@morpho-org/blue-sdk";
94
+ * import { getE2eEligibility } from "@morpho-org/morpho-test";
95
+ *
96
+ * const eligibility = getE2eEligibility({
97
+ * scenario: { name: "midnight", requires: ["midnight", "midnightBundlesV2"] },
98
+ * chainId: ChainId.PolygonMainnet,
99
+ * });
100
+ * // { status: "missingDeployments", chainId: 137, missing: ["midnight", "midnightBundlesV2"] }
101
+ * ```
102
+ */
103
+ export declare const getE2eEligibility: ({ scenario, chainId, registries, }: {
104
+ readonly scenario: E2eScenario;
105
+ readonly chainId: number;
106
+ readonly registries?: E2eRegistries;
107
+ }) => E2eEligibility;
108
+ /**
109
+ * Evaluates a scenario on every chain of the address registry.
110
+ *
111
+ * @param scenario - Scenario whose `requires` labels are checked.
112
+ * @param registries - Registries to read instead of the canonical ones.
113
+ * @returns One eligibility result per registered chain, in ascending chain-id order.
114
+ * @example
115
+ * ```ts
116
+ * import { getE2eMatrix } from "@morpho-org/morpho-test";
117
+ *
118
+ * const chainIds = getE2eMatrix({
119
+ * name: "vaultV2",
120
+ * requires: ["bundles.vaultBundlesV1", "vaultV2Factory"],
121
+ * }).flatMap((entry) => (entry.status === "eligible" ? [entry.target.chainId] : []));
122
+ * ```
123
+ */
124
+ export declare const getE2eMatrix: (scenario: E2eScenario, registries?: E2eRegistries) => readonly E2eEligibility[];
125
+ /** A target selected to run, or skipped with the reason why. */
126
+ export type E2eRun = {
127
+ readonly status: "run";
128
+ readonly target: E2eTarget;
129
+ readonly forkUrl: string;
130
+ } | {
131
+ readonly status: "skip";
132
+ readonly target: E2eTarget;
133
+ readonly reason: string;
134
+ };
135
+ /**
136
+ * Selects which eligible targets of a scenario run in the given environment.
137
+ *
138
+ * `E2E_CHAINS` (comma-separated chain ids or `ChainId` keys) restricts the chains; each entry must
139
+ * name a known chain. Every eligible chain forks through the Morpho eRPC when `ERPC_SECRET` is set
140
+ * (see `getErpcForkUrl` from `@morpho-org/test`). A selected chain where the scenario is not
141
+ * deployed is left out.
142
+ * Without `E2E_CHAINS` (or when it is blank), chains are skipped when `ERPC_SECRET` is unset.
143
+ *
144
+ * The fork URL embeds the secret, so runners must not put `forkUrl` in test names or logs.
145
+ *
146
+ * @param params.scenario - Scenario to select targets for.
147
+ * @param params.env - Environment to read `ERPC_SECRET` and `E2E_CHAINS` from.
148
+ * @param params.registries - Registries to read instead of the canonical ones.
149
+ * @returns The runs, and the skips when ERPC_SECRET is unset, for eligible chains matching the
150
+ * environment selection.
151
+ * @throws {E2eUnknownChainError} When an `E2E_CHAINS` entry names no known chain.
152
+ * @throws {E2eErpcSecretUnsetError} When `E2E_CHAINS` names an eligible chain and `ERPC_SECRET` is
153
+ * unset.
154
+ * @throws {E2eForkBlockMissingError} When an included chain registers the scenario but has no fork
155
+ * block.
156
+ * @example
157
+ * ```ts
158
+ * import { getE2eRuns } from "@morpho-org/morpho-test";
159
+ *
160
+ * const runs = getE2eRuns({
161
+ * scenario: { name: "vaultV2", requires: ["bundles.vaultBundlesV1", "vaultV2Factory"] },
162
+ * env: { E2E_CHAINS: "8453", ERPC_SECRET: "key" },
163
+ * });
164
+ * // [{ status: "run", forkUrl: "https://rpc.morpho.dev/cache/evm/8453?secret=key", target: { chainId: 8453, ... } }]
165
+ * ```
166
+ */
167
+ export declare const getE2eRuns: ({ scenario, env, registries, }: {
168
+ readonly scenario: E2eScenario;
169
+ readonly env: {
170
+ readonly [name: string]: string | undefined;
171
+ };
172
+ readonly registries?: E2eRegistries;
173
+ }) => readonly E2eRun[];
@@ -0,0 +1,213 @@
1
+ import { addressesRegistry, ChainId, deployments, } from "@morpho-org/morpho-ts";
2
+ import { getErpcForkUrl } from "@morpho-org/test";
3
+ /**
4
+ * Minimum fork block per chain. A scenario forks at the highest of this block and the registered
5
+ * deployment blocks of its required labels, so a deployment with a registered block never forks
6
+ * before it exists. Required deployments without a registered block are listed in
7
+ * `E2eTarget.undatedDeployments` for the harness to check onchain. A chain without an entry here
8
+ * can still run when every required label has a registered deployment block.
9
+ */
10
+ export const E2E_FORK_BLOCKS = {
11
+ [ChainId.EthMainnet]: 26140000n,
12
+ [ChainId.OptimismMainnet]: 157880000n,
13
+ [ChainId.Unichain]: 60620000n,
14
+ [ChainId.PolygonMainnet]: 95110000n,
15
+ [ChainId.MonadMainnet]: 111305000n,
16
+ [ChainId.WorldChainMainnet]: 36017000n,
17
+ [ChainId.StableMainnet]: 42151000n,
18
+ [ChainId.HyperliquidMainnet]: 47899000n,
19
+ [ChainId.TempoMainnet]: 43016000n,
20
+ [ChainId.RobinhoodMainnet]: 82418000n,
21
+ [ChainId.ArcMainnet]: 24719000n,
22
+ [ChainId.BaseMainnet]: 52290000n,
23
+ [ChainId.ArbitrumMainnet]: 512540000n,
24
+ [ChainId.KatanaMainnet]: 44627000n,
25
+ };
26
+ /**
27
+ * Thrown by `getE2eRuns` when `E2E_CHAINS` selects an eligible chain but `ERPC_SECRET` is unset.
28
+ */
29
+ export class E2eErpcSecretUnsetError extends Error {
30
+ chainName;
31
+ /** @param chainName - Selected chain, e.g. `"BaseMainnet"`. */
32
+ constructor(chainName) {
33
+ super(`E2E_CHAINS selects "${chainName}" but ERPC_SECRET is unset. Set it or drop the chain from E2E_CHAINS.`);
34
+ this.chainName = chainName;
35
+ this.name = "E2eErpcSecretUnsetError";
36
+ }
37
+ }
38
+ /** Thrown by `getE2eRuns` when an `E2E_CHAINS` entry names no known chain. */
39
+ export class E2eUnknownChainError extends Error {
40
+ entry;
41
+ /** @param entry - The unmatched `E2E_CHAINS` entry. */
42
+ constructor(entry) {
43
+ super(`E2E_CHAINS entry "${entry}" matches no chain. Use a chain id (e.g. "8453") or a ChainId key (e.g. "BaseMainnet").`);
44
+ this.entry = entry;
45
+ this.name = "E2eUnknownChainError";
46
+ }
47
+ }
48
+ /**
49
+ * Thrown by `getE2eRuns` when a chain registers every deployment a scenario needs but no fork block
50
+ * can be derived for it.
51
+ */
52
+ export class E2eForkBlockMissingError extends Error {
53
+ scenario;
54
+ chainId;
55
+ /**
56
+ * @param scenario - Scenario name, e.g. `"vaultV2"`.
57
+ * @param chainId - Chain without a fork block.
58
+ */
59
+ constructor(scenario, chainId) {
60
+ super(`Scenario "${scenario}" is registered on chain "${chainId}" but has no fork block. Add E2E_FORK_BLOCKS[${chainId}] or the deployment blocks of its required labels.`);
61
+ this.scenario = scenario;
62
+ this.chainId = chainId;
63
+ this.name = "E2eForkBlockMissingError";
64
+ }
65
+ }
66
+ /**
67
+ * Decides whether a scenario can run on a chain from the address and deployment registries alone.
68
+ *
69
+ * @param params.scenario - Scenario whose `requires` labels are checked.
70
+ * @param params.chainId - Chain to check.
71
+ * @param params.registries - Registries to read instead of the canonical ones.
72
+ * @returns The target to fork, or the reason the chain is ineligible.
73
+ * @example
74
+ * ```ts
75
+ * import { ChainId } from "@morpho-org/blue-sdk";
76
+ * import { getE2eEligibility } from "@morpho-org/morpho-test";
77
+ *
78
+ * const eligibility = getE2eEligibility({
79
+ * scenario: { name: "midnight", requires: ["midnight", "midnightBundlesV2"] },
80
+ * chainId: ChainId.PolygonMainnet,
81
+ * });
82
+ * // { status: "missingDeployments", chainId: 137, missing: ["midnight", "midnightBundlesV2"] }
83
+ * ```
84
+ */
85
+ export const getE2eEligibility = ({ scenario, chainId, registries = {}, }) => {
86
+ const lookup = (root, label) => label
87
+ .split(".")
88
+ .reduce((node, key) => node != null && typeof node === "object"
89
+ ? node[key]
90
+ : undefined, root);
91
+ const chainAddresses = (registries.addresses ?? addressesRegistry)[chainId];
92
+ const missing = scenario.requires.filter((label) => typeof lookup(chainAddresses, label) !== "string");
93
+ if (missing.length > 0)
94
+ return { status: "missingDeployments", chainId, missing };
95
+ const chainDeployments = (registries.deployments ?? deployments)[chainId];
96
+ const pinned = (registries.forkBlocks ?? E2E_FORK_BLOCKS)[chainId];
97
+ const known = [];
98
+ const undatedDeployments = [];
99
+ for (const label of scenario.requires) {
100
+ const block = lookup(chainDeployments, label);
101
+ if (typeof block === "bigint")
102
+ known.push(block);
103
+ else
104
+ undatedDeployments.push({
105
+ label,
106
+ address: lookup(chainAddresses, label),
107
+ });
108
+ }
109
+ if (pinned == null && (undatedDeployments.length > 0 || known.length === 0))
110
+ return { status: "missingForkBlock", chainId };
111
+ const forkBlockNumber = known.reduce((max, block) => (block > max ? block : max), pinned ?? 0n);
112
+ return {
113
+ status: "eligible",
114
+ target: {
115
+ chainId,
116
+ chainName: ChainId[chainId] ?? `Chain${chainId}`,
117
+ forkBlockNumber,
118
+ undatedDeployments,
119
+ },
120
+ };
121
+ };
122
+ /**
123
+ * Evaluates a scenario on every chain of the address registry.
124
+ *
125
+ * @param scenario - Scenario whose `requires` labels are checked.
126
+ * @param registries - Registries to read instead of the canonical ones.
127
+ * @returns One eligibility result per registered chain, in ascending chain-id order.
128
+ * @example
129
+ * ```ts
130
+ * import { getE2eMatrix } from "@morpho-org/morpho-test";
131
+ *
132
+ * const chainIds = getE2eMatrix({
133
+ * name: "vaultV2",
134
+ * requires: ["bundles.vaultBundlesV1", "vaultV2Factory"],
135
+ * }).flatMap((entry) => (entry.status === "eligible" ? [entry.target.chainId] : []));
136
+ * ```
137
+ */
138
+ export const getE2eMatrix = (scenario, registries = {}) => Object.keys(registries.addresses ?? addressesRegistry)
139
+ .map(Number)
140
+ .map((chainId) => getE2eEligibility({ scenario, chainId, registries }));
141
+ /**
142
+ * Selects which eligible targets of a scenario run in the given environment.
143
+ *
144
+ * `E2E_CHAINS` (comma-separated chain ids or `ChainId` keys) restricts the chains; each entry must
145
+ * name a known chain. Every eligible chain forks through the Morpho eRPC when `ERPC_SECRET` is set
146
+ * (see `getErpcForkUrl` from `@morpho-org/test`). A selected chain where the scenario is not
147
+ * deployed is left out.
148
+ * Without `E2E_CHAINS` (or when it is blank), chains are skipped when `ERPC_SECRET` is unset.
149
+ *
150
+ * The fork URL embeds the secret, so runners must not put `forkUrl` in test names or logs.
151
+ *
152
+ * @param params.scenario - Scenario to select targets for.
153
+ * @param params.env - Environment to read `ERPC_SECRET` and `E2E_CHAINS` from.
154
+ * @param params.registries - Registries to read instead of the canonical ones.
155
+ * @returns The runs, and the skips when ERPC_SECRET is unset, for eligible chains matching the
156
+ * environment selection.
157
+ * @throws {E2eUnknownChainError} When an `E2E_CHAINS` entry names no known chain.
158
+ * @throws {E2eErpcSecretUnsetError} When `E2E_CHAINS` names an eligible chain and `ERPC_SECRET` is
159
+ * unset.
160
+ * @throws {E2eForkBlockMissingError} When an included chain registers the scenario but has no fork
161
+ * block.
162
+ * @example
163
+ * ```ts
164
+ * import { getE2eRuns } from "@morpho-org/morpho-test";
165
+ *
166
+ * const runs = getE2eRuns({
167
+ * scenario: { name: "vaultV2", requires: ["bundles.vaultBundlesV1", "vaultV2Factory"] },
168
+ * env: { E2E_CHAINS: "8453", ERPC_SECRET: "key" },
169
+ * });
170
+ * // [{ status: "run", forkUrl: "https://rpc.morpho.dev/cache/evm/8453?secret=key", target: { chainId: 8453, ... } }]
171
+ * ```
172
+ */
173
+ export const getE2eRuns = ({ scenario, env, registries = {}, }) => {
174
+ const selected = (env.E2E_CHAINS ?? "")
175
+ .split(",")
176
+ .map((chain) => chain.trim())
177
+ .filter((chain) => chain !== "");
178
+ const matrix = getE2eMatrix(scenario, registries);
179
+ const knownChainIds = new Set([
180
+ ...Object.values(ChainId).filter((id) => typeof id === "number"),
181
+ ...matrix.map((entry) => entry.status === "eligible" ? entry.target.chainId : entry.chainId),
182
+ ]);
183
+ const selectedIds = selected.map((entry) => {
184
+ const chainId = /^\d+$/.test(entry)
185
+ ? Number(entry)
186
+ : ChainId[entry];
187
+ if (typeof chainId !== "number" || !knownChainIds.has(chainId))
188
+ throw new E2eUnknownChainError(entry);
189
+ return chainId;
190
+ });
191
+ return matrix.flatMap((entry) => {
192
+ if (entry.status === "missingDeployments")
193
+ return [];
194
+ const chainId = entry.status === "eligible" ? entry.target.chainId : entry.chainId;
195
+ if (selectedIds.length > 0 && !selectedIds.includes(chainId))
196
+ return [];
197
+ if (entry.status === "missingForkBlock")
198
+ throw new E2eForkBlockMissingError(scenario.name, chainId);
199
+ const { target } = entry;
200
+ const forkUrl = getErpcForkUrl(target.chainId, env.ERPC_SECRET);
201
+ if (forkUrl !== undefined)
202
+ return [{ status: "run", target, forkUrl }];
203
+ if (selectedIds.length > 0)
204
+ throw new E2eErpcSecretUnsetError(target.chainName);
205
+ return [
206
+ {
207
+ status: "skip",
208
+ target,
209
+ reason: "ERPC_SECRET is unset",
210
+ },
211
+ ];
212
+ });
213
+ };
@@ -1 +1,2 @@
1
+ export * from "./e2e/index.js";
1
2
  export * from "./fixtures/index.js";
package/lib/esm/index.js CHANGED
@@ -1 +1,2 @@
1
+ export * from "./e2e/index.js";
1
2
  export * from "./fixtures/index.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-test",
3
- "description": "Framework-agnostic extension of `@morpho-org/blue-sdk` that exports test fixtures useful for E2E tests on forks.",
4
- "version": "4.0.5",
3
+ "description": "Framework-agnostic extension of `@morpho-org/blue-sdk` that exports test fixtures and registry-driven E2E chain selection for tests on forks.",
4
+ "version": "4.1.0-next.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -22,13 +22,13 @@
22
22
  "peerDependencies": {
23
23
  "@morpho-org/blue-sdk": "^6.0.0 || ^7.0.0 || ^8.0.0",
24
24
  "@morpho-org/morpho-ts": "^2.7.0 || ^3.0.0 || ^4.0.0",
25
- "@morpho-org/test": "^2.8.0",
25
+ "@morpho-org/test": "^2.11.0",
26
26
  "viem": "^2.21.10"
27
27
  },
28
28
  "devDependencies": {
29
- "@morpho-org/blue-sdk": "^8.0.0",
30
- "@morpho-org/morpho-ts": "^4.0.0",
31
- "@morpho-org/test": "^2.10.1",
29
+ "@morpho-org/blue-sdk": "^8.1.0-next.0",
30
+ "@morpho-org/morpho-ts": "^4.1.0-next.0",
31
+ "@morpho-org/test": "^2.11.0-next.0",
32
32
  "typescript": "7.0.2",
33
33
  "viem": "^2.55.10"
34
34
  },