Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test vectors: use tarballs, allow multiple spec versions for progressive spec updates #514

Merged
merged 10 commits into from
Nov 1, 2019
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ install:
- IF "%PLATFORM%" == "x64" SET PATH=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%PATH%

# LFS test fixtures
- bash scripts\process_lfs.sh jsonTestsCache
- bash scripts\setup_official_tests.sh jsonTestsCache

build_script:
# the 32-bit build is done on a 64-bit image, so we need to override the architecture
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ install:
- vendor/nimbus-build-system/scripts/build_rocksdb.sh rocksdbCache

# LFS test fixtures
- scripts/process_lfs.sh jsonTestsCache
- scripts/setup_official_tests.sh jsonTestsCache

script:
- set -e # fail fast
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" update # to allow a newer Nim version to be detected
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}"
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" DISABLE_LFS_SCRIPT=1 test

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ p2pd: | go-checks
DISABLE_LFS_SCRIPT := 0
test: | build deps
ifeq ($(DISABLE_LFS_SCRIPT), 0)
V=$(V) scripts/process_lfs.sh
V=$(V) scripts/setup_official_tests.sh
endif
$(ENV_SCRIPT) nim test $(NIM_PARAMS) beacon_chain.nims && rm -f 0000-*.json

Expand All @@ -81,4 +81,3 @@ clean-testnet1:

clean: | clean-common
rm -rf build/{$(TOOLS_CSV),all_tests,*_node}

3 changes: 1 addition & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ jobs:
git config --global core.longpaths true
export GIT_LFS_SKIP_SMUDGE=1
git submodule --quiet update --init --recursive
scripts/process_lfs.sh jsonTestsCache
scripts/setup_official_tests.sh jsonTestsCache
mingw32-make -j2 ARCH_OVERRIDE=${PLATFORM} CI_CACHE=NimBinaries update
mingw32-make -j2 ARCH_OVERRIDE=${PLATFORM} fetch-dlls
mingw32-make -j2 ARCH_OVERRIDE=${PLATFORM} P2PD_CACHE=p2pdCache
file build/beacon_node
mingw32-make -j2 ARCH_OVERRIDE=${PLATFORM} DISABLE_LFS_SCRIPT=1 test
displayName: 'build and test'

2 changes: 1 addition & 1 deletion beacon_chain.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ task test, "Run all tests":

task sync_lfs_tests, "Sync LFS json tests":
# Syncs the json test files (but not the EF yaml tests)
exec "scripts/process_lfs.sh"
exec "scripts/setup_official_tests.sh"
42 changes: 28 additions & 14 deletions scripts/process_lfs.sh → scripts/setup_official_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TMP_CACHE_DIR="tmpcache"
SUBREPO_DIR="tests/official/fixtures"
# verbosity level
[[ -z "$V" ]] && V=0
[[ -z "$BUILD_MSG" ]] && BUILD_MSG="Downloading LFS files"
[[ -z "$BUILD_MSG" ]] && BUILD_MSG="Downloading official test vectors"
CACHE_DIR="$1" # optional parameter pointing to a CI cache dir. Without it, we just download the LFS files for a local `make test`.

[[ -d "${SUBREPO_DIR}" ]] || { echo "This script should be run from the \"nim-beacon-chain\" repo top dir."; exit 1; }
Expand All @@ -33,22 +33,28 @@ COMPRESS_XZ="false"
which 7z &>/dev/null && { DECOMPRESS_XZ="7z e -txz -bd -so"; COMPRESS_XZ="7z a -txz -an -bd -si -so"; }
which xz &>/dev/null && { DECOMPRESS_XZ="xz -d -c -T 0"; COMPRESS_XZ="xz -c -T 0"; }

download_lfs_files() {
[[ -z "$1" ]] && { echo "usage: download_lfs_files() subdir_name"; exit 1; }
# script output
echo -e "$BUILD_MSG"
[[ "$V" == "0" ]] && exec 3>&1 4>&2 &>/dev/null # save stdout and stderr before sending them into oblivion

#############################################
# JSON test files (SSZ v0.8.1) - TODO migrate

download_lfs_json_files() {
[[ -z "$1" ]] && { echo "usage: download_lfs_json_files() subdir_name"; exit 1; }
LFS_DIR="$1"

echo -e "$BUILD_MSG"
which git-lfs &>/dev/null || { echo "Error: 'git-lfs' not found. Please install the corresponding package."; exit 1; }
[[ "$V" == "0" ]] && exec &>/dev/null
# restore stdout and stderr to make sure this error message is shown
which git-lfs &>/dev/null || { [[ "$V" == "0" ]] && exec 1>&3 2>&4; echo "Error: 'git-lfs' not found. Please install the corresponding package."; exit 1; }

pushd "${SUBREPO_DIR}"
git lfs install # redundant after running it once per repo, but fast enough not to worry about detecting whether it ran before
git lfs pull -I "${LFS_DIR}" # we just care about test fixtures converted from YAML to JSON
popd
}

process_subdir() {
[[ -z "$1" ]] && { echo "usage: process_subdir subdir_name"; exit 1; }
process_json_subdir() {
[[ -z "$1" ]] && { echo "usage: process_json_subdir subdir_name"; exit 1; }
LFS_DIR="$1"
ARCHIVE_NAME="${LFS_DIR}.tar.xz"

Expand All @@ -57,7 +63,7 @@ process_subdir() {
# compare the archive's mtime to the date of the last commit
if [[ $(stat ${STAT_FORMAT} "${CACHE_DIR}/${ARCHIVE_NAME}") -gt $(cd "${SUBREPO_DIR}"; git log --pretty=format:%cd -n 1 --date=unix "${LFS_DIR}") ]]; then
# the cache is valid
echo "Copying cached files into ${SUBREPO_DIR}/${LFS_DIR}/"
echo "Copying cached json files into ${SUBREPO_DIR}/${LFS_DIR}/"
mkdir -p "${TMP_CACHE_DIR}"
${DECOMPRESS_XZ} "${CACHE_DIR}/${ARCHIVE_NAME}" | tar -x -C "${TMP_CACHE_DIR}" -f -
cp -a "${TMP_CACHE_DIR}/${LFS_DIR}"/* "${SUBREPO_DIR}/${LFS_DIR}/"
Expand All @@ -76,7 +82,7 @@ process_subdir() {
if [[ "${ON_MACOS}" == "1" ]]; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install git-lfs # this takes almost 5 minutes on Travis, so only run it if needed
fi
download_lfs_files "$LFS_DIR"
download_lfs_json_files "$LFS_DIR"
echo "Updating the cache."
pushd "${SUBREPO_DIR}"
# the archive will contain ${LFS_DIR} as its top dir
Expand All @@ -87,12 +93,20 @@ process_subdir() {
}

if [[ -n "${CACHE_DIR}" ]]; then
process_subdir "json_tests_v0.8.1"
process_subdir "json_tests_v0.8.3"
process_json_subdir "json_tests_v0.8.1"
process_json_subdir "json_tests_v0.8.3"

# Ethereum Foundation test vectors
mkdir -p "${CACHE_DIR}/tarballs"
rm -rf "${SUBREPO_DIR}/tarballs"
ln -s "$(pwd -P)/${CACHE_DIR}/tarballs" "${SUBREPO_DIR}"
else
# no caching
download_lfs_files "json_tests_v0.8.1"
download_lfs_files "json_tests_v0.8.3"
download_lfs_json_files "json_tests_v0.8.1"
download_lfs_json_files "json_tests_v0.8.3"
fi

pushd "${SUBREPO_DIR}"
./download_test_vectors.sh
popd

2 changes: 1 addition & 1 deletion tests/official/fixtures
2 changes: 1 addition & 1 deletion tests/official/fixtures_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ proc readValue*(r: var JsonReader, a: var seq[byte]) {.inline.} =
const
FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / "fixtures"
JsonTestsDir* = FixturesDir/"json_tests_v0.8.3"
SszTestsDir* = FixturesDir/"eth2.0-spec-tests"/"tests"
SszTestsDir* = FixturesDir/"tests-v0.8.3"

proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
try:
Expand Down