Skip to content

Commit

Permalink
Fix perf test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Dec 15, 2023
1 parent 058d007 commit 83101fa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator";
// eslint-disable-next-line import/no-relative-packages
import {rangeSyncTest} from "../../../../state-transition/test/perf/params.js";
import {
beforeValue,
getNetworkCachedState,
getNetworkCachedBlock,
// eslint-disable-next-line import/no-relative-packages
} from "../../../../state-transition/test/utils/index.js";
} from "../../../../state-transition/test/utils/testFileCache.js";
import {
beforeValue,
// eslint-disable-next-line import/no-relative-packages
} from "../../../../state-transition/test/utils/beforeValueMocha.js";
import {BeaconChain} from "../../../src/chain/index.js";
import {ExecutionEngineDisabled} from "../../../src/execution/engine/index.js";
import {Eth1ForBlockProductionDisabled} from "../../../src/eth1/index.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
CachedBeaconStateAltair,
beforeProcessEpoch,
} from "../../../src/index.js";
import {getNetworkCachedState, beforeValue, LazyValue} from "../../utils/index.js";
import {beforeValue, LazyValue} from "../../utils/beforeValueMocha.js";
import {getNetworkCachedState} from "../../utils/testFileCache.js";
import {StateEpoch} from "../types.js";
import {altairState} from "../params.js";
import {processJustificationAndFinalization} from "../../../src/epoch/processJustificationAndFinalization.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
CachedBeaconStateAltair,
beforeProcessEpoch,
} from "../../../src/index.js";
import {getNetworkCachedState, beforeValue, LazyValue} from "../../utils/index.js";
import {beforeValue, LazyValue} from "../../utils/beforeValueMocha.js";
import {getNetworkCachedState} from "../../utils/testFileCache.js";
import {StateEpoch} from "../types.js";
import {capellaState} from "../params.js";
import {processJustificationAndFinalization} from "../../../src/epoch/processJustificationAndFinalization.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
CachedBeaconStatePhase0,
beforeProcessEpoch,
} from "../../../src/index.js";
import {getNetworkCachedState, beforeValue, LazyValue} from "../../utils/index.js";
import {beforeValue, LazyValue} from "../../utils/beforeValueMocha.js";
import {getNetworkCachedState} from "../../utils/testFileCache.js";
import {StateEpoch} from "../types.js";
import {phase0State} from "../params.js";
import {processEpoch} from "../../../src/epoch/index.js";
Expand Down
36 changes: 36 additions & 0 deletions packages/state-transition/test/utils/beforeValueMocha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export type LazyValue<T> = {value: T};

/**
* Register a callback to compute a value in the before() block of mocha tests
* ```ts
* const state = beforeValue(() => getState())
* it("test", () => {
* doTest(state.value)
* })
* ```
*/
export function beforeValue<T>(fn: () => T | Promise<T>, timeout?: number): LazyValue<T> {
let value: T = null as unknown as T;

before(async function () {
this.timeout(timeout ?? 300_000);
value = await fn();
});

return new Proxy<{value: T}>(
{value},
{
get: function (target, prop) {
if (prop === "value") {
if (value === null) {
throw Error("beforeValue has not yet run the before() block");
} else {
return value;
}
} else {
return undefined;
}
},
}
);
}
2 changes: 0 additions & 2 deletions packages/state-transition/test/utils/index.ts

This file was deleted.

0 comments on commit 83101fa

Please sign in to comment.