Skip to content

Commit

Permalink
Switch to unified test format
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Mar 1, 2023
1 parent d664cd8 commit ff76ffa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 87 deletions.
29 changes: 2 additions & 27 deletions testing/ef_tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
TESTS_TAG := v1.3.0-rc.3
TESTS = general minimal mainnet
TESTS_TAG := v1.3.0-rc.3-pr18-1b09c23
TESTS = minimal mainnet
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))

# Custom fork choice tests from https://github.com/adiasg/consensus-specs
#
# Since these tests are private, we can't download them in this Makefile without
# adding an API key into the process, so we're just downloading the files
# manually and putting them in the root of the `testing/ef_tests` directory.
#
# These files can be obtained from:
# https://github.com/adiasg/consensus-specs/pull/18#issuecomment-1411070772
CUSTOM_FC_TESTS_TAG = fea20be
CUSTOM_FC_TESTS_MAINNET_ARCHIVE = $(CUSTOM_FC_TESTS_TAG)-mainnet.tar.gz
CUSTOM_FC_TESTS_MINIMAL_ARCHIVE = $(CUSTOM_FC_TESTS_TAG)-minimal.tar.gz
CUSTOM_FC_TESTS_REPO_NAME := custom-fc-tests
CUSTOM_FC_TESTS_OUTPUT_DIR := ./$(CUSTOM_FC_TESTS_REPO_NAME)

REPO_NAME := consensus-spec-tests
OUTPUT_DIR := ./$(REPO_NAME)
BASE_URL := https://github.com/ethereum/$(REPO_NAME)/releases/download/$(TESTS_TAG)
Expand Down Expand Up @@ -44,17 +30,6 @@ $(BLS_OUTPUT_DIR):
$(WGET) $(BLS_BASE_URL)/$(BLS_TEST).tar.gz -O $(BLS_TARBALL)
tar -xzf $(BLS_TARBALL) -C $(BLS_OUTPUT_DIR)

%-$(TESTS_TAG).tar.gz:
$(WGET) $(BASE_URL)/$*.tar.gz -O $@

custom-fc-tests:
mkdir $(CUSTOM_FC_TESTS_OUTPUT_DIR)
tar -xzf $(CUSTOM_FC_TESTS_MAINNET_ARCHIVE) -C $(CUSTOM_FC_TESTS_OUTPUT_DIR);
tar -xzf $(CUSTOM_FC_TESTS_MINIMAL_ARCHIVE) -C $(CUSTOM_FC_TESTS_OUTPUT_DIR);

clean-custom-fc-tests:
rm -rf $(CUSTOM_FC_TESTS_OUTPUT_DIR)

clean-test-files:
rm -rf $(OUTPUT_DIR) $(BLS_OUTPUT_DIR)

Expand Down
14 changes: 2 additions & 12 deletions testing/ef_tests/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pub trait Handler {

fn handler_name(&self) -> String;

fn tests_dir(&self) -> String {
"consensus-spec-tests".to_string()
}

fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
Self::Case::is_enabled_for_fork(fork_name)
}
Expand All @@ -47,7 +43,7 @@ pub trait Handler {
let fork_name_str = fork_name.to_string();

let handler_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join(self.tests_dir())
.join("consensus-spec-tests")
.join("tests")
.join(Self::config_name())
.join(&fork_name_str)
Expand Down Expand Up @@ -517,15 +513,13 @@ impl<E: EthSpec + TypeName> Handler for FinalityHandler<E> {
}

pub struct ForkChoiceHandler<E> {
tests_dir: String,
handler_name: String,
_phantom: PhantomData<E>,
}

impl<E: EthSpec> ForkChoiceHandler<E> {
pub fn new(tests_dir: &str, handler_name: &str) -> Self {
pub fn new(handler_name: &str) -> Self {
Self {
tests_dir: tests_dir.into(),
handler_name: handler_name.into(),
_phantom: PhantomData,
}
Expand All @@ -543,10 +537,6 @@ impl<E: EthSpec + TypeName> Handler for ForkChoiceHandler<E> {
"fork_choice"
}

fn tests_dir(&self) -> String {
self.tests_dir.clone()
}

fn handler_name(&self) -> String {
self.handler_name.clone()
}
Expand Down
76 changes: 28 additions & 48 deletions testing/ef_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,60 +479,40 @@ fn finality() {
FinalityHandler::<MainnetEthSpec>::default().run();
}

#[allow(unused_macros)] // TODO(paul): remove `allow` once we have EF test release.
macro_rules! fork_choice_tests {
($tests_dir: ident) => {
#[test]
fn fork_choice_get_head() {
ForkChoiceHandler::<MinimalEthSpec>::new($tests_dir, "get_head").run();
ForkChoiceHandler::<MainnetEthSpec>::new($tests_dir, "get_head").run();
}

#[test]
fn fork_choice_on_block() {
ForkChoiceHandler::<MinimalEthSpec>::new($tests_dir, "on_block").run();
ForkChoiceHandler::<MainnetEthSpec>::new($tests_dir, "on_block").run();
}

#[test]
fn fork_choice_on_merge_block() {
ForkChoiceHandler::<MinimalEthSpec>::new($tests_dir, "on_merge_block").run();
ForkChoiceHandler::<MainnetEthSpec>::new($tests_dir, "on_merge_block").run();
}

#[test]
fn fork_choice_ex_ante() {
ForkChoiceHandler::<MinimalEthSpec>::new($tests_dir, "ex_ante").run();
ForkChoiceHandler::<MainnetEthSpec>::new($tests_dir, "ex_ante").run();
}
};
#[test]
fn fork_choice_get_head() {
ForkChoiceHandler::<MinimalEthSpec>::new("get_head").run();
ForkChoiceHandler::<MainnetEthSpec>::new("get_head").run();
}

// TODO(paul): The typical fork choice tests from the latest release will not
// pass due to the changes in PR #18. This must be resolved before we merge into
// `unstable`, but we are waiting on new test vectors from the EF.
//
// fork_choice_tests!("consensus_spec_tests");

#[cfg(feature = "fork_choice_custom")]
mod fork_choice_custom {
use super::*;
#[test]
fn fork_choice_on_block() {
ForkChoiceHandler::<MinimalEthSpec>::new("on_block").run();
ForkChoiceHandler::<MainnetEthSpec>::new("on_block").run();
}

const CUSTOM_FC_TESTS: &str = "custom-fc-tests";
#[test]
fn fork_choice_on_merge_block() {
ForkChoiceHandler::<MinimalEthSpec>::new("on_merge_block").run();
ForkChoiceHandler::<MainnetEthSpec>::new("on_merge_block").run();
}

fork_choice_tests!(CUSTOM_FC_TESTS);
#[test]
fn fork_choice_ex_ante() {
ForkChoiceHandler::<MinimalEthSpec>::new("ex_ante").run();
ForkChoiceHandler::<MainnetEthSpec>::new("ex_ante").run();
}

#[test]
fn fork_choice_custom_reorg() {
ForkChoiceHandler::<MinimalEthSpec>::new(CUSTOM_FC_TESTS, "reorg").run();
ForkChoiceHandler::<MainnetEthSpec>::new(CUSTOM_FC_TESTS, "reorg").run();
}
#[test]
fn fork_choice_reorg() {
ForkChoiceHandler::<MinimalEthSpec>::new("reorg").run();
ForkChoiceHandler::<MainnetEthSpec>::new("reorg").run();
}

#[test]
fn fork_choice_custom_withholding() {
ForkChoiceHandler::<MinimalEthSpec>::new(CUSTOM_FC_TESTS, "withholding").run();
ForkChoiceHandler::<MainnetEthSpec>::new(CUSTOM_FC_TESTS, "withholding").run();
}
#[test]
fn fork_choice_withholding() {
ForkChoiceHandler::<MinimalEthSpec>::new("withholding").run();
ForkChoiceHandler::<MainnetEthSpec>::new("withholding").run();
}

#[test]
Expand Down

0 comments on commit ff76ffa

Please sign in to comment.