Skip to content

Commit

Permalink
Use better state assertions in spec tests (#2932)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Aug 10, 2021
1 parent 08fee5c commit 05e8265
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IAltairStateTestCase} from "../../stateTestCase";
import {TreeBacked} from "@chainsafe/ssz";
import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {PresetName} from "@chainsafe/lodestar-params";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";

export function runRewardsAndPenalties(presetName: PresetName): void {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -43,7 +43,7 @@ export function runRewardsAndPenalties(presetName: PresetName): void {
},
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IFinalityTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../utils/specTestCases";
import {expectEqualBeaconState} from "../util";
import {expectEqualBeaconStateAltair} from "../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -60,7 +60,7 @@ export function runFinality(presetName: PresetName): void {
timeout: 10000,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/spec-test-runner/test/spec/altair/fork/fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {altair} from "@chainsafe/lodestar-beacon-state-transition";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";
import {SPEC_TEST_LOCATION} from "../../../utils/specTestCases";
import {expectEqualBeaconState} from "../util";
import {expectEqualBeaconStateAltair} from "../../util";
import {IUpgradeStateCase} from "./type";

export function runFork(presetName: PresetName): void {
Expand Down Expand Up @@ -54,7 +54,7 @@ export function runFork(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
import {initializeBeaconStateFromEth1} from "@chainsafe/lodestar-beacon-state-transition";

import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {PresetName} from "@chainsafe/lodestar-params";

interface IGenesisInitSpecTest {
Expand Down Expand Up @@ -59,7 +59,7 @@ export function runInitialization(presetName: PresetName): void {
timeout: 10000,
getExpected: (testCase) => testCase.state,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessAttestationTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -47,7 +47,7 @@ export function runAttestations(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessAttesterSlashingTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -48,7 +48,7 @@ export function runAttesterSlashing(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessBlockHeader} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -45,7 +45,7 @@ export function runBlockHeader(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
import {join} from "path";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {IProcessDepositTestCase} from "./type";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -44,7 +44,7 @@ export function runDeposit(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessProposerSlashingTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function runProposerSlashing(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessSyncCommitteeTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -60,7 +60,7 @@ export function runSyncAggregate(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {allForks, altair} from "@chainsafe/lodestar-beacon-state-transition";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {IProcessVoluntaryExitTestCase} from "./type";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function runVoluntaryExit(presetName: PresetName): void {
shouldError: (testCase) => !testCase.post,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {IBlockSanityTestCase} from "./types";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {TreeBacked} from "@chainsafe/ssz";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {PresetName} from "@chainsafe/lodestar-params";

export function runBlocks(presetName: PresetName): void {
Expand Down Expand Up @@ -59,7 +59,7 @@ export function runBlocks(presetName: PresetName): void {
timeout: 10000,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {altair, allForks} from "@chainsafe/lodestar-beacon-state-transition";
import {TreeBacked} from "@chainsafe/ssz";
import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {expectEqualBeaconState} from "../../util";
import {expectEqualBeaconStateAltair} from "../../../util";
import {ssz} from "@chainsafe/lodestar-types";
import {PresetName} from "@chainsafe/lodestar-params";

Expand Down Expand Up @@ -49,7 +49,7 @@ export function runSlots(presetName: PresetName): void {
timeout: 10000,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {createIChainForkConfig} from "@chainsafe/lodestar-config";
import {ITransitionTestCase} from "./types";
import {SPEC_TEST_LOCATION} from "../../../utils/specTestCases";
import {TreeBacked} from "@chainsafe/ssz";
import {expectEqualBeaconState} from "../util";
import {expectEqualBeaconStateAltair} from "../../util";
import {PresetName} from "@chainsafe/lodestar-params";

export function runTransition(presetName: PresetName): void {
Expand Down Expand Up @@ -65,7 +65,7 @@ export function runTransition(presetName: PresetName): void {
timeout: 10000,
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expectEqualBeaconState(expected, actual);
expectEqualBeaconStateAltair(expected, actual);
},
}
);
Expand Down
19 changes: 0 additions & 19 deletions packages/spec-test-runner/test/spec/altair/util.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {config} from "@chainsafe/lodestar-config/default";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {ssz} from "@chainsafe/lodestar-types";
import {TreeBacked} from "@chainsafe/ssz";
import {expect} from "chai";
import {join} from "path";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {IStateTestCase} from "../../../../utils/specTestTypes/stateTestCase";
import {expectEqualBeaconStatePhase0} from "../../../util";

describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
"epoch justification and finalization mainnet",
Expand Down Expand Up @@ -37,7 +37,7 @@ describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
},
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expect(ssz.phase0.BeaconState.equals(actual, expected)).to.be.true;
expectEqualBeaconStatePhase0(expected, actual);
},
}
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {join} from "path";
import {expect} from "chai";

import {TreeBacked} from "@chainsafe/ssz";
import {config} from "@chainsafe/lodestar-config/default";
Expand All @@ -8,6 +7,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
import {IStateTestCase} from "../../../../utils/specTestTypes/stateTestCase";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {ssz} from "@chainsafe/lodestar-types";
import {expectEqualBeaconStatePhase0} from "../../../util";

describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
"epoch registry updates mainnet",
Expand Down Expand Up @@ -38,7 +38,7 @@ describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
},
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expect(ssz.phase0.BeaconState.equals(actual, expected)).to.be.true;
expectEqualBeaconStatePhase0(expected, actual);
},
}
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {join} from "path";
import {expect} from "chai";

import {TreeBacked} from "@chainsafe/ssz";
import {config} from "@chainsafe/lodestar-config/default";
Expand All @@ -8,6 +7,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
import {IStateTestCase} from "../../../../utils/specTestTypes/stateTestCase";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {ssz} from "@chainsafe/lodestar-types";
import {expectEqualBeaconStatePhase0} from "../../../util";

describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
"rewards and penalties minimal",
Expand Down Expand Up @@ -38,7 +38,7 @@ describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
},
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expect(ssz.phase0.BeaconState.equals(actual, expected)).to.be.true;
expectEqualBeaconStatePhase0(expected, actual);
},
}
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {join} from "path";
import {expect} from "chai";

import {TreeBacked} from "@chainsafe/ssz";
import {config} from "@chainsafe/lodestar-config/default";
Expand All @@ -8,6 +7,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
import {IStateTestCase} from "../../../../utils/specTestTypes/stateTestCase";
import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {ssz} from "@chainsafe/lodestar-types";
import {expectEqualBeaconStatePhase0} from "../../../util";

describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
"epoch slashings mainnet",
Expand Down Expand Up @@ -38,7 +38,7 @@ describeDirectorySpecTest<IStateTestCase, phase0.BeaconState>(
},
getExpected: (testCase) => testCase.post,
expectFunc: (testCase, expected, actual) => {
expect(ssz.phase0.BeaconState.equals(actual, expected)).to.be.true;
expectEqualBeaconStatePhase0(expected, actual);
},
}
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {join} from "path";
import {expect} from "chai";
import {config} from "@chainsafe/lodestar-config/default";
import {phase0, Uint64, Root, ssz} from "@chainsafe/lodestar-types";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {initializeBeaconStateFromEth1} from "@chainsafe/lodestar-beacon-state-transition";

import {SPEC_TEST_LOCATION} from "../../../../utils/specTestCases";
import {expectEqualBeaconStatePhase0} from "../../../util";

interface IGenesisInitSpecTest {
[k: string]: phase0.Deposit | unknown | null | undefined;
Expand Down Expand Up @@ -54,7 +54,7 @@ describeDirectorySpecTest<IGenesisInitSpecTest, phase0.BeaconState>(
timeout: 60000,
getExpected: (testCase) => testCase.state,
expectFunc: (testCase, expected, actual) => {
expect(ssz.phase0.BeaconState.equals(actual, expected)).to.be.true;
expectEqualBeaconStatePhase0(expected, actual);
},
//shouldSkip: (_, __, index) => index !== 0,
}
Expand Down
Loading

0 comments on commit 05e8265

Please sign in to comment.