Cache slashing protection tests data (#3500)

This commit is contained in:
Lion - dapplion
2021-12-08 16:42:01 +01:00
committed by GitHub
parent ed7962416e
commit 2275fecf44
9 changed files with 52 additions and 43 deletions

View File

@@ -19,7 +19,7 @@ README.md
.codecov.yml
# Tooling
/docker
docker
prometheus.yml
# Docker
@@ -27,9 +27,10 @@ Dockerfile
docker-compose.yml
# Tests
/packages/**/test
packages/**/test
.__testdb
/packages/spec-test-runner/spec-tests
packages/spec-test-runner/spec-tests
packages/validator/spec-tests
# Lodestar artifacts
.lodestar

View File

@@ -31,6 +31,13 @@ jobs:
if: steps.cache-deps.outputs.cache-hit == 'true'
# </common-build>
# Cache validator slashing protection data tests
- name: Restore spec tests cache
uses: actions/cache@master
with:
path: packages/validator/spec-tests
key: spec-test-data-${{ hashFiles('packages/validator/test/spec/params.ts') }}
- name: Lint Grafana Dashboard
run: yarn validate-gdash
- name: Test root binary exists

1
.gitignore vendored
View File

@@ -25,6 +25,7 @@ validators
.vscode
# Tests artifacts
packages/validator/spec-tests
packages/lodestar/test-logs/
packages/beacon-state-transition/test-cache
packages/*/benchmark_data

View File

@@ -29,8 +29,8 @@
"pretest": "yarn run check-types",
"test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'",
"test": "yarn test:unit",
"test:e2e": "yarn run download-spec-tests && mocha 'test/e2e/**/*.test.ts'",
"download-spec-tests": "node -r ts-node/register test/e2e/slashing-protection-interchange-tests/downloadTests.ts",
"test:e2e": "yarn run download-spec-tests && mocha 'test/spec/**/*.test.ts'",
"download-spec-tests": "node -r ts-node/register test/spec/downloadTests.ts",
"coverage": "codecov -F lodestar-validator",
"check-readme": "typescript-docs-verifier"
},

View File

@@ -1,33 +0,0 @@
import path from "path";
// Full link: https://github.com/eth2-clients/slashing-protection-interchange-tests/releases/download/v5.1.0/eip-3076-tests-v5.1.0.tar.gz
export const SPEC_TEST_VERSION = "v5.1.0";
export const TESTS_TO_DOWNLOAD = [`eip-3076-tests-${SPEC_TEST_VERSION}`];
export const SPEC_TEST_REPO_URL = "https://github.com/eth2-clients/slashing-protection-interchange-tests";
export const SPEC_TEST_LOCATION = path.join(__dirname, "../../slashing-protection-interchange-spec-tests");
/* eslint-disable @typescript-eslint/naming-convention */
export interface ISlashingProtectionInterchangeTest {
name: string;
genesis_validators_root: string;
steps: [
{
should_succeed: boolean;
contains_slashable_data: boolean;
interchange: any;
blocks: {
pubkey: string;
should_succeed: boolean;
slot: string;
signing_root?: string;
}[];
attestations: {
pubkey: string;
should_succeed: boolean;
source_epoch: string;
target_epoch: string;
signing_root?: string;
}[];
}
];
}

View File

@@ -10,7 +10,7 @@ import {
SlashingProtectionAttestation,
InvalidBlockError,
InvalidAttestationError,
} from "../../../src/slashingProtection";
} from "../../src/slashingProtection";
chai.use(chaiAsPromised);

View File

@@ -0,0 +1,7 @@
import path from "path";
// Full link: https://github.com/eth2-clients/slashing-protection-interchange-tests/releases/download/v5.1.0/eip-3076-tests-v5.1.0.tar.gz
export const SPEC_TEST_VERSION = "v5.1.0";
export const TESTS_TO_DOWNLOAD = [`eip-3076-tests-${SPEC_TEST_VERSION}`];
export const SPEC_TEST_REPO_URL = "https://github.com/eth2-clients/slashing-protection-interchange-tests";
export const SPEC_TEST_LOCATION = path.join(__dirname, "../../spec-tests");

View File

@@ -15,11 +15,37 @@ import {
InvalidBlockError,
SlashingProtectionBlock,
SlashingProtectionAttestation,
} from "../../../src/slashingProtection";
import {ISlashingProtectionInterchangeTest, SPEC_TEST_LOCATION} from "./params";
} from "../../src/slashingProtection";
import {SPEC_TEST_LOCATION} from "./params";
chai.use(chaiAsPromised);
/* eslint-disable @typescript-eslint/naming-convention */
type SlashingProtectionInterchangeTest = {
name: string;
genesis_validators_root: string;
steps: [
{
should_succeed: boolean;
contains_slashable_data: boolean;
interchange: any;
blocks: {
pubkey: string;
should_succeed: boolean;
slot: string;
signing_root?: string;
}[];
attestations: {
pubkey: string;
should_succeed: boolean;
source_epoch: string;
target_epoch: string;
signing_root?: string;
}[];
}
];
};
/* eslint-disable no-console */
describe("slashing-protection-interchange-tests", () => {
@@ -110,12 +136,12 @@ describe("slashing-protection-interchange-tests", () => {
}
});
export function loadTestCases(testsPath: string): ISlashingProtectionInterchangeTest[] {
export function loadTestCases(testsPath: string): SlashingProtectionInterchangeTest[] {
const files = fs.readdirSync(testsPath);
if (files.length === 0) {
throw Error(`Not tests found in ${testsPath}`);
}
return files.map(
(file) => JSON.parse(fs.readFileSync(path.join(testsPath, file), "utf8")) as ISlashingProtectionInterchangeTest
(file) => JSON.parse(fs.readFileSync(path.join(testsPath, file), "utf8")) as SlashingProtectionInterchangeTest
);
}