Skip to content

Commit

Permalink
feat: use spec-test-util for ESM and wget compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Dec 20, 2024
1 parent 1016197 commit 443a878
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
3 changes: 2 additions & 1 deletion packages/ssz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@chainsafe/persistent-merkle-tree": "0.8.0"
},
"devDependencies": {
"@lodestar/spec-test-util": "^1.23.1",
"@types/js-yaml": "^4.0.5",
"js-yaml": "^3.13.1",
"snappyjs": "^0.6.1"
Expand All @@ -55,4 +56,4 @@
"simple serialize",
"ssz"
]
}
}
45 changes: 7 additions & 38 deletions packages/ssz/test/spec/downloadTests.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
import fs from "fs";
import path from "path";
import {execSync} from "child_process";
import {SPEC_TEST_LOCATION, SPEC_TEST_VERSION, SPEC_TEST_REPO_URL} from "../specTestVersioning.js";
import {downloadTests} from "@lodestar/spec-test-util/downloadTests";
import {ethereumConsensusSpecsTests} from "../specTestVersioning.js";

/* eslint-disable no-console */

const specVersion = SPEC_TEST_VERSION;
const outputDir = SPEC_TEST_LOCATION;
const specTestsRepoUrl = SPEC_TEST_REPO_URL;
const defaultTestsToDownload = ["general", "mainnet", "minimal"];

const versionFile = path.join(outputDir, "version.txt");
const existingVersion = fs.existsSync(versionFile) && fs.readFileSync(versionFile, "utf8").trim();

if (existingVersion === specVersion) {
console.log(`version ${specVersion} already downloaded`);
process.exit(0);
} else {
console.log(`Downloading new version ${specVersion}`);
}

if (fs.existsSync(outputDir)) {
console.log(`Cleaning existing version ${existingVersion} at ${outputDir}`);
shell(`rm -rf ${outputDir}`);
}

fs.mkdirSync(outputDir, {recursive: true});

for (const test of defaultTestsToDownload) {
const url = `${specTestsRepoUrl}/releases/download/${specVersion}/${test}.tar.gz`;
console.log(`Downloading ${url} to ${outputDir}`);
shell(`wget -c ${url} -O - | tar -xz --directory ${outputDir}`);
console.log(`Downloaded ${url} to ${outputDir}`);
}

// If successful
fs.writeFileSync(versionFile, specVersion);

function shell(cmd: string): string {
return execSync(cmd, {encoding: "utf8"}).trim();
for (const downloadTestOpts of [ethereumConsensusSpecsTests]) {
downloadTests(downloadTestOpts, console.log).catch((e: Error) => {
console.error(e);
process.exit(1);
});
}
11 changes: 7 additions & 4 deletions packages/ssz/test/specTestVersioning.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import url from "url";
import {DownloadTestsOptions} from "@lodestar/spec-test-util/downloadTests";

// WARNING! Don't move or rename this file !!!
//
Expand All @@ -8,6 +8,9 @@ import url from "url";
//
// The contents of this file MUST include the URL, version and target path, and nothing else.

export const SPEC_TEST_REPO_URL = "https://github.com/ethereum/consensus-spec-tests";
export const SPEC_TEST_VERSION = "v1.4.0-beta.1";
export const SPEC_TEST_LOCATION = path.join(path.dirname(import.meta.url), "../spec-tests");
export const ethereumConsensusSpecsTests: DownloadTestsOptions = {
specVersion: "v1.4.0-beta.1",
outputDir: path.join(import.meta.dirname, "../spec-tests"),
specTestsRepoUrl: "https://github.com/ethereum/consensus-spec-tests",
testsToDownload: ["general", "mainnet", "minimal"],
};

0 comments on commit 443a878

Please sign in to comment.